Repository navigation
Conversation
caugner
force-pushed
the
464-protocol-relative-urls-with-https
branch
from
October 21, 2026 09:52
1b66caa to
7899b94
Compare
caugner
force-pushed
the
464-protocol-relative-urls-with-https
branch
from
October 21, 2026 11:07
7899b94 to
aba8906
Compare
caugner
force-pushed
the
464-protocol-relative-urls-with-https
branch
from
November 23, 2026 10:40
aba8906 to
be99dd7
Compare
Name the fixtures after the `src` form they exercise (`_relative`, `_https`, `cross_origin_noproto`) instead of numbering them, so the sub-cases in "checks for same origin" are self-describing. The `sameorigin3` fixture loads `//www.mozilla.org` on `mozilla.org`, which is a different origin, so it joins the `cross_origin_` fixtures.
Replace the regex-based classification into relative, protocol-relative and full URLs with a single `new URL(scriptSrc, baseUrl)`, and derive `sameOrigin` and `secureScheme` from the resolved `scriptUrl`. This drops the `relativeOrigin` and `secureOrigin` flags and the second `new URL(scriptSrc)` parse. Scoring is unchanged: protocol-relative URLs still count as a foreign origin with an insecure scheme, and the resolved scheme of a path-relative URL matches the former `session.url.protocol` check since `baseUrl` is derived from the session. Resolving every `src` means a malformed value such as `src="//"` throws from `new URL`. Since `analyzeScan` runs tests without a per-test `try`/`catch`, that would abort the whole scan, so skip such a `src` instead and cover it with a test.
A protocol-relative `src` that resolves to the page's exact origin (same scheme, host and port) loads from the page itself, so any attack on it also applies to the document. Score it like any other same-origin script (0 points) instead of as an external script loaded over HTTP (-50). A different host behind a protocol-relative `src` (`//www.mozilla.org` on `mozilla.org`) is still a distinct origin and keeps the off-origin scoring, so that case takes over the "scores as foreign" test while the `sameorigin_noproto` fixture moves into "checks for same origin".
An off-origin protocol-relative `src` resolves to whatever scheme the visitor reached the page over, so judge it by the scheme a normal visitor ends up with instead of a blanket -50. When there is no HTTP server, or the HTTP redirect chain ends on `https:`, the script always loads over HTTPS and scores like an `https://` external script (-5 without SRI). Otherwise it can load over HTTP and keeps the -50 / -20 penalty. Only the final hop of the chain matters: an intermediate HTTP hop (`http` -> `http` -> `https`) still lands the visitor on HTTPS, and that downgradeable hop is already penalized by the redirection test (`RedirectionNotToHttpsOnInitialRedirection`), so docking it here too would count one flaw twice. The `cross_origin_noproto` fixture (a different host, HTTP redirecting to HTTPS in the test defaults) accordingly scores -5 instead of -50.
The -20 and -50 descriptions stated that protocol-relative URLs are penalized unconditionally. Since the analyzer only penalizes them when they can resolve to HTTP, reword the descriptions so users are not told a `src="//..."` URL is penalized when it scored 0 or -5.
caugner
force-pushed
the
464-protocol-relative-urls-with-https
branch
from
November 24, 2026 17:38
be99dd7 to
a6dc893
Compare
caugner
commented
Nov 25, 2026
Contributor
Author
There was a problem hiding this comment.
Note: It makes sense to split up the test cases more systematically, but I'll do this in a separate PR, stacked on top.
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.
Description
Update the
subresource-integrityanalyzer to score protocol-relative script URLs (src="//cdn.example.com/…") according to the actual risk, instead of applying a blanket −50://www.mozilla.orgonmozilla.org) is a distinct origin and is handled by the off-origin case below, not treated as same-origin.https://(−5 without SRI) when a normal visitor ends up on HTTPS (no HTTP server, or the HTTP request ultimately redirects to HTTPS), and ashttp://(−50 / −20 with SRI) otherwise.This also reworks the −20 / −50 grade descriptions, which previously stated protocol-relative URLs are penalized unconditionally:
Motivation
Only penalize protocol-relative URLs in the one case that carries additional risk, per the security team's analysis in #464.
Given a document that loads a protocol-relative sub-resource, there are four cases:
Only case 2 warrants a penalty. The observatory distinguishes the document scheme from the redirect chain, so it penalizes a protocol-relative URL only when it is off-origin and a normal visitor is served the document over HTTP.
The document counts as served over HTTPS whenever a visitor ends up there, including through a downgradeable intermediate hop (
http → http → https), since the visitor still lands on HTTPS and the script loads over HTTPS. That insecure hop is a redirect flaw already penalized by the redirection test (RedirectionNotToHttpsOnInitialRedirection); scoring it here as well would dock one flaw twice.Additional details
Example that previously scored −50 despite being served only over HTTPS: https://developer.mozilla.org/en-US/observatory/analyze?host=runephilosof-abtion.github.io%2Fobservatory-test%2F
Since every
srcis now resolved against the served base URL:srcthat cannot be resolved into a URL (e.g.src="//") is skipped rather than throwing and aborting the whole scan.srcthat is not loaded over HTTP(S) (e.g. adata:URL) is skipped as well.srcis detected by resolving it, so forms like///cdn.example.com/…or\\cdn.example.com/…are covered too.Related issues and pull requests
Fixes #464.