| Version | Supported |
|---|---|
0.4.x |
✅ |
0.3.x |
✅ |
< 0.3 |
❌ |
@innovatorved/code-lab executes user-supplied JavaScript, TypeScript, C++20 (WebAssembly / WASI Preview 1), Python 3.12 (CPython WASI / Pyodide), POSIX shell pipelines, and HTML/CSS/ESM web previews entirely inside the visitor's browser. There is no backend execution server.
- Web Worker Isolation:
executeInWorker()runs untrusted code inside a dedicatedBlob-backed Web Worker with no direct reference to the hostwindowordocument. Infinite loops and hung timers are preempted viaworker.terminate()whentimeoutMsexpires. - Main-Thread Fallback:
executeInVirtualRuntime()executes inside a shadowednew Function(...)scope on the caller's thread. Host applications running untrusted multi-tenant code should preferexecuteInWorker()so infinite loops cannot block the UI thread.
- Iframe Sandbox: The embedded Web Preview iframe renders with
sandbox="allow-scripts allow-forms allow-modals", which stripsallow-same-originand assigns the preview document a unique opaque origin (null). Scripts inside the iframe cannot read host cookies,localStorage, or IndexedDB. - Pop-Out Service Worker Scope (
/__preview/:port/*): When a user pops out a preview into a dedicated browser tab viapreview-sw.js, the Service Worker serves virtual server responses under/__preview/:port/*on the registering origin unless hosted on a dedicated preview subdomain.- Production Recommendation: If your deployment hosts authenticated user sessions on the main origin and allows rendering untrusted third-party repositories in popped-out tabs, serve
preview-sw.jsfrom a dedicated sandbox origin (e.g.,*.preview.example.com) so popped-out previews do not share an origin with authenticated cookies.
- Production Recommendation: If your deployment hosts authenticated user sessions on the main origin and allows rendering untrusted third-party repositories in popped-out tabs, serve
- Content Security Policy (
previewCsp): Every HTML response served to the embedded iframe or viapreview-sw.js(includingUint8Array/ArrayBufferbinary HTML responses) receives aContent-Security-Policy(<meta http-equiv="Content-Security-Policy">insrcdocand a response header inpreview-sw.js) built bysrc/csp.ts:'balanced'(default): Allows inline scripts/styles and ESM CDNs (https://cdn.jsdelivr.net,https://esm.sh,https://unpkg.com,blob:,data:), while lockingobject-src 'none',base-uri 'none', andform-action 'self'.'strict': Removes'unsafe-inline','unsafe-eval', and wildcard network origins (connect-src 'self',script-src 'self' blob: https://cdn.jsdelivr.net).- Custom string (
{ mode: 'custom', policy: '...' }or raw string): Pass a custom CSP directive string viapreviewCspinCodeLab.mount(el, { previewCsp })or<code-lab preview-csp="strict">(newlines and"/</>characters are stripped to prevent header/meta attribute injection).
- Service Worker Client & Origin Verification:
preview-sw.jsverifies thatMessageEventreplies originate from a controlledClients.get(sourceId)window on the same origin before resolving virtual loopback requests. - CSP Violation Diagnostics: When a preview resource is blocked by CSP, the preview bridge posts a
codelab-preview-csp/codelab-preview-violationmessage to the workbench, which emits structuredpreview-violationandcsp-violationevents (lab.on('preview-violation', ({ blockedURI, violatedDirective, effectiveDirective }) => ...)).
- ZIP Bomb & Traversal Guards:
extractZip()enforces a 100 MB total uncompressed size cap, a 25 MB single-entry cap, a 10,000 entry count cap, and strips.., drive prefixes, and prototype-pollution path segments (__proto__,constructor,prototype). - URL Snapshot Decompression Guard:
#codelab=URL hash decompression enforces a 5 MB stream limit to prevent decompression-bomb memory exhaustion. - Prototype-Safe VFS & Search Maps: Workspace file maps, search group tables, and Git status snapshots filter out dangerous keys (
__proto__,constructor,prototype) and useObject.prototype.hasOwnProperty.call(...).
- Markdown rendered in the Guide tab, hints, and
.mdpreviews is HTML-escaped before inline token expansion, restricts links and images tohttp://,https://,mailto:,#, and relative paths (blockingjavascript:,data:, andvbscript:schemes, including URLs with balanced parentheses), and strips event-handler attributes. - Internal DOM builders use the strict
htmltagged template (src/html.ts) andescapeHtmlso untrusted values are escaped by default unless explicitly wrapped inraw(...).
Please report security vulnerabilities privately via GitHub Security Advisories rather than opening a public issue. Include:
- Affected version and component (
runtime,shell,workbench,preview-sw,csp, ormarkdown). - Minimal reproduction steps or proof-of-concept payload.
- Expected vs. actual security boundary behavior.
We aim to acknowledge reports within 48 hours and publish a fix and advisory once verified.