Repository navigation
Remove Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy from proxied responses - #903
Open
santicomp2014 wants to merge 2 commits into
Open
santicomp2014 wants to merge 2 commits into
santicomp2014 wants to merge 2 commits into
Conversation
The Hypothesis client logs people in through a popup window, and the page that h shows in the popup sends the authorization code back to the client with `window.opener.postMessage()`. When a proxied site sends `Cross-Origin-Opener-Policy: same-origin` the browser cuts the link between the page and the popups it opens, so `window.opener` is null in the popup and the code never reaches the client. The person presses "Log in", approves, and nothing happens. pywb passes this header through unchanged and Via HTML did not remove it. Add it to BLOCKED_OUTBOUND, next to Content-Security-Policy. Tests: - Unit: a test that names the header, in mixed, lower and upper case. The existing parametrized test only covers what is already in BLOCKED_OUTBOUND, so it could not fail for a header that is missing from the list. - Functional: the test upstream site now sends the header and proxy_test.py checks that it is not in the proxied response. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A site that sends Cross-Origin-Embedder-Policy tells the browser to refuse anything from another site that has not opted in. The Hypothesis client's script and the frame its sidebar lives in both come from another site and neither opts in, so on such a page there is no Hypothesis at all. Tested on a local page that embeds the public client: - no header: the client loads and the sidebar works; - require-corp: the browser blocks the client's own script (ERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoep); - credentialless: the script loads and the sidebar's frame is blocked. The header only does its job together with Cross-Origin-Opener-Policy, which the previous commit removes, so leaving it would protect nothing and only block the client. The unit test now names both headers, and the functional test site sends both. The new cases failed before the change (3 unit failures). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Symptom
On some proxied pages a person presses "Log in" in the Hypothesis sidebar, approves in the popup window, and nothing happens. They stay logged out.
Cause
The client logs people in through a popup window (h's
/oauth/authorize?response_mode=web_message). The page that h shows in the popup hands the authorization code back to the sidebar withwindow.opener.postMessage(...).When the proxied site sends
Cross-Origin-Opener-Policy: same-origin, the browser cuts the link between the page and any popup it opens, sowindow.openeris null in the popup. h's page has nowhere to send the code, and the sidebar never receives it.Via HTML removes some upstream headers that would break the embed (
BLOCKED_OUTBOUNDinviahtml/hooks/_headers.py), but not this one. pywb 2.10.1 has no rule for the header either, so it reaches the browser unchanged.How it was reproduced
On staging on 2026-11-12, with https://www.iana.org/help/example-domains opened in a tab through
edu-viahtml.staging.hypothes.is/proxy/mp_/...:cross-origin-opener-policy: same-origin.x-frame-optionsandcontent-security-policywere absent, as expected.When this applies
Browsers only apply
Cross-Origin-Opener-Policyto the top-level page of a tab. They ignore it on a page inside an iframe.#333 looked at this same header in 2022. It was closed without a change because Via showed the Via HTML page inside an iframe, so the header had no effect there. Via's
proxyview (via/templates/proxy.html.jinja2) still loads the page in an iframe.In the reproduction above the Via HTML page was the top-level page of the tab, and there the header does take effect. Removing the header in Via HTML is the first option that was listed in #333.
The fix
Add
Cross-Origin-Opener-PolicytoBLOCKED_OUTBOUND, with a comment that explains the login popup and what the header does to it. The second commit addsCross-Origin-Embedder-Policybeside it; see below.modify_outbound()compares header names in lower case, so the header is removed however the site spells it. Without the header the page gets the browser's default policy (unsafe-none), which keeps the link to the popup.Also removed:
Cross-Origin-Embedder-PolicyAdded in a second commit. A site that sends this header tells the browser to refuse anything from another site that has not opted in. The client's script and the frame its sidebar lives in both come from another site and neither opts in, so on such a page there is no Hypothesis at all.
Tested on a local page that embeds the public client (Chromium, not through Via):
Cross-Origin-Embedder-Policy: require-corpERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoep)Cross-Origin-Embedder-Policy: credentiallessThe two headers only do their job together, so with
Cross-Origin-Opener-Policyremoved this one would protect nothing and only block the client. Unlike the opener policy, it governs whatever page carries it, so it should matter in a frame as well as in a tab; the framed case was not tested. It is rare on reading pages.Not changed here
Cross-Origin-Opener-Policy-Report-OnlyandCross-Origin-Embedder-Policy-Report-Onlyonly report and do not block anything, so they are left alone.Tests
tests/unit/viahtml/hooks/_headers_test.py): a new test that names both headers and runs with each name in mixed, lower and upper case. The existing parametrized test takes its cases fromBLOCKED_OUTBOUND, so it cannot fail for a header that is missing from the list.tests/functional/proxy_test.py): the test upstream site now sendsCross-Origin-Opener-Policy: same-originandCross-Origin-Embedder-Policy: require-corp, and a new test for each checks that the header is not in the proxied response, in the same style as theContent-Security-Policytest.tests/functional/headers_test.pyalso covers the header through itsBLOCKED_OUTBOUNDparametrization.Both new tests were run before the fix and failed: 3 unit failures (one per case), and 1 functional failure with
assert 'same-origin' == '*MISSING*'. The embedder cases were also run before their fix and failed: 3 unit failures.What was run
Locally on macOS with tox 3.28.0 and Python 3.11.11, with the fix applied:
tox -e formatandtox -e checkformatting: no files changed, passedtox -e lint: passedtox -e tests(all unit tests): 522 passedtox -e coverage: 100%tox -e functests(all functional tests): 33 passedThe pyenv on the machine used does not offer the Python version in
.python-version(3.11.18; its newest 3.11 is 3.11.11), so tox was run locally withPYENV_VERSION=3.11.11.CI on this PR's head commit (the Backend job, CPython 3.11.18):
lint,checkformatting,tests,coverageandfunctestsall succeeded.What was not run
Before merging
Please do not merge this without a review. Merging to
mainstarts the deploy pipeline (.github/workflows/deploy.yml: staging, then production).Once it is on staging, the check is to repeat the reproduction above: the proxied page should no longer have the
cross-origin-opener-policyheader, and the login should complete.🤖 Generated with Claude Code