charlie-tango / hooks

Collection of React Hooks used by Charlie Tango
MIT License
76 stars 10 forks source link

fix(useScript): apply attributes before appending script to DOM #100

Closed schnogz closed 2 years ago

schnogz commented 2 years ago

When using security focused attributes for scripts such as nonce, these values need to be set on the element before it is appended to the DOM. Setting afterwards breaks the security model and the browser will reject executing the script.

Currently Screen Shot 2022-04-14 at 3 43 34 PM

With Change Screen Shot 2022-04-14 at 3 43 05 PM

Notice the value of the nonce is now hidden meaning Chrome has accepted it and masked the value for security reasons.

vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/charlietango/hooks/GLigMFctLK6kGp3u5gw9zwZeWttv
✅ Preview: https://hooks-git-fork-schnogz-fix-use-script-nonce-4d9ace-charlietango.vercel.app

thebuilder commented 2 years ago

Makes sense! - Haven't had the need to set nonce on dynamic scripts.

schnogz commented 2 years ago

Can you publish an updated version of the repo to NPM? would love to use this in production at my company soon but cant due to security issue above.

Thanks for the awesome hooks BTW!