Skip to content

Don't add csp-headers if none are required #21318

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

Merged
merged 1 commit into from
Jan 17, 2017
Merged

Don't add csp-headers if none are required #21318

merged 1 commit into from
Jan 17, 2017

Conversation

arjenm
Copy link
Contributor

@arjenm arjenm commented Jan 17, 2017

Q A
Branch? 3.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets This PR is also the ticket
License MIT

In 3.2 a tool to adjust Content Security Policy headers in combination with the WebProfiler was added. We encountered a bug in its behavior.
We had CSP-headers that did not have a script-src/style-src nor a default-src (it was something like form-action: https:). In that scenario, the ContentSecurityPolicyHandler would add script-src: 'unsafe-inline' 'nonce-....', but that would actually change the "everything is allowed scenario" into "only inline and nonce-... is allowed". The result was only the javascript of WebProfiler was allowed, rather than everything.

This PR fixes the scenario where no default-src nor a script-src/style-src is provided. It simply continue's rather than treats it as an empty list of rules that need additional rules.

A bug I did find, but not fix, is the fact that that 'unsafe-inline' is ignored in at least Firefox and Chrome due to the fact there is also a nonce-element in the rule.

@stof
Copy link
Member

stof commented Jan 17, 2017

A bug I did find, but not fix, is the fact that that 'unsafe-inline' is ignored in at least Firefox and Chrome due to the fact there is also a nonce-element in the rule.

This is not a bug. unsafe-inline combined with nonces is about supporting both CSP 1 and CSP 2 together

@arjenm
Copy link
Contributor Author

arjenm commented Jan 17, 2017

Ok, it doesn't really matter for my PR anyway, so I scratched that. Thanks for correcting me :)

@romainneutron
Copy link
Contributor

LGTM 👍

@fabpot
Copy link
Member

fabpot commented Jan 17, 2017

Thank you @arjenm.

@fabpot fabpot merged commit 6fecc94 into symfony:3.2 Jan 17, 2017
fabpot added a commit that referenced this pull request Jan 17, 2017
This PR was merged into the 3.2 branch.

Discussion
----------

Don't add csp-headers if none are required

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | This PR is also the ticket
| License       | MIT

In 3.2 a tool to adjust Content Security Policy headers in combination with the WebProfiler was added. We encountered a bug in its behavior.
We had CSP-headers that did not have a script-src/style-src nor a default-src (it was something like `form-action: https:`). In that scenario, the ContentSecurityPolicyHandler would add `script-src: 'unsafe-inline' 'nonce-....'`, but that would actually change the "everything is allowed scenario" into "only inline and nonce-... is allowed". The result was _only_ the javascript of WebProfiler was allowed, rather than everything.

This PR fixes the scenario where no default-src nor a script-src/style-src is provided. It simply continue's rather than treats it as an empty list of rules that need additional rules.

~A bug I did find, but not fix, is the fact that that `'unsafe-inline'` is ignored in at least Firefox and Chrome due to the fact there is also a nonce-element in the rule.~

Commits
-------

6fecc94 Don't add csp-headers if none are required
@fabpot fabpot mentioned this pull request Feb 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants