Add duplicate attribute tracking for CSP nonce validation#695
Add duplicate attribute tracking for CSP nonce validation#695TimvdLippe merged 2 commits intoservo:mainfrom
Conversation
0773845 to
cec02c3
Compare
…#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>
…#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>
simonwuelker
left a comment
There was a problem hiding this comment.
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?
…#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>
6c8fbae to
bb5bdf7
Compare
There was a problem hiding this comment.
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.
Point html5ever, markup5ever, xml5ever, web_atoms, and tendril to the duplicate-attr-flag branch which adds had_duplicate_attributes to ElementFlags. This will be rebased once servo/html5ever#695 lands.
Point html5ever, markup5ever, xml5ever, web_atoms, and tendril to the duplicate-attr-flag branch which adds had_duplicate_attributes to ElementFlags. This will be rebased once servo/html5ever#695 lands. Signed-off-by: Dyego Aurélio <dyegoaurelio@gmail.com>
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>
Signed-off-by: Dyego Aurélio <dyegoaurelio@gmail.com>
bb5bdf7 to
cedc11a
Compare
|
servo PR at servo/servo#43216 |
Point html5ever, markup5ever, xml5ever, web_atoms, and tendril to the duplicate-attr-flag branch which adds had_duplicate_attributes to ElementFlags. This will be rebased once servo/html5ever#695 lands. Signed-off-by: Dyego Aurélio <dyegoaurelio@gmail.com>
|
@simonwuelker can you publish these crates? |
I don't have the necessary permissions to publish to crates.io. cc @servo/cargo-publish . and why is the semver check applying the wrong labels again... |
|
Published markup5ever, html5ever, and xml5ever. |
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_attrsfield during nonce validation.Reference: