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

CSP headers are incorrect with multiple rules #682

Open
letanloc1998 opened this issue Oct 8, 2024 · 3 comments
Open

CSP headers are incorrect with multiple rules #682

letanloc1998 opened this issue Oct 8, 2024 · 3 comments

Comments

@letanloc1998
Copy link

Hi everyone,

When we config CSP header like:

Content-Security-Policy: a
Content-Security-Policy: b
Content-Security-Policy: c

Each header is independent. (It means we must write rule for both script-src-elem and connect-src,...)

How to split Content-Security-Policy to multiple headers? Because it's very long.

Many thanks

@mikewest
Copy link
Member

mikewest commented Oct 8, 2024

I don't think I understand the question.

Content-Security-Policy: a
Content-Security-Policy: b
Content-Security-Policy: c

would imply that a and b and c are all enforced. You don't need to specify each directive in a distinct header, though:

Content-Security-Policy: a; b; c

would also enforce a, b, and c. The two models differ in some edge cases that are important (e.g. enforcing hashes or nonces and an allowlist of domains), but they're often interchangable.

Is that somewhere near what you're asking?

@annevk
Copy link
Member

annevk commented Oct 8, 2024

Per combining semantics shouldn't it be identical to

Content-Security-Policy: a, b, c

?

@mikewest
Copy link
Member

mikewest commented Oct 8, 2024

Yes. But Content-Security-Policy: a, b, c is not identical to Content-Security-Policy: a; b; c. The former creates three policies, all of which are enforced. The latter creates one policy with three directives, all of which are enforced. These are distinct. For example, a simplified version of the headers sent from myaccount.google.com is:

content-security-policy: script-src ... 'nonce-75mShyMY4JEfhPfGuk2DeA';object-src 'none'; ...
content-security-policy: script-src https://apis.google.com [more domains go here]; ...

That enforces a nonce constraint and also enforces an allowlist of domains. That's not possible to do in a single policy.

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

No branches or pull requests

3 participants