Open Bug 1768040 Opened 3 years ago Updated 3 years ago

CSP check is done against the text at the time of preparing but evaluation uses different text if updated after preparation

Categories

(Core :: DOM: Security, defect, P3)

Firefox 102
defect

Tracking

()

People

(Reporter: hiroshige, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: sec-low, Whiteboard: [domsecurity-backlog2])

Steps to reproduce:

Originally reported in https://github.com/whatwg/html/issues/7882.
WPT: https://github.com/web-platform-tests/wpt/pull/33903

  1. Load a page with a CSP policy that allows the hash of the original script text at Step 1 but forbids the hash of the updated script text at Step 3.
  2. Add an inline script <script>...original text...</script> to DOM. This triggers #prepare-a-script.
  3. Update the text content of the script element.
  4. Execute the script.

(This can be done e.g. by adding stylesheets that block immediate evaluation of inline scripts.)

This is related to https://bugzilla.mozilla.org/show_bug.cgi?id=1651092, but not only the updated text was evaluated, but also the CSP check was inconsistent (done against the original text).

Actual results:

The updated script text was evaluated.
This indicates that the CSP check was done against the original text at the time of #prepare-a-script but evaluation was done using the updated text.

Expected results:

According to the spec, both the CSP check and evaluation should uses the text at the time of #prepare-a-script (source text in https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script).

So the original text should be evaluated.

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Security' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: Security
Product: Firefox → Core
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Whiteboard: [domsecurity-backlog2]
Keywords: sec-low
You need to log in before you can comment on or make changes to this bug.