Git Product home page Git Product logo

Comments (13)

duracelltomi avatar duracelltomi commented on August 17, 2024 1

I can of course.

What about adding a filter like gtm4wp_get_csp_nonce and what is returned is added to the <script> tag?

from gtm4wp.

duracelltomi avatar duracelltomi commented on August 17, 2024 1

I'm just finishing my vacation time, will do the release next week

from gtm4wp.

duracelltomi avatar duracelltomi commented on August 17, 2024 1

Indeed, however 1.21 beta1 is now out, you can test it:
https://github.com/duracelltomi/gtm4wp/releases/tag/1.21.beta1

from gtm4wp.

duracelltomi avatar duracelltomi commented on August 17, 2024

This filter was removed because it introduced some security risks.

If you want to alter the container code in any way, you should turn off the container code in plugin options and add your own container code using the GTM4WP_WPACTION_AFTER_CONTAINER_CODE / gtm4wp_after_container_code filter which fires regardless of whether container code is turned on or off in plugin settings.

Just make sure to output the full header script.

from gtm4wp.

gettonet avatar gettonet commented on August 17, 2024

Datalayer script is making it impossible to add to CSP as hash, as it is dynamically created and it's different on every page:


<script data-cfasync="false" data-pagespeed-no-defer' . ( $has_html5_support ? ' type="text/javascript"' : '' ) . ( $add_cookiebot_ignore ? ' data-cookieconsent="ignore"' : '' ) . '>';

	if ( '' !== $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] ) {
		$gtm4wp_datalayer_data = array();
		$gtm4wp_datalayer_data = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_DATALAYER, $gtm4wp_datalayer_data );

		echo '
	var dataLayer_content = ' . wp_json_encode( $gtm4wp_datalayer_data, JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK ) . ';';

		echo '
	' . esc_js( $gtm4wp_datalayer_name ) . '.push( dataLayer_content );';
	}

	echo '
</script>';

It is not the container itself, as it can be added to CSP as hash.
But what to do with datalayer script?
Wouldn't it be worth considering adding a filter for nonce?

from gtm4wp.

gettonet avatar gettonet commented on August 17, 2024

That would be great!

from gtm4wp.

gettonet avatar gettonet commented on August 17, 2024

I tried to help, so created a pull request here: #352

from gtm4wp.

duracelltomi avatar duracelltomi commented on August 17, 2024

Please review this branch: 7faf339

from gtm4wp.

gettonet avatar gettonet commented on August 17, 2024

Looking good @duracelltomi ! Thank you for your effort, this is indeed an improvement and a huge help to anyone who's using your plugin and dealing with CSP setup.

from gtm4wp.

gettonet avatar gettonet commented on August 17, 2024

@duracelltomi what's the status, would you like to release this update soon?

from gtm4wp.

gettonet avatar gettonet commented on August 17, 2024

@duracelltomi just wanted to follow up, will the release be public soon?

from gtm4wp.

duracelltomi avatar duracelltomi commented on August 17, 2024

If nothing extreme happens, tomorrow.

from gtm4wp.

gettonet avatar gettonet commented on August 17, 2024

Something extreme must have happened! :) @duracelltomi

from gtm4wp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.