|
| 1 | +From bbe4000b0322fd46086cf73856cbafff9823b421 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Roland Shoemaker < [email protected]> |
| 3 | +Date: Mon, 24 Feb 2025 11:18:31 -0800 |
| 4 | +Subject: [PATCH] html: properly handle trailing solidus in unquoted attribute |
| 5 | + value in foreign content |
| 6 | + |
| 7 | +The parser properly treats tags like <p a=/> as <p a="/">, but the |
| 8 | +tokenizer emits the SelfClosingTagToken token incorrectly. When the |
| 9 | +parser is used to parse foreign content, this results in an incorrect |
| 10 | +DOM. |
| 11 | + |
| 12 | +Thanks to Sean Ng (https://ensy.zip) for reporting this issue. |
| 13 | + |
| 14 | +Fixes golang/go#73070 |
| 15 | +Fixes CVE-2025-22872 |
| 16 | + |
| 17 | +Change-Id: I65c18df6d6244bf943b61e6c7a87895929e78f4f |
| 18 | +Reviewed-on: https://go-review.googlesource.com/c/net/+/661256 |
| 19 | +Reviewed-by: Neal Patel < [email protected]> |
| 20 | +Reviewed-by: Roland Shoemaker < [email protected]> |
| 21 | +LUCI-TryBot-Result: Go LUCI < [email protected]> |
| 22 | +Auto-Submit: Gopher Robot < [email protected]> |
| 23 | +Link: https://github.com/golang/net/commit/e1fcd82abba34df74614020343be8eb1fe85f0d9 |
| 24 | +--- |
| 25 | + vendor/golang.org/x/net/html/token.go | 18 ++++++++++++++++-- |
| 26 | + 1 file changed, 16 insertions(+), 2 deletions(-) |
| 27 | + |
| 28 | +diff --git a/vendor/golang.org/x/net/html/token.go b/vendor/golang.org/x/net/html/token.go |
| 29 | +index 3c57880..6598c1f 100644 |
| 30 | +--- a/vendor/golang.org/x/net/html/token.go |
| 31 | ++++ b/vendor/golang.org/x/net/html/token.go |
| 32 | +@@ -839,8 +839,22 @@ func (z *Tokenizer) readStartTag() TokenType { |
| 33 | + if raw { |
| 34 | + z.rawTag = strings.ToLower(string(z.buf[z.data.start:z.data.end])) |
| 35 | + } |
| 36 | +- // Look for a self-closing token like "<br/>". |
| 37 | +- if z.err == nil && z.buf[z.raw.end-2] == '/' { |
| 38 | ++ // Look for a self-closing token (e.g. <br/>). |
| 39 | ++ // |
| 40 | ++ // Originally, we did this by just checking that the last character of the |
| 41 | ++ // tag (ignoring the closing bracket) was a solidus (/) character, but this |
| 42 | ++ // is not always accurate. |
| 43 | ++ // |
| 44 | ++ // We need to be careful that we don't misinterpret a non-self-closing tag |
| 45 | ++ // as self-closing, as can happen if the tag contains unquoted attribute |
| 46 | ++ // values (i.e. <p a=/>). |
| 47 | ++ // |
| 48 | ++ // To avoid this, we check that the last non-bracket character of the tag |
| 49 | ++ // (z.raw.end-2) isn't the same character as the last non-quote character of |
| 50 | ++ // the last attribute of the tag (z.pendingAttr[1].end-1), if the tag has |
| 51 | ++ // attributes. |
| 52 | ++ nAttrs := len(z.attr) |
| 53 | ++ if z.err == nil && z.buf[z.raw.end-2] == '/' && (nAttrs == 0 || z.raw.end-2 != z.attr[nAttrs-1][1].end-1) { |
| 54 | + return SelfClosingTagToken |
| 55 | + } |
| 56 | + return StartTagToken |
| 57 | +-- |
| 58 | +2.34.1 |
| 59 | + |
0 commit comments