getAttribute('nonce') works in Firefox, but not Chrome

getAttribute('nonce') works in Firefox, but not Chrome



Given I am loading a script like this:


<script nonce="35609alksdgx30q" src="example.com/main.js"></script>



And inside main.js I need to grab the nonce on the script tag:


main.js


const currentScriptElement = document.currentScript
const nonce = currentScriptElement.getAttribute('nonce')



If console.log(nonce), I get two different values:


console.log(nonce)


35609alksdgx30q


""



If I get the nonce using the experimental nonce property (HTMLElement.nonce), I get the following values:


null


35609alksdgx30q



So to reliably get the nonce, I have to do something like this:


const nonce = currentScript.nonce || currentScript.getAttribute('nonce') || false



My question is, why doesn't getAttribute('nonce') consistently return the nonce value? I suspect this is a security thing, but then why doesn't Firefox also return an empty string when using getAttribute('nonce')?


getAttribute('nonce')


getAttribute('nonce')



Yes, I know technically nonce is used for inline scripts, and yes this script is cleared by the site's CSP policy. I have to grab nonce this way due to how some things were implemented xD


nonce


nonce









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ