-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement dangling markup injection mitigation #10022
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@annevk PTAL when you have time!
Some first surface level comments:
|
Added a note for this.
I can work on adding more tests. |
As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4
As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4
As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jonathan Hao <[email protected]> Reviewed-by: Jonathan Hao <[email protected]> Cr-Commit-Position: refs/heads/main@{#1243370}
As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jonathan Hao <[email protected]> Reviewed-by: Jonathan Hao <[email protected]> Cr-Commit-Position: refs/heads/main@{#1243370}
As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jonathan Hao <[email protected]> Reviewed-by: Jonathan Hao <[email protected]> Cr-Commit-Position: refs/heads/main@{#1243370}
…=testonly Automatic update from web-platform-tests Add more dangling markup tests to WPT As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jonathan Hao <[email protected]> Reviewed-by: Jonathan Hao <[email protected]> Cr-Commit-Position: refs/heads/main@{#1243370} -- wpt-commits: 200fcfbdd33cdb61775b29bba6f08230fc15bfd1 wpt-pr: 43808
…=testonly Automatic update from web-platform-tests Add more dangling markup tests to WPT As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jonathan Hao <[email protected]> Reviewed-by: Jonathan Hao <[email protected]> Cr-Commit-Position: refs/heads/main@{#1243370} -- wpt-commits: 200fcfbdd33cdb61775b29bba6f08230fc15bfd1 wpt-pr: 43808
…=testonly Automatic update from web-platform-tests Add more dangling markup tests to WPT As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <jkokatsugoogle.com> Reviewed-by: Yifan Luo <lyfchromium.org> Commit-Queue: Jonathan Hao <phaochromium.org> Reviewed-by: Jonathan Hao <phaochromium.org> Cr-Commit-Position: refs/heads/main{#1243370} -- wpt-commits: 200fcfbdd33cdb61775b29bba6f08230fc15bfd1 wpt-pr: 43808 UltraBlame original commit: 91a7441aaacb9223d196da7765c28ca737c8a77e
…=testonly Automatic update from web-platform-tests Add more dangling markup tests to WPT As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <jkokatsugoogle.com> Reviewed-by: Yifan Luo <lyfchromium.org> Commit-Queue: Jonathan Hao <phaochromium.org> Reviewed-by: Jonathan Hao <phaochromium.org> Cr-Commit-Position: refs/heads/main{#1243370} -- wpt-commits: 200fcfbdd33cdb61775b29bba6f08230fc15bfd1 wpt-pr: 43808 UltraBlame original commit: 91a7441aaacb9223d196da7765c28ca737c8a77e
…=testonly Automatic update from web-platform-tests Add more dangling markup tests to WPT As part of formally adding dangling markup injection mitigation to html spec[1], we need to add more tests to WPT. This change moves some of the existing tests to WPT, and add more tests. [1]: whatwg/html#10022 Change-Id: I7b03839adeb749c3206a4fb95a9dfa5785c634c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5151927 Auto-Submit: Jun Kokatsu <jkokatsugoogle.com> Reviewed-by: Yifan Luo <lyfchromium.org> Commit-Queue: Jonathan Hao <phaochromium.org> Reviewed-by: Jonathan Hao <phaochromium.org> Cr-Commit-Position: refs/heads/main{#1243370} -- wpt-commits: 200fcfbdd33cdb61775b29bba6f08230fc15bfd1 wpt-pr: 43808 UltraBlame original commit: 91a7441aaacb9223d196da7765c28ca737c8a77e
@annevk friendly ping :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, but I don't think this works. "parse a URL" is an entry point for non-HTML callers that want an easy way to obtain a base URL, such as XMLHttpRequest and fetch().
We should probably have "HTML-parse a URL" that's "encoding-parse a URL", but limited to HTML elements and with the additional injection mitigations. And then we need good test coverage to ensure the injection mitigations are not cropping up in places they shouldn't.
So, what I found out is that I only care about parsing URL when the environment is a Document object, because that's when URL parsing is called from HTML Elements. I essentially added that branch to Does that work? |
That seems somewhat attractive and might be a good way to find all the endpoints, but I think a more responsible approach would be to start by identifying the endpoints that need this mitigation. Then you make those endpoints invoke a new parse a URL algorithm (e.g., "HTML-parse a URL" as I suggested above or "parse an element URL" as I suggested in whatwg/fetch#546 (comment) a couple years back). Then we can worry about deduplicating some of the logic between that new URL parser wrapper and existing URL parser wrappers. That's mainly an editorial matter. (It might well turn out that after this we can remove the document overload from "parse a URL" and friends which would be a nice clarification.) And in parallel there needs to be test coverage for all these endpoint changes and also some test coverage for other URL endpoints to ensure they are not changing. |
Added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this probably has to change https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes as well.
Also, I had a brief look at the tests, but they don't look exhaustive. I had expected some kind of loop over all the features we want to test and whether they should have this behavior or not and then create a test for each of them.
…om protocol handler
Adding more tests per this comment[1]. [1] whatwg/html#10022 (review) Change-Id: Ia3360404630c1c22b1dad14ed930c0517f66b6e7
Adding more tests per this comment[1]. [1] whatwg/html#10022 (review) Change-Id: Ia3360404630c1c22b1dad14ed930c0517f66b6e7
The tests has been added. |
Adding more tests per this comment[1]. [1] whatwg/html#10022 (review) Change-Id: Ia3360404630c1c22b1dad14ed930c0517f66b6e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5362504 Reviewed-by: Jonathan Hao <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jun Kokatsu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1275548}
Adding more tests per this comment[1]. [1] whatwg/html#10022 (review) Change-Id: Ia3360404630c1c22b1dad14ed930c0517f66b6e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5362504 Reviewed-by: Jonathan Hao <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jun Kokatsu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1275548}
Adding more tests per this comment[1]. [1] whatwg/html#10022 (review) Change-Id: Ia3360404630c1c22b1dad14ed930c0517f66b6e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5362504 Reviewed-by: Jonathan Hao <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jun Kokatsu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1275548}
Should CSS features that fetch things use HTML-parse also? Consider <div style='background-image: url("?\
...secret stuff... '> It's slightly harder to pull off since the |
Missing:
|
I'm not entirely sold that the mitigation shouldn't apply to such APIs. If pages use libraries or polyfills that take URLs from markup (e.g. |
Yeah, perhaps that's why the prior approach attempted patching the URL parser directly, but that didn't result in agreement. I personally think this is a reasonable middle ground. |
Done!
This was removed per discussion that no browser would be rendering cite attribute as a link.
Yes, this is okay to leave.
Similar to above, the result will just generate an
Done! |
I was thinking that maybe we should treat This isn't necessarily sufficient to make me think that we should inflict this weird variant of URL parsing on all APIs, but maybe we should do more to make the failure case discoverable. ( |
CC: @mikewest if he has an opinion about above and this comment. |
Adding more tests per this comment[1]. [1] whatwg/html#10022 (review) Change-Id: Ia3360404630c1c22b1dad14ed930c0517f66b6e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5362504 Reviewed-by: Jonathan Hao <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jun Kokatsu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1275548}
…ation, a=testonly Automatic update from web-platform-tests Add more tests for dangling markup mitigation Adding more tests per this comment[1]. [1] whatwg/html#10022 (review) Change-Id: Ia3360404630c1c22b1dad14ed930c0517f66b6e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5362504 Reviewed-by: Jonathan Hao <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jun Kokatsu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1275548} -- wpt-commits: 48aa7068cc0810f6c02f7a4de26bbcc4e528bed6 wpt-pr: 45034
…ation, a=testonly Automatic update from web-platform-tests Add more tests for dangling markup mitigation Adding more tests per this comment[1]. [1] whatwg/html#10022 (review) Change-Id: Ia3360404630c1c22b1dad14ed930c0517f66b6e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5362504 Reviewed-by: Jonathan Hao <[email protected]> Reviewed-by: Yifan Luo <[email protected]> Commit-Queue: Jun Kokatsu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1275548} -- wpt-commits: 48aa7068cc0810f6c02f7a4de26bbcc4e528bed6 wpt-pr: 45034
Hi, is there any way of moving forward with this change? |
@achristensen07's objection in whatwg/url#284 (comment) as I understand it was mainly:
An HTML-specific mitigation isn't needed everywhere, true. But as I mentioned in #10022 (comment) , URLs found in HTML attributes can end up used in JS APIs, and so the mitigation as specified in this PR is not as strong as it could be. Having at least all browser-supported URL parsing entry points perform the check seems more robust. Although I care more about what happens in browsers, I think having non-browser APIs have consistent URL parsing with browsers is reasonable, even if it includes quirks that are not needed in other contexts. We have a similar situation with https://url.spec.whatwg.org/#windows-drive-letter , and that was seemingly deemed acceptable. |
Okay, so should we reopen whatwg/url#284 and move the discussion there? |
I'm not persuaded that because you could take an arbitrary HTML attribute value and parse it as a URL we have to protect against this at the level of the URL parser and thereby impact every other URL parser consumer. (And create issues for them whereby they have to deal with these code points before handing them to the URL parser.) There is a tradeoff here and I think that values the defense-in-depth argument too highly. |
Sorry for the delayed response @shhnjk; it's been a long few weeks... I continue to prefer patching URL and dealing with the problem there. Given that opinions there apparently haven't changed in 7 years, I'm quite happy to land on something smaller that we can agree on. :) To that end, I agree with @annevk that dealing with the core set of dangling markup attacks is probably the right place to start, and doing so via a new wrapper in HTML is probably fine. This patch ends up scanning the URL a few times, however, which certainly doesn't match Chromium's implementation, and would probably be pretty expensive for other vendors as well. I'd suggest that we could be more efficient by embedding the dangling-markup check in URL as whatwg/url#284 suggests, but still leaving HTML responsible for any action taken. If the flag in whatwg/url#284 is too much, a smaller change would be to introduce a more-specific validation error for step 2 of https://url.spec.whatwg.org/#concept-basic-url-parser (e.g. "ascii-tab-or-newline validation error" rather than "invalid-URL-unit validation error"), then consuming that error combined with rescanning the URL for It seems unlikely to me that Chromium would change its implementation to scan a URL more than once in any event, given that my initial (very dumb) implementation had some pretty noticeable impacts on benchmarks. That implementation detail seems unlikely to me to be web visible, though, so if it's a spec-level representation we can agree upon, I'm happy with it. |
I've discussed this with @mozfreddyb and @valenting. We're OK with this PR. I still think the added fragmentation of different behavior for different URL entry points in the web platform is not great. Adding complexity that is sometimes possible to bypass (minimized markup or |
@annevk can we merge this now? |
Implementation bug for Gecko: https://bugzilla.mozilla.org/show_bug.cgi?id=1899514 |
I found an existing WebKit bug (https://bugs.webkit.org/show_bug.cgi?id=172748). I think this is ready to merge, but leaving to @annevk. |
Sorry for missing this somehow. It seems like there needs to be a new Chromium bug as they would have to make changes, no? This also needs rebasing. |
As discussed in whatwg/fetch#546 and whatwg/url#284, we'd like to add the dangling markup injection mitigation to the HTML spec (which was implemented in Chromium for ~ 6 years).
This PR makes the following changes:
check dangling markup
algorithm.HTML-parse a URL
algorithm which calls thecheck dangling markup
algorithm before parsing.HTML-encoding-parsing-and-serialize a URL
algorithm which has same logic as HTML-encoding-parsing-and-serializing a URL except it usesHTML-parse a URL
algorithm above.check dangling markup
-backed algorithms.I have not modified the module specifier resolution, since it has a strict grammer and it's most likely to not result in a successful dangling markup injection.
I hope this change covers all of the scope we are interested in 😊 And going forward, any potential dangling markup injection sinks should call the
check dangling markup
-backed algorithms.Fixes: #10021
<
and whitespace are not valid in URLs)./common-dom-interfaces.html ( diff )
/form-control-infrastructure.html ( diff )
/iframe-embed-object.html ( diff )
/images.html ( diff )
/input.html ( diff )
/links.html ( diff )
/media.html ( diff )
/rendering.html ( diff )
/scripting.html ( diff )
/semantics.html ( diff )
/urls-and-fetching.html ( diff )