Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Avoid calling eval when there is no script embedded in the toolbar #27584

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 13, 2018

Conversation

stof
Copy link
Member

@stof stof commented Jun 12, 2018

Q A
Branch? 4.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27583
License MIT
Doc PR n/a

#27189 changed the way embedded scripts were eval'd for the toolbar. But it also refactored the code in a way triggering eval all the time, even when there is no embedded script, which was reported several times as an issue with CSP.

While the debug panel (showing dumps) still requires having unsafe-eval in the CSP header (due to embedding scripts that we eval), this PR reverts back to the behavior of Symfony 4.0 and older, where only toolbars actually embedding scripts have this CSP compat issue.

return script.firstChild.nodeValue;
}).join(';\n')));
var i, scripts = [].slice.call(el.querySelectorAll('script'));
for (i = 0; i < scripts.length; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not define i inside the loop? for (var i..., that way you can be sure you won't get any scope bleeding.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this variable is not only used by this loop but also by next ones. Putting it inside the loop might make us remove the variable declaration by mistake in a refactoring, which would make us use a global variable here.

that way you can be sure you won't get any scope bleeding.

That's wrong. It would be true when using let, but not for var (which is scoped only by functions, not by loops)

Copy link
Contributor

Choose a reason for hiding this comment

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

I was confusing it with let indeed. In case of var this is indeed better 👍

@fabpot
Copy link
Member

fabpot commented Jun 13, 2018

Thank you @stof.

@fabpot fabpot merged commit a0f78a5 into symfony:4.1 Jun 13, 2018
fabpot added a commit that referenced this pull request Jun 13, 2018
… toolbar (stof)

This PR was merged into the 4.1 branch.

Discussion
----------

Avoid calling eval when there is no script embedded in the toolbar

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27583
| License       | MIT
| Doc PR        | n/a

#27189 changed the way embedded scripts were eval'd for the toolbar. But it also refactored the code in a way triggering `eval` all the time, even when there is no embedded script, which was reported several times as an issue with CSP.

While the debug panel (showing dumps) still requires having `unsafe-eval` in the CSP header (due to embedding scripts that we eval), this PR reverts back to the behavior of Symfony 4.0 and older, where only toolbars actually embedding scripts have this CSP compat issue.

Commits
-------

a0f78a5 Avoid calling eval when there is no script embedded in the toolbar
@ogizanagi
Copy link
Contributor

I'm late but thank you taking care of this @stof 👍

@fabpot fabpot mentioned this pull request Jun 25, 2018
@stof stof deleted the fix_csp_eval branch July 24, 2018 07:21
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