Closed Bug 1523283 Opened 6 years ago Closed 6 years ago

Allow setting .nonce property via JavaScript on script elements.

Categories

(Core :: DOM: Security, defect)

63 Branch
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1389421

People

(Reporter: robclap8, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.71 Safari/537.36

Steps to reproduce:

// Set a CSP nonce-only policy.
// Create a script and add it from a nonced script.
// In CSP nonce-only policies, it is necessary to propagate the nonce value:
let newscript = document.createElement('script');
let myscript = document.getElementById('myscriptid');
newscript.src = '/mysrc.js';
newscript.nonce = myscript.nonce;
myscript.parentNode.insertBefore(newscript,myscript);

Actual results:

The created script does not execute

Expected results:

The created script runs.

There are two main reasons this does not work:

  • getting the nonce by reading the "nonce" property does not work, it's currently necessary to use myscript.getAttribute('nonce')
  • setting the nonce with ".nonce" does not work, it is currently necessary to use newscript.setAttribute('nonce',myscript.nonce||myscript.getAttribute('nonce'))

Note that "myscript.nonce||" is for compatibility reasons as chrome hides nonces from the DOM to address exfiltration: https://bugs.chromium.org/p/chromium/issues/detail?id=680419&q=nonce%20idl&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified

The minimal fix would be to allow setting nonces by assigning the correct value to the ".nonce" property.

The ideal fix would be to also hide 'nonce' from the DOM.

I think this was already brought up by Artur in #1505412 but it was not addressed nor assigned a bug to track it.

Flags: needinfo?(arturjanc)

I don't know how to reproduce this issue as it's to technical for me.

I'm assigning a component to get a start on this, if considered wrong, please feel free to change it to a more appropriate one.

Component: Untriaged → DOM: Security
Product: Firefox → Core
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Flags: needinfo?(arturjanc)
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.