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

Appearance settings

[3.2][WebProfilerBundle] Fix bundle usage in Content-Security-Policy context without unsafe-inline #18568

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
Jun 9, 2016

Conversation

romainneutron
Copy link
Contributor

Q A
Branch? 3.2
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #15397
License MIT
Doc PR N/A

Hello, this PR fixes the compatibility of the WebprofilerBundle in a context where Content-Security-Policy headers are could prevent unsafe-inline of script-src or style-src directives.

This PR has been originally proposed in 2.8 in #18434

if (!$this->authorizesInline($directives, $type)) {
if (!isset($headers[$header][$type])) {
if (isset($headers[$header]['default-src'])) {
$headers[$header][$type] = $headers[$header]['default-src'];
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is nested pretty deeply, it might be more readable if the first if becomes a guard clause with a continue

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 17, 2016

How could we ensure that strict CSP compliancy is preserved on the long run?
I suggest looking at https://docs.travis-ci.com/user/gui-and-headless-browsers/

@romainneutron
Copy link
Contributor Author

Toggling to Need Work : I will disable CSP when browsing profiler pages and will introduce nonce only for toolbar injection.

@romainneutron romainneutron force-pushed the fix-csp-webprofiler-3.2 branch 5 times, most recently from cda45ee to e5e4f73 Compare April 17, 2016 16:00
@romainneutron
Copy link
Contributor Author

Work done, it can now be reviewed

@romainneutron
Copy link
Contributor Author

How could we ensure that strict CSP compliancy is preserved on the long run?

@nicolas-grekas you asked this question. Checking if the injected script has the appropriate nonce, headers are included and rendered toolbar include nonce should be alright.

@romainneutron romainneutron force-pushed the fix-csp-webprofiler-3.2 branch 2 times, most recently from 0a024c0 to 3083453 Compare April 18, 2016 09:09
@@ -27,7 +27,6 @@
{{ dump.data|raw }}
</div>
{% endfor %}
<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="var h = this.parentNode.innerHTML, rx=/<script>(.*?)<\/script>/g, s; while (s = rx.exec(h)) {eval(s[1]);};" />
Copy link
Member

Choose a reason for hiding this comment

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

@nicolas-grekas what was the reason for this one ?

Copy link
Member

Choose a reason for hiding this comment

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

Toggle nested levels in the toolbar

$this->cleanHeaders($response);
$this->updateCspHeaders($response, $nonces);

return $nonces;
Copy link
Member

Choose a reason for hiding this comment

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

returning something from an event listener looks weird to me

Copy link
Member

Choose a reason for hiding this comment

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

OK, this method is actually not an event listener. So the phpdoc is wrong (and the naming is not that good either)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@romainneutron
Copy link
Contributor Author

Thanks @stof for this review, I'm going to take care of this


/**
* @param Response $response
*/
Copy link
Member

Choose a reason for hiding this comment

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

to be removed

@fabpot
Copy link
Member

fabpot commented Jun 8, 2016

👍

@romainneutron romainneutron force-pushed the fix-csp-webprofiler-3.2 branch 2 times, most recently from e48e16e to 52ae783 Compare June 9, 2016 10:58
@romainneutron
Copy link
Contributor Author

PR updated, comments addressed

fabpot added a commit that referenced this pull request Jun 9, 2016
…ron)

This PR was merged into the 2.8 branch.

Discussion
----------

[2.8][WebProfilerBundle] Fix invalid CSS style

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

Related to #18568 (comment)

Commits
-------

aa35a16 [WebProfilerBundle] Fix invalid CSS style
@romainneutron romainneutron force-pushed the fix-csp-webprofiler-3.2 branch from 52ae783 to ef3827f Compare June 9, 2016 11:10
*
* @return array
*/
private function updateCspHeaders(Response $response, array $nonces = array()) {
Copy link
Member

Choose a reason for hiding this comment

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

{ on a new line

@romainneutron romainneutron force-pushed the fix-csp-webprofiler-3.2 branch from ef3827f to bb94559 Compare June 9, 2016 11:15
@romainneutron romainneutron force-pushed the fix-csp-webprofiler-3.2 branch from bb94559 to 571a1f2 Compare June 9, 2016 11:16
@fabpot
Copy link
Member

fabpot commented Jun 9, 2016

Thank you @romainneutron.

@fabpot fabpot merged commit 571a1f2 into symfony:master Jun 9, 2016
fabpot added a commit that referenced this pull request Jun 9, 2016
…ecurity-Policy context without unsafe-inline (romainneutron)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[3.2][WebProfilerBundle] Fix bundle usage in Content-Security-Policy context without unsafe-inline

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

Hello, this PR fixes the compatibility of the WebprofilerBundle in a context where Content-Security-Policy headers are could prevent `unsafe-inline` of `script-src` or `style-src` directives.

This PR has been originally proposed in 2.8 in #18434

Commits
-------

571a1f2 [WebProfilerBundle] Fix bundle usage in Content-Security-Policy context without unsafe-inline
@romainneutron romainneutron deleted the fix-csp-webprofiler-3.2 branch June 9, 2016 11:19
@fabpot fabpot mentioned this pull request Oct 27, 2016
@herndlm
Copy link
Contributor

herndlm commented Jun 4, 2018

Could this be broken since 4.1 in contexts where unsafe-eval is not allowed? I had problems after upgrading because of CSP violations, but need to retest tomorrow

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.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.