Skip to content

[Profiler] Fix dump makes toolbar disappear #27189

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
May 9, 2018
Merged

[Profiler] Fix dump makes toolbar disappear #27189

merged 1 commit into from
May 9, 2018

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented May 7, 2018

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

Don't know if there is a better solution than executing eval on the global scope.

For ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval

If you use the eval function indirectly, by invoking it via a reference other than eval, as of ECMAScript 5 it works in the global scope rather than the local scope. This means, for instance, that function declarations create global functions, and that the code being evaluated doesn't have access to local variables within the scope where it's being called.

@fabpot
Copy link
Member

fabpot commented May 9, 2018

Thank you @ogizanagi.

@fabpot fabpot merged commit 0cd51ae into symfony:4.1 May 9, 2018
fabpot added a commit that referenced this pull request May 9, 2018
This PR was merged into the 4.1 branch.

Discussion
----------

[Profiler] Fix dump makes toolbar disappear

| Q             | A
| ------------- | ---
| Branch?       | 4.1 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #27180   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

Don't know if there is a better solution than executing eval on the global scope.

For ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
> If you use the eval function indirectly, by invoking it via a reference other than eval, as of ECMAScript 5 it works in the global scope rather than the local scope. This means, for instance, that function declarations create global functions, and that the code being evaluated doesn't have access to local variables within the scope where it's being called.

Commits
-------

0cd51ae [Profiler] Fix dump makes toolbar disappear
@ogizanagi ogizanagi deleted the fix/dump_makes_toolbar_disappear branch May 9, 2018 06:02
/* Evaluate in global scope scripts embedded inside the toolbar */
eval.call({}, ([].slice.call(el.querySelectorAll('script')).map(function (script) {
return script.firstChild.nodeValue;
}).join('\n')));
Copy link
Member

Choose a reason for hiding this comment

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

we should join them using ;\n to avoid issues in case of having a script without a final semi-colon. The ASI rules might not always end a statement on a newline char.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed in 0998710

@fabpot fabpot mentioned this pull request May 21, 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
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.

6 participants