|
| 1 | +From 8877ca93a7bdbf7868c0a2cb941042b74fe2983f Mon Sep 17 00:00:00 2001 |
| 2 | +From: Roland Shoemaker <roland@golang.org> |
| 3 | +Date: Mon, 4 May 2026 11:47:15 -0700 |
| 4 | +Subject: [PATCH] html: escape greater-than symbol in doctype identifiers |
| 5 | + |
| 6 | +During parsing, we unescape character references. When rendering, we |
| 7 | +re-escape certain characters in certain scenarios in order to avoid |
| 8 | +token content causing unexpected parser behavior. |
| 9 | + |
| 10 | +We appear to have not taken this into account when rendering DOCTYPE |
| 11 | +tokens, allowing ">" in PUBLIC/SYSTEM identifier strings, which trigger |
| 12 | +a abrupt-doctype-system-identifier parse error which immediately emits |
| 13 | +the current DOCTYPE token and then continues parsing in the data state. |
| 14 | + |
| 15 | +This may cause bypass in HTML santizers which use the html package for |
| 16 | +parsing. |
| 17 | + |
| 18 | +Thanks to ensy for reporting this issue. |
| 19 | + |
| 20 | +Fixes CVE-2026-25681 |
| 21 | + |
| 22 | +Change-Id: I1d5be92129d17bfbf0917148db2672d57c224a18 |
| 23 | +Reviewed-on: https://go-review.googlesource.com/c/net/+/781703 |
| 24 | +Reviewed-by: Neal Patel <nealpatel@google.com> |
| 25 | +Reviewed-by: Nicholas Husin <nsh@golang.org> |
| 26 | +TryBot-Bypass: Roland Shoemaker <roland@golang.org> |
| 27 | +Auto-Submit: Gopher Robot <gobot@golang.org> |
| 28 | +Reviewed-by: Nicholas Husin <husin@google.com> |
| 29 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 30 | +Upstream-reference: https://github.com/golang/net/commit/4ece7b612ad44ad6c4d5e0d5d4df9c18cc211905.patch |
| 31 | +--- |
| 32 | + vendor/golang.org/x/net/html/render.go | 19 +++++++++++++------ |
| 33 | + .../html/testdata/go/doctype_named_entity.dat | 8 ++++++++ |
| 34 | + 2 files changed, 21 insertions(+), 6 deletions(-) |
| 35 | + create mode 100644 vendor/golang.org/x/net/html/testdata/go/doctype_named_entity.dat |
| 36 | + |
| 37 | +diff --git a/vendor/golang.org/x/net/html/render.go b/vendor/golang.org/x/net/html/render.go |
| 38 | +index 0157d89..671fcdb 100644 |
| 39 | +--- a/vendor/golang.org/x/net/html/render.go |
| 40 | ++++ b/vendor/golang.org/x/net/html/render.go |
| 41 | +@@ -113,14 +113,14 @@ func render1(w writer, n *Node) error { |
| 42 | + if _, err := w.WriteString(" PUBLIC "); err != nil { |
| 43 | + return err |
| 44 | + } |
| 45 | +- if err := writeQuoted(w, p); err != nil { |
| 46 | ++ if err := writeDoctypeQuoted(w, p); err != nil { |
| 47 | + return err |
| 48 | + } |
| 49 | + if s != "" { |
| 50 | + if err := w.WriteByte(' '); err != nil { |
| 51 | + return err |
| 52 | + } |
| 53 | +- if err := writeQuoted(w, s); err != nil { |
| 54 | ++ if err := writeDoctypeQuoted(w, s); err != nil { |
| 55 | + return err |
| 56 | + } |
| 57 | + } |
| 58 | +@@ -128,7 +128,7 @@ func render1(w writer, n *Node) error { |
| 59 | + if _, err := w.WriteString(" SYSTEM "); err != nil { |
| 60 | + return err |
| 61 | + } |
| 62 | +- if err := writeQuoted(w, s); err != nil { |
| 63 | ++ if err := writeDoctypeQuoted(w, s); err != nil { |
| 64 | + return err |
| 65 | + } |
| 66 | + } |
| 67 | +@@ -251,19 +251,26 @@ func childTextNodesAreLiteral(n *Node) bool { |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | +-// writeQuoted writes s to w surrounded by quotes. Normally it will use double |
| 72 | ++// writeDoctypeQuoted writes s to w surrounded by quotes. Normally it will use double |
| 73 | + // quotes, but if s contains a double quote, it will use single quotes. |
| 74 | ++// If s contains any '>' characters, they are replaced with > in order |
| 75 | ++// to prevent triggering an abrupt-doctype-system-identifier parse error. |
| 76 | + // It is used for writing the identifiers in a doctype declaration. |
| 77 | + // In valid HTML, they can't contain both types of quotes. |
| 78 | +-func writeQuoted(w writer, s string) error { |
| 79 | ++func writeDoctypeQuoted(w writer, s string) error { |
| 80 | + var q byte = '"' |
| 81 | + if strings.Contains(s, `"`) { |
| 82 | ++ // parseDoctype will never produce a Node with both quote types, but a user |
| 83 | ++ // can construct their own Node that violates this assumption. |
| 84 | ++ if strings.Contains(s, `'`) { |
| 85 | ++ return errors.New("doctype contains both quote types, cannot be safely rendered") |
| 86 | ++ } |
| 87 | + q = '\'' |
| 88 | + } |
| 89 | + if err := w.WriteByte(q); err != nil { |
| 90 | + return err |
| 91 | + } |
| 92 | +- if _, err := w.WriteString(s); err != nil { |
| 93 | ++ if _, err := w.WriteString(strings.ReplaceAll(s, ">", ">")); err != nil { |
| 94 | + return err |
| 95 | + } |
| 96 | + if err := w.WriteByte(q); err != nil { |
| 97 | +diff --git a/vendor/golang.org/x/net/html/testdata/go/doctype_named_entity.dat b/vendor/golang.org/x/net/html/testdata/go/doctype_named_entity.dat |
| 98 | +new file mode 100644 |
| 99 | +index 0000000..a8bd963 |
| 100 | +--- /dev/null |
| 101 | ++++ b/vendor/golang.org/x/net/html/testdata/go/doctype_named_entity.dat |
| 102 | +@@ -0,0 +1,8 @@ |
| 103 | ++#data |
| 104 | ++<!DOCTYPE > PUBLIC ">" ">"> |
| 105 | ++#errors |
| 106 | ++#document |
| 107 | ++| <!DOCTYPE > ">" ">"> |
| 108 | ++| <html> |
| 109 | ++| <head> |
| 110 | ++| <body> |
| 111 | +-- |
| 112 | +2.45.4 |
| 113 | + |
0 commit comments