Closed Bug 2073075 Opened 2 months ago Closed 2 months ago

[wpt-sync] Sync PR 62762 - Apply CSP to inline event handler content attributes when set

Categories

(Core :: DOM: Core & HTML, task, P4)

task

Tracking

()

RESOLVED FIXED
158 Branch
Tracking Status
firefox158 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 62762 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/62762
Details from upstream follow.

Byungwoo Lee <blee@igalia.com> wrote:

Apply CSP to inline event handler content attributes when set

Per the HTML spec, the event handler content attribute change steps
run the CSP "Should element's inline behavior be blocked?" check when
the attribute is set [1][2]. But the violation was reported lazily,
when the handler was first accessed, rather than when the attribute
was set.

To report a violation and skip setting the inline event listener as
per the spec, Element provides the following functions:

  • SetElementAttributeEventListenerFromScriptBody()
  • SetDocumentAttributeEventListenerFromScriptBody()
  • SetWindowAttributeEventListenerFromScriptBody()

The functions check whether the modification is an inline handler
(kDirectly or kByParser) and, if so, whether it is blocked by CSP
(ContentSecurityPolicy::AllowInline()). When blocked, a violation is
reported and the listener is not set. The CSP check is guarded by
the stable runtime feature CheckCSPOnInlineScriptAttributeSet.

Element's subclasses use these functions in ParseAttribute() when
they set an inline event handler (HTMLInputElement, HTMLBodyElement,
HTMLElement, HTMLFrameElementBase, HTMLFrameSetElement, MathMLElement,
SVGSMILElement, SVGElement, SVGScriptElement, SVGSVGElement).

This CL updates two tests that do not match the spec:

  • style-element-csp-nonce-allowed.html: Fix the unintended CSP
    violation on the inline onerror attribute.
  • domdebugger-script-blocked-by-csp.js: Introduce CSP violation by
    setAttribute() instead of click().

[1] https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-content-attributes
[2] https://w3c.github.io/webappsec-csp/#should-block-inline

Low-Coverage-Reason: COVERAGE_UNDERREPORTED Tests exist (targeting-for-multiple-inline-handler-violations.html)
Bug: 559396684
Change-Id: I864b7456169307e78df8eab9d975d9d3ea863b21
Reviewed-on: https://chromium-review.googlesource.com/8365264
WPT-Export-Revision: ce9725bd0664542a3497602045bc87f5fccac9e5

Component: web-platform-tests → DOM: Core & HTML
Product: Testing → Core

CI Results

Ran 9 Firefox configurations based on mozilla-central, and Firefox, and Chrome on GitHub CI

Total 11 tests

Status Summary

Firefox

ERROR : 1[GitHub] 5[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
NOTRUN: 2[GitHub] 6[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]

Chrome

OK : 1
PASS : 3

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Details

New Tests That Don't Pass

Tests Disabled in Gecko Infrastructure

Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch
You need to log in before you can comment on or make changes to this bug.