Skip to content

fix(sri): compare exact origin instead of registrable domain - #559

Draft
caugner wants to merge 4 commits into
mainfrom
558-sri-same-origin
Draft

caugner wants to merge 4 commits into
mainfrom
558-sri-same-origin

Conversation

@caugner

@caugner caugner commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix the subresource integrity test to treat a script's exact origin (scheme + host + port) as the equivalence check, instead of the site's registrable domain (eTLD+1) plus scheme.

  • Compare new URL(scriptSrc).origin against the origin the page was served from.
  • A different subdomain (e.g. cdn.example.com vs. example.com) now counts as a distinct, foreign origin.
  • Drop the now-unused tldts dependency and a redundant sameSecondLevelDomain branch.
  • Describe same-origin results as "the same origin" instead of "a similar origin".

Motivation

Ensure the SRI test reflects the same-origin policy. Treating any host on the registrable domain as same-origin exempted cross-origin scripts (subdomain takeover, delegated/vendor-hosted subdomains) from the SRI penalty, the very resources SRI is meant to protect. Raised by the security team.

Additional details

test_content_sri_sameorigin2.html previously loaded from https://www.mozilla.org/… while the page origin is https://mozilla.org and relied on the registrable-domain equivalence to be considered same-origin; it now loads from the page's own origin. New tests assert that a different subdomain, scheme or port is penalized as an external origin. Another test asserts the base origin follows the final redirect (a script on the post-redirect host is treated as same-origin).

Related issues and pull requests

Fixes #558.

@caugner
caugner force-pushed the 558-sri-same-origin branch from 6eef72b to c5108d9 Compare July 15, 2026 19:41
@caugner
caugner marked this pull request as ready for review July 15, 2026 19:47
@caugner
caugner requested review from a team and mdn-bot as code owners July 15, 2026 19:47
@caugner
caugner requested a review from LeoMcA July 15, 2026 19:47
caugner added a commit that referenced this pull request Jul 15, 2026
…th-https

Rebuild the protocol-relative URL handling (issue #464) on top of the
exact-origin SRI model from #559.

- Drop all `tldts` usage; the origin dimension now compares the resolved
  script `origin` against the page's `baseOrigin` (scheme + host + port).
- Collapse the per-branch origin computation to a single
  `new URL(scriptSrc, baseUrl).origin === baseOrigin`, guarded on
  `baseUrl` so a missing session resolves to a foreign origin. Same-host
  protocol-relative URLs are therefore same-origin.
- Keep the scheme dimension (`httpEnforcesHttps` and the
  `relativeProtocol && httpEnforcesHttps` clause) unchanged.
- Update tests for exact-origin semantics: `//www.mozilla.org` against
  apex `mozilla.org` is now off-origin (scored by scheme), and the
  on-origin path uses a new same-host `//mozilla.org` fixture.
@caugner
caugner marked this pull request as draft September 9, 2026 11:00
@caugner
caugner force-pushed the 558-sri-same-origin branch from 2591d80 to 14a6546 Compare October 21, 2026 09:52
@caugner
caugner added this pull request to stack #642 October 21, 2026 09:53
The subresource integrity test treated any host on the site's registrable
domain (eTLD+1, via `tldts`) plus scheme as an equivalent origin, so a
script from a different subdomain (`cdn.example.com`, `evil.example.com`)
was exempted from the SRI penalty as if it were same-origin.

Compare the script's exact origin (scheme + host + port) against the
origin the page was served from, so a different subdomain counts as a
distinct, foreign origin. This drops the last use of `tldts` and removes
a redundant `sameSecondLevelDomain` branch that produced the same result
as its successor.
`tldts` was only used by the subresource integrity test, which no longer
resolves registrable domains.
The redirect branch of `baseUrl` was untested because the helper leaves
`redirectHistory` empty. Assert that a script foreign to the requested
origin is treated as same-origin once the page redirects to that script's
host.
Set `sameOrigin` explicitly for each kind of script URL: a full URL
compares its exact origin with the page origin, a relative URL is
same-origin, and a protocol-relative URL is foreign without being parsed,
so a malformed `//...` source cannot throw. Protocol-relative scripts are
excluded from the same-origin check via `!relativeProtocol`, keeping
their existing score.

Derive the secure scheme of relative scripts from the final page URL,
the same base used for the origin comparison.

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.

SRI test treats same registrable domain + scheme as same origin

2 participants