add nonces to all inline JS for plugins
-
Hi there,
I am trying to make my site more secure from XXS, and one way to do this is to add nonces to any inline Javascript.
I came across this PHP snippet to be added to the functions.php on stackoverflow:add_action( 'run_custom_nonce_value', 'custom_nonce_value' ); function custom_nonce_value () { $created_nonce = wp_create_nonce(); define( 'NONCE_RANDVALUE', $created_nonce ); }
add_filter( 'script_loader_tag', 'add_nonce_to_script', 10, 3 ); function add_nonce_to_script( $tag, $handle, $source ) { custom_nonce_value(); $val_nonce = NONCE_RANDVALUE; $search = "type='text/javascript'"; $replace = "type='text/javascript' nonce='".$val_nonce."' "; $subject = $tag; $output = str_replace($search, $replace, $subject); return $output; }
Is there any way to apply this to all JS that is loaded inline, including any plugin you use?
thx for any help on this.The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘add nonces to all inline JS for plugins’ is closed to new replies.