Skip to content

Add duplicate attribute tracking for CSP nonce validation#695

Open
dyegoaurelio wants to merge 1 commit intoservo:mainfrom
dyegoaurelio:duplicate-attr-flag
Open

Add duplicate attribute tracking for CSP nonce validation#695
dyegoaurelio wants to merge 1 commit intoservo:mainfrom
dyegoaurelio:duplicate-attr-flag

Conversation

@dyegoaurelio
Copy link

Implements detection and propagation of duplicate attributes through the tokenizer, tree builder, and TreeSink interface to support CSP (Content Security Policy) nonce validation.

This enables html5ever consumers (e.g., Servo) to properly implement step 3 of the CSP "is element nonceable" algorithm by checking the ElementFlags.had_duplicate_attrs field during nonce validation.

Reference:

@dyegoaurelio dyegoaurelio changed the title Add duplicate attribute tracking for CSP nonce validation. Add duplicate attribute tracking for CSP nonce validation Nov 29, 2025
github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Feb 27, 2026
…#40956)

This PR fixes two related issues with Content Security Policy (CSP)
nonce validation for external scripts:

1. Missing nonce validation for external scripts with malformed
attributes
2. Incorrect violation event reporting for blocked external resources


This makes servo closer to passing the `nonce-enforce-blocked` wpt test.

The remaining failures are blocked by required changes in the html
parser.

1. Svg script support (servo/html5ever#118)
```html
<svg xmlns="http://www.w3.org/2000/svg">
<script attribute attribute nonce="abc">
    t.unreached_func("Duplicate attribute in SVG, no execution.")();
</script>
</svg>
```

2. Duplicate attrs check
the html parser needs to provide this flag, as mentioned on the original
commit message
(4821bc0)

```html
<script attribute attribute nonce="abc">
    t.unreached_func("Duplicate attribute, no execution.")();
</script>
<script attribute attribute=<style nonce="abc">
    t.unreached_func("2# Duplicate attribute, no execution.")();
</script>

[...]

<script src="../support/nonce-should-be-blocked.js?5" attribute attribute nonce="abc"></script>
```

I've also created a PR to implement the duplicate attrs flag on
html5ever servo/html5ever#695

Testing: doesn't fixes the aforementioned wpt test yet.
Fixes: part of #36437

---------

Signed-off-by: Dyego Aurélio <dyegoaurelio@gmail.com>
github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Feb 27, 2026
…#40956)

This PR fixes two related issues with Content Security Policy (CSP)
nonce validation for external scripts:

1. Missing nonce validation for external scripts with malformed
attributes
2. Incorrect violation event reporting for blocked external resources


This makes servo closer to passing the `nonce-enforce-blocked` wpt test.

The remaining failures are blocked by required changes in the html
parser.

1. Svg script support (servo/html5ever#118)
```html
<svg xmlns="http://www.w3.org/2000/svg">
<script attribute attribute nonce="abc">
    t.unreached_func("Duplicate attribute in SVG, no execution.")();
</script>
</svg>
```

2. Duplicate attrs check
the html parser needs to provide this flag, as mentioned on the original
commit message
(4821bc0)

```html
<script attribute attribute nonce="abc">
    t.unreached_func("Duplicate attribute, no execution.")();
</script>
<script attribute attribute=<style nonce="abc">
    t.unreached_func("2# Duplicate attribute, no execution.")();
</script>

[...]

<script src="../support/nonce-should-be-blocked.js?5" attribute attribute nonce="abc"></script>
```

I've also created a PR to implement the duplicate attrs flag on
html5ever servo/html5ever#695

Testing: doesn't fixes the aforementioned wpt test yet.
Fixes: part of #36437

---------

Signed-off-by: Dyego Aurélio <dyegoaurelio@gmail.com>
Copy link
Contributor

@simonwuelker simonwuelker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks reasonable. Just one nit: I know the existing code likes to use abbreviations a lot, but I'd like to move away from that in the long term, especially for pub interfaces. Can you rename had_duplicate_attrs to had_duplicate_attributes everywhere?

github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Feb 27, 2026
…#40956)

This PR fixes two related issues with Content Security Policy (CSP)
nonce validation for external scripts:

1. Missing nonce validation for external scripts with malformed
attributes
2. Incorrect violation event reporting for blocked external resources


This makes servo closer to passing the `nonce-enforce-blocked` wpt test.

The remaining failures are blocked by required changes in the html
parser.

1. Svg script support (servo/html5ever#118)
```html
<svg xmlns="http://www.w3.org/2000/svg">
<script attribute attribute nonce="abc">
    t.unreached_func("Duplicate attribute in SVG, no execution.")();
</script>
</svg>
```

2. Duplicate attrs check
the html parser needs to provide this flag, as mentioned on the original
commit message
(4821bc0)

```html
<script attribute attribute nonce="abc">
    t.unreached_func("Duplicate attribute, no execution.")();
</script>
<script attribute attribute=<style nonce="abc">
    t.unreached_func("2# Duplicate attribute, no execution.")();
</script>

[...]

<script src="../support/nonce-should-be-blocked.js?5" attribute attribute nonce="abc"></script>
```

I've also created a PR to implement the duplicate attrs flag on
html5ever servo/html5ever#695

Testing: doesn't fixes the aforementioned wpt test yet.
Fixes: part of #36437

---------

Signed-off-by: Dyego Aurélio <dyegoaurelio@gmail.com>
@dyegoaurelio dyegoaurelio force-pushed the duplicate-attr-flag branch from cec02c3 to 6c8fbae Compare March 2, 2026 23:12
Implements detection and propagation of duplicate attributes through
the tokenizer, tree builder, and TreeSink interface to support CSP
(Content Security Policy) nonce validation.

This enables html5ever consumers (e.g., Servo) to properly implement
step 3 of the CSP "is element nonceable" algorithm by checking the
`ElementFlags.had_duplicate_attrs` field during nonce validation.

Reference:
 - https://www.w3.org/TR/CSP/#is-element-nonceable
 - servo/servo@4821bc0
Signed-off-by: Dyego Aurélio <dyegoaurelio@gmail.com>
@dyegoaurelio dyegoaurelio force-pushed the duplicate-attr-flag branch from 6c8fbae to bb5bdf7 Compare March 2, 2026 23:13
@github-actions github-actions bot added the V-breaking Breaking change label Mar 2, 2026
@github-actions github-actions bot added V-breaking Breaking change and removed V-breaking Breaking change labels Mar 2, 2026
Copy link
Contributor

@simonwuelker simonwuelker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
If you need this change for a servo PR then you also need to prepare a new release (See RELEASING.md
that we can use for servo. It would also be nice to have the servo PR ready so we can run tests on it. html5ever itself has much less test coverage than the WPT suite from servo can provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

V-breaking Breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants