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

Disable CSP header on exception pages only in debug #25933

Merged
merged 1 commit into from
Jan 26, 2018

Conversation

ostrolucky
Copy link
Contributor

@ostrolucky ostrolucky commented Jan 26, 2018

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #24772
License MIT
Doc PR

Based on a feedback we received, there are situations on production when it's desired to have CSP header in place even if exception occurred.

This uses now same condition that is used by ExceptionController in TwigBridge to evaluate if styled exception template is going to be shown, minus showException request attribute which don't make sense in this context, because it's used by PreviewController only and in such case this listener isn't triggered.

Overriding CSP header via HTML meta tag unfortunately, but not surprisingly, doesn't work.

Same condition is used by default TwigBridge ExceptionController
to evaluate if styled exception page is supposed to be shown.
@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Jan 26, 2018
@fabpot
Copy link
Member

fabpot commented Jan 26, 2018

Thank you @ostrolucky.

@fabpot fabpot merged commit b77538c into symfony:2.7 Jan 26, 2018
fabpot added a commit that referenced this pull request Jan 26, 2018
…lucky)

This PR was merged into the 2.7 branch.

Discussion
----------

Disable CSP header on exception pages only in debug

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #24772
| License       | MIT
| Doc PR        |

Based on a feedback we received, there are situations on production when it's desired to have CSP header in place even if exception occurred.

This uses now same condition that is used by ExceptionController in TwigBridge to evaluate if styled exception template is going to be shown, minus `showException` request attribute which don't make sense in this context, because it's used by PreviewController only and in such case this listener isn't triggered.

Overriding CSP header via HTML meta tag unfortunately, but not surprisingly, doesn't work.

Commits
-------

b77538c Disable CSP header on exception pages only in debug
@stof
Copy link
Member

stof commented Jan 29, 2018

Overriding CSP header via HTML meta tag unfortunately, but not surprisingly, doesn't work.

That's logic: the meta tag can add a new header, not replace the HTTP headers. And the behavior of browsers when receiving multiple CSP headers is to apply all policies (making a AND between them). So a new header cannot disable the other ones.

@@ -32,11 +32,13 @@ class ExceptionListener implements EventSubscriberInterface
{
protected $controller;
protected $logger;
protected $debug;
Copy link
Member

Choose a reason for hiding this comment

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

should have been private (too bad that I see it just after the release is done)

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.

None yet

5 participants