-
-
Notifications
You must be signed in to change notification settings - Fork 507
Detect script tags that load or contain JavaScript to prevent strict CSP-compatibility backsliding. #1956
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
Conversation
1f3640a
to
c6e62ce
Compare
…ed by the new script templating functions: wp_get_script_tag() and wp_get_inline_script_tag().
c6e62ce
to
3ea1acd
Compare
Hi @enricocarraro, welcome to this repo! Thanks for the PR. Checklist of things to do before this PR will be properly reviewed:
Please feel free to ask for as much guidance as you need from me and the others in the team. In my case, my remarks will often presume you know what you're doing with PHPCS (as why would you send in a sniff otherwise?), please don't let that intimidate you and ask for as much clarification as you need. I've had a quick look at it so far and to me it's unclear what this sniff is looking for based on the PR description, so I can't review the code to see if the sniff actually does what it is supposed to do. Aside from that, the PR description refers to a function which won't be introduced in WP until version Other notes:
|
Oh and from looking at the PRs for Core, we will need to verify if there are any other sniffs looking at the content of inline scripts and see if these need adjusting to allow for this new way of adding inline scripts, as looking for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests?
Hi @jrfnl, thanks for taking the time to look into this PR and pointing out what is not clear about it.
The sniff is looking for script tags that contain inline JavaScript, since the
I am not sure what the most appropriate category would be; I placed it into
I will make sure to include the property in the next commits.
In retrospect, I think it would be better to add this new sniff under
In my opinion, both |
Good point, @jrfnl ! |
While it would be nice to have a sniff for this, the PR as-is is not mergable as there are open questions and the sniff isn't accompanied by tests. No action has been taken on this in over two years, so I'm going to close this PR. |
From WP trac ticket #51407:
A series of efforts have been made to enable strict-CSP compatibility in WordPress, the most important being assuring each trusted script tag can be injected with a nonce (WP PR 498, and WP PR 551).
This sniff should prevent developers from writing strict-CSP incompatible code, at least for what concerns script tags. It detects script tags that should be either enqueued or generated by the new script templating functions (WP PR 591) that will be introduced in WordPress 5.7.
Script loaders standard behaviour:
wp_enqueue_script()
is defined: usewp_enqueue_script()
;wp_get_script_tag()
or print directly the tag withwp_print_script_tag()
.Inline scripts standard behaviour:
wp_add_inline_script()
is defined: usewp_add_inline_script()
;wp_get_inline_script_tag()
or print directly the tag withwp_print_inline_script_tag()
.Checklist: