Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[HttpKernel] Disable CSP header on exception pages#25532

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:2.7fromostrolucky:fix-24772
Jan 4, 2018

Conversation

@ostrolucky
Copy link
Contributor

@ostroluckyostrolucky commentedDec 17, 2017
edited
Loading

QA
Branch?2.7
Bug fix?yes
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#24772
LicenseMIT
Doc PR-

This makes exception pages styled normally when using CSP listener. Technically it's new feature, but from user POV it's bugfix, because it's really confusing to get a blank page. It takes a while to realize it is because of enabled CSP. Therefore I'm trying to push it as patch release.

@javiereguiluz
Copy link
Member

@romainneutron as our CSP expert, would you agree with this change? Thanks!

@ostrolucky adding new listeners always impacts performance. Can't this header removal be done in the existingonKernelException ... or better, can this CSP header not added at all for exceptions in the first place? Thanks!

@ostrolucky
Copy link
ContributorAuthor

There must be CSP header removal, because we don't have control over not adding it, it's done in userspace.
It can't be done in onKernelException, because that event is triggered before onKernelResponse, so header would be re-added after ExceptionListener is long done.

What can be done to avoid unnecessarily adding new listener is to add this listener from inside onKernelException, but that will require access to EventDispatcher in this listener. Let me know if you would like that more, or there is better way.

@stof
Copy link
Member

@ostrolucky you can have access to the EventDispatcher. It is passed as third argument to the listener when calling it.

ostrolucky reacted with thumbs up emoji

@stof
Copy link
Member

However, if the listener is added dynamically, don't forget to remove it dynamically too (to reset state properly for reused kernel).

@nicolas-grekasnicolas-grekas added this to the2.7 milestoneDec 18, 2017
@ostrolucky
Copy link
ContributorAuthor

ostrolucky commentedDec 18, 2017
edited
Loading

@stof Unfortunately I can't do that. According to BC promise I can't add arguments to public method 🙁

edit: but added it via func_get_arg. Better?

@ostroluckyostroluckyforce-pushed thefix-24772 branch 3 times, most recently from4b40940 to187e429CompareDecember 18, 2017 23:09
@javiereguiluz
Copy link
Member

Can anybody think of a simpler solution to this issue? The func_get_arg, the listeners, etc. look a bit complicated (but maybe this is the simplest solution possible).

@chalasr
Copy link
Member

func_get_arg() is the way to go I think. Should it trigger a deprecation notice in 4.1 to really add the dispatcher as optional arg in 5.0?

@nicolas-grekas
Copy link
Member

I would suggest to make the class final in 4.1 (can be done now)

@nicolas-grekas
Copy link
Member

The code looks good to me.
@ostrolucky do you think you could add a test case for it?

@ostrolucky
Copy link
ContributorAuthor

Sure. What kind of test?

@nicolas-grekas
Copy link
Member

eg one that check that whe appropriate, the header is removed, and the event listener is not left in place?

{
$exception =$event->getException();
$request =$event->getRequest();
$eventDispatcher =func_num_args() >2 ?func_get_arg(2) :null;
Copy link
Member

Choose a reason for hiding this comment

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

just define the proper arguments instead

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Can I define them as non-optional?

Choose a reason for hiding this comment

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

@stof that'd be a BC break...

Copy link
Member

Choose a reason for hiding this comment

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

hmm, our listener methods are indeed not marked as@internal 😢

@ostrolucky
Copy link
ContributorAuthor

status: needs review

$cspRemovalListener =function (FilterResponseEvent$event)use (&$cspRemovalListener,$eventDispatcher) {
$event->getResponse()->headers->remove('Content-Security-Policy');
$eventDispatcher->removeListener(KernelEvents::RESPONSE,$cspRemovalListener);
};
Copy link
Member

Choose a reason for hiding this comment

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

This code should be move under theif as it's only used there.

@fabpot
Copy link
Member

Thank you@ostrolucky.

@fabpotfabpot merged commitf33a383 intosymfony:2.7Jan 4, 2018
fabpot added a commit that referenced this pull requestJan 4, 2018
…ucky)This PR was merged into the 2.7 branch.Discussion----------[HttpKernel] Disable CSP header on exception pages| Q             | A| ------------- | ---| Branch?       | 2.7| Bug fix?      | yes| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#24772| License       | MIT| Doc PR        | -This makes exception pages styled normally when using CSP listener. Technically it's new feature, but from user POV it's bugfix, because it's really confusing to get a blank page. It takes a while to realize it is because of enabled CSP. Therefore I'm trying to push it as patch release.Commits-------f33a383 [HttpKernel] Disable CSP header on exception pages
tobymackenzie added a commit to tobymackenzie/tobymackenzie.com.site that referenced this pull requestJan 10, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof requested changes

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

2.7

Development

Successfully merging this pull request may close these issues.

7 participants

@ostrolucky@javiereguiluz@stof@chalasr@nicolas-grekas@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp