Skip to content

Conversation

@enricocarraro
Copy link

@enricocarraro enricocarraro commented Aug 26, 2020

This PR uses the newly introduced script tag formatting functions introduced in #591 to generate every script tag.
I followed this guide on adopting CSP, considering the strict-dynamic option enabled.
I made a plugin prototype that enables Strict CSP to test these changes.

Trac ticket: https://core.trac.wordpress.org/ticket/39941


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@enricocarraro enricocarraro force-pushed the inline_script_using_inline_js_function branch from cda5081 to cd28054 Compare August 27, 2020 16:14
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

It looks like there are some WordPress coding standards violations in here: https://travis-ci.com/github/WordPress/wordpress-develop/jobs/378458383 Have you set up your local environment to lint for these?

* @param string $javascript Inline JavaScript code.
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
*/
do_action( 'wp_get_inline_script_tag', $javascript, $attributes );
Copy link
Author

@enricocarraro enricocarraro Oct 2, 2020

Choose a reason for hiding this comment

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

@Ayesh I added the change you suggested. Would you mind giving me your opinion on this?
It can be used in the following way:

add_action(
    'wp_get_inline_script_tag',
    function ( $js ) {
        $hash = sha256( $js );
        header( "Content-Security-Policy: script-src 'sha256-$hash'" );
    }
);

Edit: the change was reverted; relevant discussion here.

@enricocarraro enricocarraro changed the title Refactoring inline scripts in the admin area to use inline_js Refactor <script> tag to be generated by wp_get_script_tag and related functions. Oct 5, 2020
@enricocarraro enricocarraro force-pushed the inline_script_using_inline_js_function branch 3 times, most recently from 1c12606 to 609bdbe Compare October 14, 2020 15:40
@enricocarraro enricocarraro force-pushed the inline_script_using_inline_js_function branch 5 times, most recently from 8defd6c to 24c26b9 Compare October 20, 2020 08:30
@hellofromtonya
Copy link
Contributor

Closed with changeset https://core.trac.wordpress.org/changeset/50167

@swissspidy
Copy link
Member

@hellofromtonya Actually, no. That commit only resolved #498.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants