Skip to content

Remove Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy from proxied responses - #903

Open
santicomp2014 wants to merge 2 commits into
mainfrom
strip-coop-header
Open

santicomp2014 wants to merge 2 commits into
mainfrom
strip-coop-header

Conversation

@santicomp2014

@santicomp2014 santicomp2014 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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 with window.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, so window.opener is 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_OUTBOUND in viahtml/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_/...:

  • A fetch of the proxied page from the browser showed cross-origin-opener-policy: same-origin. x-frame-options and content-security-policy were absent, as expected.
  • h's access log showed seven approved authorizations in a row from that tab, with no token exchange after any of them.
  • The same browser signed in normally on a page that does not send the header.

When this applies

Browsers only apply Cross-Origin-Opener-Policy to 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 proxy view (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-Policy to BLOCKED_OUTBOUND, with a comment that explains the login popup and what the header does to it. The second commit adds Cross-Origin-Embedder-Policy beside 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-Policy

Added 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):

Header on the page Result
none the client loads and the sidebar works
Cross-Origin-Embedder-Policy: require-corp the browser blocks the client's own script (ERR_BLOCKED_BY_RESPONSE.NotSameOriginAfterDefaultedToSameOriginByCoep)
Cross-Origin-Embedder-Policy: credentialless the script loads and the sidebar's frame is blocked

The two headers only do their job together, so with Cross-Origin-Opener-Policy removed 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-Only and Cross-Origin-Embedder-Policy-Report-Only only report and do not block anything, so they are left alone.

Tests

  • Unit (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 from BLOCKED_OUTBOUND, so it cannot fail for a header that is missing from the list.
  • Functional (tests/functional/proxy_test.py): the test upstream site now sends Cross-Origin-Opener-Policy: same-origin and Cross-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 the Content-Security-Policy test. tests/functional/headers_test.py also covers the header through its BLOCKED_OUTBOUND parametrization.

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 format and tox -e checkformatting: no files changed, passed
  • tox -e lint: passed
  • tox -e tests (all unit tests): 522 passed
  • tox -e coverage: 100%
  • tox -e functests (all functional tests): 33 passed

The 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 with PYENV_VERSION=3.11.11.

CI on this PR's head commit (the Backend job, CPython 3.11.18): lint, checkformatting, tests, coverage and functests all succeeded.

What was not run

  • A login in a browser against a build with this change. Nothing was deployed, and no staging or production service was called while preparing this PR.
  • The Docker image build.

Before merging

Please do not merge this without a review. Merging to main starts 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-policy header, and the login should complete.

🤖 Generated with Claude Code

santicomp2014 and others added 2 commits November 12, 2026 01:10
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>
@santicomp2014 santicomp2014 changed the title Remove Cross-Origin-Opener-Policy from proxied responses Remove Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy from proxied responses Nov 12, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant