content-security-policy/sandbox/autoplay-disabled-by-csp.html: the parent reads the document of a CSP-sandboxed (opaque-origin) frame

Open Beginner friendly
#65,463 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
html, javascript
Domain
testing

Research direction

Read content-security-policy/sandbox/autoplay-disabled-by-csp.html and support/autoplay.html.headers, then check how the iframe load handler accesses the video element. The report identifies the cross-origin SecurityError and suggests adding allow-same-origin to the support page's sandbox policy. Run the affected WPT and confirm the harness error and timeout are gone while the autoplay check still passes.

Written by the indexing model from the issue text.

Description

content-security-policy/sandbox/autoplay-disabled-by-csp.html ("csp-derived sandboxing flags prevent autoplay.") loads support/autoplay.html in an iframe, and that page is served with (support/autoplay.html.headers):

Content-Security-Policy: sandbox

Without allow-same-origin, the frame's document gets the sandboxed origin browsing context flag and so an opaque origin. The parent's load handler then does:

var v = iframe.contentWindow.document.getElementById('v');

document is not one of a Window's cross-origin properties (HTML, CrossOriginProperties), so every engine throws a SecurityError there. The exception escapes the load listener: the harness reports it (harness ERROR), and the subtest never finishes (TIMEOUT). Only the logTest subtest (Expecting logs: ["Loaded iframe"]) passes.

It fails this way in all six wpt.fyi runs at the latest aligned revisions:

  • Stable at 4b26db8978:
    • Chrome 158.0.8127.36 (run 5308846168604672): Uncaught SecurityError: Failed to read a named property 'document' from 'Window': Blocked a frame with origin "http://web-platform.test:8000" from accessing a cross-origin frame.
    • Firefox 160.0.1 (5108487085096960): SecurityError: Permission denied to access property "document" on cross-origin object
    • Safari 27.2 (4778240791805952): SecurityError: Sandbox access violation: Blocked a frame at "http://web-platform.test:8000" from accessing a cross-origin frame. The frame being accessed is sandboxed and lacks the "allow-same-origin" flag.
  • Experimental at 71b58bb191: Chrome 160.0.8168.0 (5165587534446592), Firefox 162.0a1 (5188734707040256) and Safari Technology Preview 256 (5096019650674688) give the same errors.

https://wpt.fyi/results/content-security-policy/sandbox/autoplay-disabled-by-csp.html?run_id=5308846168604672&run_id=5108487085096960&run_id=4778240791805952

The test and its support files have not changed since they were added in #54729.

Suggested fix

Serve the support page with Content-Security-Policy: sandbox allow-same-origin. The frame stays sandboxed. allow-same-origin does not lift the sandboxed automatic features browsing context flag (only allow-scripts does), and that flag is what makes the video ineligible for autoplay (HTML "eligible for autoplay"). The test therefore still checks what it is meant to check, and the parent can reach the video element.

Dominant language
HTML
Stars
6.3k
Forks
4.1k
Avg merge
17h 20m
Merged PRs (30d)
841

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from web-platform-tests/wpt

All issues in web-platform-tests/wpt

Similar issues

More Testing & QA issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.