Avoid calling eval when there is no script embedded in the toolbar#27584
Conversation
| return script.firstChild.nodeValue; | ||
| }).join(';\n'))); | ||
| var i, scripts = [].slice.call(el.querySelectorAll('script')); | ||
| for (i = 0; i < scripts.length; ++i) { |
There was a problem hiding this comment.
Why not define i inside the loop? for (var i..., that way you can be sure you won't get any scope bleeding.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
I was confusing it with let indeed. In case of var this is indeed better 👍
|
Thank you @stof. |
… 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
|
I'm late but thank you taking care of this @stof 👍 |
#27189 changed the way embedded scripts were eval'd for the toolbar. But it also refactored the code in a way triggering
evalall 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-evalin 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.