Repository navigation
Extend CSP script-src hashes - #784
carlosjoan91 wants to merge 5 commits into
Conversation
mikewest
left a comment
There was a problem hiding this comment.
Hey Carlos, thanks for the PR. I took a quick pass through and have a few questions.
That said, as we move CSP into a more stable maintenance model, we're going to be a little stricter about what we land in the spec to ensure that we have support from implementers, reasonably solid tests, etc. Can you help me understand the current state of the feature from that perspective?
|
|
||
| 6. Let |documentURLTokens| and |resourceURLPathTokens| be the result of | ||
| <a lt="strictly split a string">strictly splitting</a> |documentURLPath| | ||
| and |resourceURLPath| respectively on the U+002F SOLIDUS character (`/`). |
There was a problem hiding this comment.
I don't understand the point of serializing and then splitting. Could you more simply access the URL's path, which is already either a single segment or a list of segments? I think that dropping the last item off the list (assuming it's non-empty) would address 5, and get you something similar to what you get with the serializing/splitting.
|
|
||
| Given a {{URL}} |resourceURL| and a {{URL}} |documentURL|, | ||
| this algorithm returns a {{String}} that represents the relative path of | ||
| |resourceURL| according to |documentURL| if they are same origin. |
There was a problem hiding this comment.
Can you help me understand the value of the check here? I think the goal is to specify what to hash in a way that's consistent across pages, but I don't understand why, for example, it's better to build a relative path than to hash the absolute path. Is the deployment story impacted one way or the other?
| 15. [=list/iterate|For each=] |index| of [=the exclusive range=] 0 to |resultTokens|' [=list/size=] - 1: | ||
|
|
||
| 1. Append |resultTokens|[|index|] to |result|. | ||
|
|
||
| 2. Append U+002F SOLIDUS character (`/`) to |result|. |
There was a problem hiding this comment.
It might make sense to rely on https://infra.spec.whatwg.org/#string-concatenate to construct |result|, which would let you consolidate 15.* and 16.
There was a problem hiding this comment.
Ack, I'll add a commit that switches to it
| MegaCorp, Inc. now wants to deploy a more strict policy using <a grammar>`url-hash-source`</a>s: | ||
|
|
||
| <pre> | ||
| <a http-header>Content-Security-Policy</a>: <a>script-src</a> https: 'unsafe-inline' 'strict-dynamic-url' 'url-hash-EAaArVRs5qV39C9S3zO0z9ynVoWeZkuNfeMpsVDQnOk=' |
There was a problem hiding this comment.
What is this hash referring to? It's not script.js, /script.js, or https://example.com/script.js, so I feel like I'm missing something.
|
|
||
| 1. If the result of executing [[#match-request-to-source-list]] on | ||
| |request|, |directive|'s <a for="directive">value</a>, and | ||
| |policy|, is "`Does Not Match`", return "`Blocked`". |
There was a problem hiding this comment.
I'm not sure I understands this step. If a url-hash-source expression is present, won't it be checked exhaustively in step 3, returning Allowed if it matches? We only get here when that expression doesn't match, in which case I'm not sure I understand why we ignore the rest of the source list checks. Do these expressions exclude other source list checks (non-URL hashes, for instance)?
There was a problem hiding this comment.
I'll let @meacer correct me since he worked more on this section, but I think the intention is to ignore hosts if any URL hashes are set
|
From Mike's comment up top (#784 (review))
Part of that is that we need to have an issue in this repo, not TAG, where we can discuss and track the proposal before we ever get to landing a PR for it. |
Co-authored-by: Mike West <[email protected]>
Co-authored-by: Mike West <[email protected]>
Our intention is to do an origin trial in Chrome 141, so this is currently fully implemented in Chrome (behind a runtime enabled feature), and we have some tentative WPTs (under https://github.com/web-platform-tests/wpt/tree/master/content-security-policy/script-src/tentative), as far as other implementers we have filed position requests, but have not received responses yet. |
I think I might be misunderstanding the order of things. I had originally assumed that TAG review should happen before the PR can land (in fact I originally requested TAG review before even creating a PR, and just pointed the TAG review request to a diff, but a PR was requested as part of TAG review). Is the correct order to handle discussions directly in the repo and get the PR landed (or maybe approved but not landed) before requesting TAG review? |
Test that url sources match the URL string for each way of creating a worker: dedicated and shared workers and service workers, whose URL strings (passed to the Worker and SharedWorker constructors and to navigator.serviceWorker.register()) are checked against the policy of the document. Which URL strings match is already tested for <script> elements by the URL forms tests, so for each of these, only check that url sources apply (by an absolute URL string) and that a URL string with a single-dot segment is matched as written rather than as the URL relative to the document it resolves to. Also check url sources in worker-src for each of them. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
Like the tests for creating workers, test that url sources match the URL string of scripts imported with importScripts() by dedicated and shared workers and service workers. These URL strings are resolved against the worker's URL and checked against the policy of the worker, delivered with the worker script. Service workers fetch imported scripts differently, through the script cache while they are installed. As a service worker can't post to the document before it controls it, a blocked import makes the registration fail. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
Like the tests for workers and importScripts(), test that url sources match the URL string for each way of requesting a module script: - in a document, in modules.https.window.js, module scripts of <script type="module"> elements, and scripts imported by a module script with a static import and with import(), - in dedicated and shared workers and service workers, in workers.https.window.js next to the classic workers, the scripts of module workers and scripts imported by them with a static import and, except in service workers, which don't allow it, with import(). The static imports of a module worker's script are fetched for the document, like the script itself, so they're checked against the policy of the document. Scripts imported with import() are checked against the policy of the worker. To import a URL string, the module script of a document or the script of a module worker is a support script which imports it. In a document, it's requested with an absolute URL string and allowed by its url source rather than by the nonce, which the scripts it imports would inherit. The <script> elements of iframe.sub.html and iframe_meta.sub.html (and their copies in child_dir/) get the type given in the script_type parameter, and worker.sub.html creates module workers when the module parameter is "true". Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
Like the tests for workers and importScripts(), test that url sources match the URL string for each way of requesting a module script: - in a document, in modules.https.window.js, module scripts of <script type="module"> elements, and scripts imported by a module script with a static import and with import(), - in dedicated and shared workers and service workers, in workers.https.window.js next to the classic workers, the scripts of module workers and scripts imported by them with a static import and, except in service workers, which don't allow it, with import(). The static imports of a module worker's script are fetched for the document, like the script itself, so they're checked against the policy of the document. Scripts imported with import() are checked against the policy of the worker. To import a URL string, the module script of a document or the script of a module worker is a support script which imports it. In a document, it's requested with an absolute URL string and allowed by its url source rather than by the nonce, which the scripts it imports would inherit. The <script> elements of iframe.sub.html and iframe_meta.sub.html (and their copies in child_dir/) get the type given in the script_type parameter, and worker.sub.html creates module workers when the module parameter is "true". Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
A classic script preloaded by a <link rel=preload> and a module script preloaded by a <link rel=modulepreload> are checked against the policy when they're preloaded, with the URL string of the <link>'s href attribute. If the preload is blocked, a violation is reported even if the <script> element requesting the script afterwards is allowed. A module which failed to preload also fails to be imported. Test that url sources allow preloaded scripts of both kinds with a relative URL string, which already works when matching the URL relative to the document and must keep working when matching the URL string as written, and with a URL string with a single-dot segment, which only works when matching the URL string as written. url_string_test() in support/util.js can now preload the script first, in the new preload.sub.html. It creates the <script> element of the type given in the script_type parameter only once the script is preloaded, as otherwise the speculative parser could request it before the preload. Not all browsers fire a securitypolicyviolation event for a blocked preload, so it also reports a violation if the preload fails. Like iframe.sub.html, it reports any other violation unless it's of the directive given in the ignored_violation_directive parameter. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
Like the tests for workers and importScripts(), test that url sources match the URL string for each way of requesting a module script: - in a document, in modules.https.window.js, module scripts of <script type="module"> elements, and scripts imported by a module script with a static import and with import(), - in dedicated and shared workers and service workers, in workers.https.window.js next to the classic workers, the scripts of module workers and scripts imported by them with a static import and, except in service workers, which don't allow it, with import(). The static imports of a module worker's script are fetched for the document, like the script itself, so they're checked against the policy of the document. Scripts imported with import() are checked against the policy of the worker. To import a URL string, the module script of a document or the script of a module worker is a support script which imports it. In a document, it's requested with an absolute URL string and allowed by its url source rather than by the nonce, which the scripts it imports would inherit. The <script> elements of iframe.sub.html and iframe_meta.sub.html (and their copies in child_dir/) get the type given in the script_type parameter, and worker.sub.html creates module workers when the module parameter is "true". Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
A classic script preloaded by a <link rel=preload> and a module script preloaded by a <link rel=modulepreload> are checked against the policy when they're preloaded, with the URL string of the <link>'s href attribute. If the preload is blocked, a violation is reported even if the <script> element requesting the script afterwards is allowed. A module which failed to preload also fails to be imported. Test that url sources allow preloaded scripts of both kinds with a relative URL string, which already works when matching the URL relative to the document and must keep working when matching the URL string as written, and with a URL string with a single-dot segment, which only works when matching the URL string as written. url_string_test() in support/util.js can now preload the script first, in the new preload.sub.html. It creates the <script> element of the type given in the script_type parameter only once the script is preloaded, as otherwise the speculative parser could request it before the preload. Not all browsers fire a securitypolicyviolation event for a blocked preload, so it also reports a violation if the preload fails. Like iframe.sub.html, it reports any other violation unless it's of the directive given in the ignored_violation_directive parameter. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
Like the tests for workers and importScripts(), test that url sources match the URL string for each way of requesting a module script: - in a document, in modules.https.window.js, module scripts of <script type="module"> elements, and scripts imported by a module script with a static import and with import(), - in dedicated and shared workers and service workers, in workers.https.window.js next to the classic workers, the scripts of module workers and scripts imported by them with a static import and, except in service workers, which don't allow it, with import(). The static imports of a module worker's script are fetched for the document, like the script itself, so they're checked against the policy of the document. Scripts imported with import() are checked against the policy of the worker. To import a URL string, the module script of a document or the script of a module worker is a support script which imports it. In a document, it's requested with an absolute URL string and allowed by its url source rather than by the nonce, which the scripts it imports would inherit. The <script> elements of iframe.sub.html and iframe_meta.sub.html (and their copies in child_dir/) get the type given in the script_type parameter, and worker.sub.html creates module workers when the module parameter is "true". Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
A classic script preloaded by a <link rel=preload> and a module script preloaded by a <link rel=modulepreload> are checked against the policy when they're preloaded, with the URL string of the <link>'s href attribute. If the preload is blocked, a violation is reported even if the <script> element requesting the script afterwards is allowed. A module which failed to preload also fails to be imported. Test that url sources allow preloaded scripts of both kinds with a relative URL string, which already works when matching the URL relative to the document and must keep working when matching the URL string as written, and with a URL string with a single-dot segment, which only works when matching the URL string as written. url_string_test() in support/util.js can now preload the script first, in the new preload.sub.html. It creates the <script> element of the type given in the script_type parameter only once the script is preloaded, as otherwise the speculative parser could request it before the preload. Not all browsers fire a securitypolicyviolation event for a blocked preload, so it also reports a violation if the preload fails. Like iframe.sub.html, it reports any other violation unless it's of the directive given in the ignored_violation_directive parameter. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
The tentative tests in content-security-policy/script-src/tentative test url
hashes, but most of them would equally apply to other syntaxes of sources which
allow a script by its URL string, which are being discussed in the issue
below. They also aren't limited to script-src, e.g. worker-src applies to
workers. And 'strict-dynamic-url' isn't about matching URLs at all.
So fork them into two new directories, like the existing ones for other kinds
of sources and keywords (e.g. unsafe-hashes):
- content-security-policy/url-sources/tentative/ for sources which allow a
script by its URL string ("url sources"). Each test file has a variant for
each syntax, given in the source parameter; for now only ?source=hash for
url hashes. url_source() in support/util.js returns the url source for a URL
string in the syntax of the variant, and assert_url_source_report() checks
the members of a violation report for it.
- content-security-policy/strict-dynamic-url/tentative/ for the behavior of
'strict-dynamic-url' which doesn't depend on url sources. The behavior with
scripts allowed by url sources is tested in url-sources/.
The tests are the same as the existing ones, with these changes:
- They're .window.js files, with the support code shared in support/util.js.
Tests which load a script with a policy and check whether it ran use
url_string_test() there, which takes the URL string the script is requested
with, the URL strings its url sources allow, and the directive and other
sources of the policy. The tests of more than one policy, of violation
reports and of 'strict-dynamic-url' keep their own promise_test().
- Test names say "url source" rather than "url hash", unless they're about a
hash of something else, e.g. of an inline script.
- Scripts are allowed by the url source of the URL string they're requested
with (e.g. the value of the src attribute), as discussed in the issue below,
rather than of the absolute URL it resolves to. Where the existing tests
request a script with an absolute URL string, both are the same. The worker
violation report tests now import the blocked script with an absolute URL
string too, so that the reported url source doesn't depend on which of the
two it's computed from. So none of the forked tests depend on whether the
absolute URL is matched: they pass both when matching as in the spec PR and
when only the URL string is matched.
- The relative URL tests are in forms.https.window.js, run with the policy in
the header only, as delivering it in a meta tag is tested by the other
files.
- The violation report tests are in one file for documents and each type of
worker, with the policies delivered as headers through pipes, and only check
the members relevant for url sources. The evalHash member will be tested
with eval hashes.
The existing tests are left as they are for now, and can be removed once the
new ones have landed.
Explainer: https://github.com/explainers-by-googlers/script-src-v2
Spec PR: w3c/webappsec-csp#784
Issue: w3c/webappsec-csp#826
Test which URL strings a url source matches, for scripts requested with different forms of URL strings, to show where matching URLs relative to the document differs from what authors write in the markup: - path-absolute (with a query, as on the https://arturjanc.com/csp-hashes-demo/ pages), scheme-relative and absolute URL strings, including an uppercase scheme and host, - dot segments, backslashes, empty queries, spaces and non-ASCII characters in queries, percent-encoded characters, fragments, character references and surrounding whitespace, - absolute and scheme-relative URL strings of cross-origin scripts, which relative URL strings don't match, and the URL string of a redirected script, which is matched rather than the redirect target. The expectations follow matching the URL string as written (e.g. the src attribute value), as discussed at TPAC 2026, rather than the absolute URL or the URL relative to the document from the spec PR. That's all that's agreed on so far, so a URL string matches wherever it resolves. Whether URL strings which aren't absolute URLs should only match same-origin scripts, to protect against injected <base> elements, is still discussed. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
Test which URL strings a url source matches when they're resolved against a base URL other than the document URL: same-origin, parent directory (as in single-page applications) and cross-origin <base> URLs, a document defining its own <base> before or after an injected one, and <base> elements allowed or blocked by base-uri. As in the URL forms tests, the expectations follow matching the URL string as written, wherever it resolves, and not the absolute URL it resolves to. That's all that's agreed on in the issue below so far. So an injected <base> can make an allowed relative URL string load a different script, also from another origin, and the tests show it: - Without base-uri, an injected cross-origin or same-origin <base> takes effect. - base-uri 'self' blocks an injected cross-origin <base>, but not a same-origin one, which can point a relative URL string to a different same-origin script. - Neither does a path in base-uri, which matches as a prefix, so base-uri can't allow only a document's own base URL and not an injected one in a subdirectory of it, which takes effect if it comes first. - base-uri 'none' blocks both, and a document's own <base> takes precedence over injected ones after it, as only the first one is used. - A document's own cross-origin <base>, allowed by base-uri, works. Path-absolute and absolute URL strings can't be pointed elsewhere by a same-origin <base>. Whether url sources should also protect documents without a suitable base-uri, e.g. by matching URL strings which aren't absolute URLs only for same-origin scripts, or by url sources which name an origin as in the hybrid syntax discussed in the issue, is still open. These tests would change accordingly. url_string_test() in support/util.js can now also add other directives to the policy and insert <base> elements. iframe.sub.html and iframe_meta.sub.html (and their copies in child_dir/) insert them for the base_url parameters. The tests in which base-uri blocks a <base> also pass base-uri as ignored_violation_directive, so that its violation, which isn't the result of the test, doesn't end it early. Any other violation is still reported. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826
…ase64; r=tschuster The script-url-blocked-report-contains-hash tests compared the urlHash of the violation report against a base64url encoded, unpadded hash, while Chromium reports standard, padded base64. They could only pass for URLs whose hash contains no '+' or '/', and fail for the URL the tests use. The encoding isn't specified yet, as the spec PR doesn't define urlHash, so expect the format Chromium reports. It can be used unchanged in a url-hash-source, as the spec PR matches hashes against their standard, padded base64 encoding. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337041
…rict-dynamic-url.enabled prefs; r=tschuster Gate support for CSP url hashes (url-hash-source) and the 'strict-dynamic-url' keyword separately. How url sources are spelled is still being discussed, and url hashes may be replaced by another kind of url source, while 'strict-dynamic-url' doesn't depend on that and can stay enabled. Both prefs are disabled by default. The next patch adds a CI variant which enables them, and the following patches implement the features behind them. Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826 Differential Revision: https://phabricator.services.mozilla.com/D337042
The script-url-blocked-report-contains-hash tests compared the urlHash of the violation report against a base64url encoded, unpadded hash, while Chromium reports standard, padded base64. They could only pass for URLs whose hash contains no '+' or '/', and fail for the URL the tests use. The encoding isn't specified yet, as the spec PR doesn't define urlHash, so expect the format Chromium reports. It can be used unchanged in a url-hash-source, as the spec PR matches hashes against their standard, padded base64 encoding. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337041 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=2086032 gecko-commit: 6b2790e603c89e144045d9ec34f7d87613a093cd gecko-commit-git: bd11a08e83c00eab8fe18d7a77be75f867d543aa gecko-reviewers: tschuster
…ase64; r=tschuster The script-url-blocked-report-contains-hash tests compared the urlHash of the violation report against a base64url encoded, unpadded hash, while Chromium reports standard, padded base64. They could only pass for URLs whose hash contains no '+' or '/', and fail for the URL the tests use. The encoding isn't specified yet, as the spec PR doesn't define urlHash, so expect the format Chromium reports. It can be used unchanged in a url-hash-source, as the spec PR matches hashes against their standard, padded base64 encoding. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337041 UltraBlame original commit: 6b2790e603c89e144045d9ec34f7d87613a093cd
…rict-dynamic-url.enabled prefs; r=tschuster Gate support for CSP url hashes (url-hash-source) and the 'strict-dynamic-url' keyword separately. How url sources are spelled is still being discussed, and url hashes may be replaced by another kind of url source, while 'strict-dynamic-url' doesn't depend on that and can stay enabled. Both prefs are disabled by default. The next patch adds a CI variant which enables them, and the following patches implement the features behind them. Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826 Differential Revision: https://phabricator.services.mozilla.com/D337042 UltraBlame original commit: 9c5795aedd1164dc31bc310825b0f6f96c7f254e
…ase64; r=tschuster The script-url-blocked-report-contains-hash tests compared the urlHash of the violation report against a base64url encoded, unpadded hash, while Chromium reports standard, padded base64. They could only pass for URLs whose hash contains no '+' or '/', and fail for the URL the tests use. The encoding isn't specified yet, as the spec PR doesn't define urlHash, so expect the format Chromium reports. It can be used unchanged in a url-hash-source, as the spec PR matches hashes against their standard, padded base64 encoding. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337041 UltraBlame original commit: 6b2790e603c89e144045d9ec34f7d87613a093cd
…rict-dynamic-url.enabled prefs; r=tschuster Gate support for CSP url hashes (url-hash-source) and the 'strict-dynamic-url' keyword separately. How url sources are spelled is still being discussed, and url hashes may be replaced by another kind of url source, while 'strict-dynamic-url' doesn't depend on that and can stay enabled. Both prefs are disabled by default. The next patch adds a CI variant which enables them, and the following patches implement the features behind them. Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826 Differential Revision: https://phabricator.services.mozilla.com/D337042 UltraBlame original commit: 9c5795aedd1164dc31bc310825b0f6f96c7f254e
…ase64; r=tschuster The script-url-blocked-report-contains-hash tests compared the urlHash of the violation report against a base64url encoded, unpadded hash, while Chromium reports standard, padded base64. They could only pass for URLs whose hash contains no '+' or '/', and fail for the URL the tests use. The encoding isn't specified yet, as the spec PR doesn't define urlHash, so expect the format Chromium reports. It can be used unchanged in a url-hash-source, as the spec PR matches hashes against their standard, padded base64 encoding. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337041 UltraBlame original commit: 6b2790e603c89e144045d9ec34f7d87613a093cd
…rict-dynamic-url.enabled prefs; r=tschuster Gate support for CSP url hashes (url-hash-source) and the 'strict-dynamic-url' keyword separately. How url sources are spelled is still being discussed, and url hashes may be replaced by another kind of url source, while 'strict-dynamic-url' doesn't depend on that and can stay enabled. Both prefs are disabled by default. The next patch adds a CI variant which enables them, and the following patches implement the features behind them. Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826 Differential Revision: https://phabricator.services.mozilla.com/D337042 UltraBlame original commit: 9c5795aedd1164dc31bc310825b0f6f96c7f254e
…xtension-reviewers,robwu When security.csp.url-hashes.enabled is set, parse 'url-<hash-algorithm>- <base64-value>' source expressions into nsCSPUrlHashSrc, a sibling of nsCSPHashSrc, and serialize them back with the "url-" prefix. With the pref disabled, they're ignored as before. Matching them against script requests is implemented separately. url-hash-source is a separate grammar from hash-source, so unlike hashes, url hashes never match inline content, don't disable 'unsafe-inline' and aren't integrity metadata. 'strict-dynamic' doesn't ignore them, and they count as a usable source for its "no hash or nonce" warning. The validators of built-in page and add-on CSPs reject them, as they can allow remote scripts. test_csp_validator.js checks that add-on CSPs reject them, and ignore them with the pref disabled. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337047
…xtension-reviewers,robwu When security.csp.url-hashes.enabled is set, parse 'url-<hash-algorithm>- <base64-value>' source expressions into nsCSPUrlHashSrc, a sibling of nsCSPHashSrc, and serialize them back with the "url-" prefix. With the pref disabled, they're ignored as before. Matching them against script requests is implemented separately. url-hash-source is a separate grammar from hash-source, so unlike hashes, url hashes never match inline content, don't disable 'unsafe-inline' and aren't integrity metadata. 'strict-dynamic' doesn't ignore them, and they count as a usable source for its "no hash or nonce" warning. The validators of built-in page and add-on CSPs reject them, as they can allow remote scripts. test_csp_validator.js checks that add-on CSPs reject them, and ignore them with the pref disabled. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337047 UltraBlame original commit: 12934243fde033b1f6564ba4c3d562aa1fe59322
…xtension-reviewers,robwu When security.csp.url-hashes.enabled is set, parse 'url-<hash-algorithm>- <base64-value>' source expressions into nsCSPUrlHashSrc, a sibling of nsCSPHashSrc, and serialize them back with the "url-" prefix. With the pref disabled, they're ignored as before. Matching them against script requests is implemented separately. url-hash-source is a separate grammar from hash-source, so unlike hashes, url hashes never match inline content, don't disable 'unsafe-inline' and aren't integrity metadata. 'strict-dynamic' doesn't ignore them, and they count as a usable source for its "no hash or nonce" warning. The validators of built-in page and add-on CSPs reject them, as they can allow remote scripts. test_csp_validator.js checks that add-on CSPs reject them, and ignore them with the pref disabled. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337047 UltraBlame original commit: 12934243fde033b1f6564ba4c3d562aa1fe59322
…xtension-reviewers,robwu When security.csp.url-hashes.enabled is set, parse 'url-<hash-algorithm>- <base64-value>' source expressions into nsCSPUrlHashSrc, a sibling of nsCSPHashSrc, and serialize them back with the "url-" prefix. With the pref disabled, they're ignored as before. Matching them against script requests is implemented separately. url-hash-source is a separate grammar from hash-source, so unlike hashes, url hashes never match inline content, don't disable 'unsafe-inline' and aren't integrity metadata. 'strict-dynamic' doesn't ignore them, and they count as a usable source for its "no hash or nonce" warning. The validators of built-in page and add-on CSPs reject them, as they can allow remote scripts. test_csp_validator.js checks that add-on CSPs reject them, and ignore them with the pref disabled. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337047 UltraBlame original commit: 12934243fde033b1f6564ba4c3d562aa1fe59322
The CSP url-hash matching compares the policy's base64-value, with '-'/'_' normalized to '+'/'/', against the padded base64 encoding of the URL digest, so values without '=' padding never match per spec. Encode the hashes with padding in the test helper, i.e. don't pass omitPadding to toBase64(), so the tests don't depend on lenient decoding. Chromium ignores padding when parsing hash sources, so these tests keep passing there. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337048
The CSP url-hash matching compares the policy's base64-value, with '-'/'_' normalized to '+'/'/', against the padded base64 encoding of the URL digest, so values without '=' padding never match per spec. Encode the hashes with padding in the test helper, i.e. don't pass omitPadding to toBase64(), so the tests don't depend on lenient decoding. Chromium ignores padding when parsing hash sources, so these tests keep passing there. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337048 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=2086032 gecko-commit: d5374cf6c0e53c4def973f3a56ccea3ec9670974 gecko-commit-git: 150804d91b0bab16055597a2236e7c219a49be16 gecko-reviewers: tschuster
The CSP url-hash matching compares the policy's base64-value, with '-'/'_' normalized to '+'/'/', against the padded base64 encoding of the URL digest, so values without '=' padding never match per spec. Encode the hashes with padding in the test helper, i.e. don't pass omitPadding to toBase64(), so the tests don't depend on lenient decoding. Chromium ignores padding when parsing hash sources, so these tests keep passing there. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337048 UltraBlame original commit: d5374cf6c0e53c4def973f3a56ccea3ec9670974
The CSP url-hash matching compares the policy's base64-value, with '-'/'_' normalized to '+'/'/', against the padded base64 encoding of the URL digest, so values without '=' padding never match per spec. Encode the hashes with padding in the test helper, i.e. don't pass omitPadding to toBase64(), so the tests don't depend on lenient decoding. Chromium ignores padding when parsing hash sources, so these tests keep passing there. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337048 UltraBlame original commit: d5374cf6c0e53c4def973f3a56ccea3ec9670974
The CSP url-hash matching compares the policy's base64-value, with '-'/'_' normalized to '+'/'/', against the padded base64 encoding of the URL digest, so values without '=' padding never match per spec. Encode the hashes with padding in the test helper, i.e. don't pass omitPadding to toBase64(), so the tests don't depend on lenient decoding. Chromium ignores padding when parsing hash sources, so these tests keep passing there. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337048 UltraBlame original commit: d5374cf6c0e53c4def973f3a56ccea3ec9670974
…solute URL; r=tschuster Implement the url-hash steps of the script directives pre-request check from the spec PR in nsCSPDirective::permits(), next to the nonce and integrity checks, so url hashes can't affect other loads: - Step 1.3: allow a script-like request if the hash of its URL, without fragment and credentials, matches a url-hash-source. - Step 1.5: if the directive has a url-hash-source, block other requests instead of matching them against host-source, scheme-source and 'self'. This differs from the PR in two places which look like mistakes in it: step 1.5 falls through to "Allowed" there, where the explainer and Chromium block, and its "Is expression of hash type?" also accepts plain hash-sources, while only url-hash-sources are matched against URLs here. Relative URLs aren't matched yet, and redirected requests are matched by their target URL for now. Without security.csp.url-hashes.enabled, url-hash-sources aren't parsed, so nothing changes. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337049
…chuster Pass the original URI of a redirected request down to nsCSPDirective::permits() instead of just a "was redirected" flag, and match url-hash-sources against it rather than the redirect target. Host and scheme source matching is unchanged and still only gets the "was redirected" bit. A url hash allowlists one specific URL, so a redirect from it is expected to keep being allowed, and matching the redirect target instead would let a page find out whether an allowlisted URL redirects. This follows the explainer and Chromium, which check url hashes against the URL before redirects. The spec PR uses the request's current URL. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337050
…solute URL; r=tschuster Implement the url-hash steps of the script directives pre-request check from the spec PR in nsCSPDirective::permits(), next to the nonce and integrity checks, so url hashes can't affect other loads: - Step 1.3: allow a script-like request if the hash of its URL, without fragment and credentials, matches a url-hash-source. - Step 1.5: if the directive has a url-hash-source, block other requests instead of matching them against host-source, scheme-source and 'self'. This differs from the PR in two places which look like mistakes in it: step 1.5 falls through to "Allowed" there, where the explainer and Chromium block, and its "Is expression of hash type?" also accepts plain hash-sources, while only url-hash-sources are matched against URLs here. Relative URLs aren't matched yet, and redirected requests are matched by their target URL for now. Without security.csp.url-hashes.enabled, url-hash-sources aren't parsed, so nothing changes. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337049 UltraBlame original commit: 333ac5dcdc57cba2e78cf0fdcc2f7c8ac1c23d57
…chuster Pass the original URI of a redirected request down to nsCSPDirective::permits() instead of just a "was redirected" flag, and match url-hash-sources against it rather than the redirect target. Host and scheme source matching is unchanged and still only gets the "was redirected" bit. A url hash allowlists one specific URL, so a redirect from it is expected to keep being allowed, and matching the redirect target instead would let a page find out whether an allowlisted URL redirects. This follows the explainer and Chromium, which check url hashes against the URL before redirects. The spec PR uses the request's current URL. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337050 UltraBlame original commit: e941e20e09f3c1a6b513342aee87524abf61506a
…solute URL; r=tschuster Implement the url-hash steps of the script directives pre-request check from the spec PR in nsCSPDirective::permits(), next to the nonce and integrity checks, so url hashes can't affect other loads: - Step 1.3: allow a script-like request if the hash of its URL, without fragment and credentials, matches a url-hash-source. - Step 1.5: if the directive has a url-hash-source, block other requests instead of matching them against host-source, scheme-source and 'self'. This differs from the PR in two places which look like mistakes in it: step 1.5 falls through to "Allowed" there, where the explainer and Chromium block, and its "Is expression of hash type?" also accepts plain hash-sources, while only url-hash-sources are matched against URLs here. Relative URLs aren't matched yet, and redirected requests are matched by their target URL for now. Without security.csp.url-hashes.enabled, url-hash-sources aren't parsed, so nothing changes. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337049 UltraBlame original commit: 333ac5dcdc57cba2e78cf0fdcc2f7c8ac1c23d57
…chuster Pass the original URI of a redirected request down to nsCSPDirective::permits() instead of just a "was redirected" flag, and match url-hash-sources against it rather than the redirect target. Host and scheme source matching is unchanged and still only gets the "was redirected" bit. A url hash allowlists one specific URL, so a redirect from it is expected to keep being allowed, and matching the redirect target instead would let a page find out whether an allowlisted URL redirects. This follows the explainer and Chromium, which check url hashes against the URL before redirects. The spec PR uses the request's current URL. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337050 UltraBlame original commit: e941e20e09f3c1a6b513342aee87524abf61506a
…solute URL; r=tschuster Implement the url-hash steps of the script directives pre-request check from the spec PR in nsCSPDirective::permits(), next to the nonce and integrity checks, so url hashes can't affect other loads: - Step 1.3: allow a script-like request if the hash of its URL, without fragment and credentials, matches a url-hash-source. - Step 1.5: if the directive has a url-hash-source, block other requests instead of matching them against host-source, scheme-source and 'self'. This differs from the PR in two places which look like mistakes in it: step 1.5 falls through to "Allowed" there, where the explainer and Chromium block, and its "Is expression of hash type?" also accepts plain hash-sources, while only url-hash-sources are matched against URLs here. Relative URLs aren't matched yet, and redirected requests are matched by their target URL for now. Without security.csp.url-hashes.enabled, url-hash-sources aren't parsed, so nothing changes. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337049 UltraBlame original commit: 333ac5dcdc57cba2e78cf0fdcc2f7c8ac1c23d57
…chuster Pass the original URI of a redirected request down to nsCSPDirective::permits() instead of just a "was redirected" flag, and match url-hash-sources against it rather than the redirect target. Host and scheme source matching is unchanged and still only gets the "was redirected" bit. A url hash allowlists one specific URL, so a redirect from it is expected to keep being allowed, and matching the redirect target instead would let a page find out whether an allowlisted URL redirects. This follows the explainer and Chromium, which check url hashes against the URL before redirects. The spec PR uses the request's current URL. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337050 UltraBlame original commit: e941e20e09f3c1a6b513342aee87524abf61506a
When security.csp.strict-dynamic-url.enabled is set, support the 'strict-dynamic-url' keyword in script directives. Like 'strict-dynamic', it makes 'unsafe-inline' ignored for scripts, and it allows script requests by non-parser-inserted <script> elements, but without blocking parser-inserted ones or ignoring host-source, scheme-source and 'self'. As with 'strict-dynamic', XSLT loads aren't treated as non-parser-inserted scripts, and workers aren't affected. The first effect is part of "Does a source list allow all inline behavior for type?" in the spec PR. Its pre-request check has no step for the second one yet, so this follows §8.2 Usage of "'strict-dynamic'" in the PR, and Chromium. Spec PR: w3c/webappsec-csp#784 Differential Revision: https://phabricator.services.mozilla.com/D337051
…-url/; r=tschuster The url hash tests in script-src/tentative/ aren't limited to script-src, and 'strict-dynamic-url' isn't about matching URLs at all, so fork them into url-hashes/tentative/ and strict-dynamic-url/tentative/, like the directories for other sources and keywords. url-hashes/tentative/README.md describes how the tests are organized. The forked tests share their support code, run with the policy both in a header and in a meta tag, as variants, and allow scripts by the hash of the URL string they're requested with, as discussed in the issue below. They pass both with the spec PR's matching and when only the URL string is matched. The existing tests can be removed once these have landed. Explainer: https://github.com/explainers-by-googlers/script-src-v2 Spec PR: w3c/webappsec-csp#784 Issue: w3c/webappsec-csp#826 Differential Revision: https://phabricator.services.mozilla.com/D339265
This implements the work described in w3ctag/design-reviews#1128
Preview | Diff