diff options
| author | Roland Shoemaker <bracewell@google.com> | 2026-01-09 11:12:01 -0800 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2026-03-05 17:05:07 -0800 |
| commit | fb16297ae571a232e46a67e6e40027f1f82ef6ec (patch) | |
| tree | b7e6af55fa6024240fa080981913cb47834e560e /src/html/template/state_string.go | |
| parent | 36d8b15842748194c4a2ce7e9cf46c65a958283c (diff) | |
| download | go-fb16297ae571a232e46a67e6e40027f1f82ef6ec.tar.xz | |
html/template: properly escape URLs in meta content attributes
The meta tag can include a content attribute that contains URLs, which
we currently don't escape if they are inserted via a template action.
This can plausibly lead to XSS vulnerabilities if untrusted data is
inserted there, the http-equiv attribute is set to "refresh", and the
content attribute contains an action like `url={{.}}`.
Track whether we are inside of a meta element, if we are inside of a
content attribute, _and_ if the content attribute contains "url=". If
all of those are true, then we will apply the same URL escaping that we
use elsewhere.
Also add a new GODEBUG, htmlmetacontenturlescape, to allow disabling this
escaping for cases where this behavior is considered safe. The behavior
can be disabled by setting htmlmetacontenturlescape=0.
Fixes CVE-2026-27142
Fixes #77954
Change-Id: I9bbca263be9894688e6ef1e9a8f8d2f4304f5873
Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/3360
Reviewed-by: Neal Patel <nealpatel@google.com>
Reviewed-by: Nicholas Husin <husin@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/752181
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/html/template/state_string.go')
| -rw-r--r-- | src/html/template/state_string.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/html/template/state_string.go b/src/html/template/state_string.go index eed1e8bcc0..f5a70b2231 100644 --- a/src/html/template/state_string.go +++ b/src/html/template/state_string.go @@ -36,12 +36,14 @@ func _() { _ = x[stateCSSBlockCmt-25] _ = x[stateCSSLineCmt-26] _ = x[stateError-27] - _ = x[stateDead-28] + _ = x[stateMetaContent-28] + _ = x[stateMetaContentURL-29] + _ = x[stateDead-30] } -const _state_name = "stateTextstateTagstateAttrNamestateAfterNamestateBeforeValuestateHTMLCmtstateRCDATAstateAttrstateURLstateSrcsetstateJSstateJSDqStrstateJSSqStrstateJSTmplLitstateJSRegexpstateJSBlockCmtstateJSLineCmtstateJSHTMLOpenCmtstateJSHTMLCloseCmtstateCSSstateCSSDqStrstateCSSSqStrstateCSSDqURLstateCSSSqURLstateCSSURLstateCSSBlockCmtstateCSSLineCmtstateErrorstateDead" +const _state_name = "stateTextstateTagstateAttrNamestateAfterNamestateBeforeValuestateHTMLCmtstateRCDATAstateAttrstateURLstateSrcsetstateJSstateJSDqStrstateJSSqStrstateJSTmplLitstateJSRegexpstateJSBlockCmtstateJSLineCmtstateJSHTMLOpenCmtstateJSHTMLCloseCmtstateCSSstateCSSDqStrstateCSSSqStrstateCSSDqURLstateCSSSqURLstateCSSURLstateCSSBlockCmtstateCSSLineCmtstateErrorstateMetaContentstateMetaContentURLstateDead" -var _state_index = [...]uint16{0, 9, 17, 30, 44, 60, 72, 83, 92, 100, 111, 118, 130, 142, 156, 169, 184, 198, 216, 235, 243, 256, 269, 282, 295, 306, 322, 337, 347, 356} +var _state_index = [...]uint16{0, 9, 17, 30, 44, 60, 72, 83, 92, 100, 111, 118, 130, 142, 156, 169, 184, 198, 216, 235, 243, 256, 269, 282, 295, 306, 322, 337, 347, 363, 382, 391} func (i state) String() string { if i >= state(len(_state_index)-1) { |
