Skip to content

Enforce secure nested-document lifecycle for Code OSS webviews #267

Description

@wieslawsoltes

Current nested-lifecycle checkpoint — 19 September 2026

Main is 2b64b08965aeba5ecbd33fcc0bd1beaaceaf6243. The audit found a real missing lifecycle contract after merged Permissions Policy, script-CSP, generation and pagehide work.

Active branch feature/iframe-beforeunload-lifecycle-267 in /Users/wieslawsoltes/GitHub/.worktrees/WebScene-beforeunload-267, exact base 2b64b089, implements synchronous cancelable nested beforeunload before authored iframe navigation/document replacement. A veto must preserve the current realm, document generation and pending tasks; reentrant self-navigation is blocked without blocking sibling document work. No commit exists yet.

Only git diff --check runs. WPT-derived regression, unchanged Markdown Preview and the full nested-consumer matrix remain authored/scheduled but unexecuted.

Parent epic: #264. Top-level release epic: #227.

Proven gap

After service-worker readiness, unchanged browser/pre/index.html creates a nested iframe, sets a sandbox and Permissions Policy, navigates it to fake.html, reads contentWindow/contentDocument, then calls document.open(), write(), and close() with extension HTML. Updates replace the active frame. The prelude observes DOMContentLoaded/load/beforeunload, posts messages across the frame, uses ResizeObserver, preserves scroll, and removes stale frames.

WebScene's capability record at b81f594c explicitly limits iframe support to an initial same-origin document and leaves navigated src/srcdoc, history, sandboxing, origin transitions, cross-origin access control, complete load/error order, repeated-navigation teardown, and arbitrary iframe rendering outside the claim. No CSP enforcement implementation was found in the audited runtime. #253 owns the sandbox DOMTokenList and token semantics; this issue owns the resulting browsing-context, document, origin, CSP, Permissions Policy, navigation, and replacement behavior.

Dependencies and boundaries

Acceptance

  • Selected HTML iframe/navigation, WindowProxy, origin, CSP, sandbox, Permissions Policy, DOM parsing/writing, and lifecycle WPTs pass with checked-in Chromium results and explicit exclusions.
  • Native top-level + nested fixtures cover src, srcdoc, fake.html, base URL, initial about:blank, realm/constructor identity, contentWindow/contentDocument, parent/top/frameElement, same-origin access, opaque sandbox origins, cross-origin denial, postMessage target/origin, CSP nonces/sources, permissions, and links/download/navigation admission.
  • open/write/close, update replacement, reload, detach during load, error, beforeunload/pagehide, observer disconnect, and shutdown produce browser-order events and reject callbacks from stale generations.
  • 100 create/load/write/replace/reload/detach cycles leave zero old realms, WindowProxy targets, documents, observers, ports, fetches, and scene nodes. A 1 MiB HTML update reaches load and first stable scene at p95 <= 250 ms; retained growth after warm-up <= 8 MiB.
  • Markdown CSP blocks disallowed scripts/resources while permitting its nonce, styles, images, and local-resource origins; sandbox flags never silently broaden access.
  • The same contracts cover notebook output, custom editor, webview view/panel, release notes, chat/MCP, Mermaid, and Simple Browser documents.

Proposed PR stack

  1. navigation and WindowProxy/realm identity;
  2. document open/write/close and replacement lifecycle;
  3. origin/CSP/Permissions Policy enforcement;
  4. teardown/performance/WPT and unchanged webview acceptance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vscode-oss/plannedPlanned for the AppScene/WebScene VS Code OSS integration

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions