]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.25] html/template: properly escape URLs in meta content attributes
authorRoland Shoemaker <bracewell@google.com>
Fri, 9 Jan 2026 19:12:01 +0000 (11:12 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 6 Mar 2026 00:15:29 +0000 (16:15 -0800)
commita9db31e6d9f280418ce441067f3f9dc0a036e770
tree689a8a98e0e48a4cc72f16820ccc3d06e995c462
parentd8174a9500d53784594b198f6195d1fae8dfe803
[release-branch.go1.25] 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.

Updates #77954
Fixes #77971
Fixes CVE-2026-27142

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-internal-review.googlesource.com/c/go/+/3644
Reviewed-by: Damien Neil <dneil@google.com>
Commit-Queue: Roland Shoemaker <bracewell@google.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/752101
Auto-Submit: Gopher Robot <gobot@golang.org>
TryBot-Bypass: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
doc/godebug.md
src/html/template/attr_string.go
src/html/template/context.go
src/html/template/element_string.go
src/html/template/escape.go
src/html/template/escape_test.go
src/html/template/state_string.go
src/html/template/transition.go
src/internal/godebugs/table.go
src/runtime/metrics/doc.go