From fb16297ae571a232e46a67e6e40027f1f82ef6ec Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Fri, 9 Jan 2026 11:12:01 -0800 Subject: 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 Reviewed-by: Nicholas Husin Reviewed-on: https://go-review.googlesource.com/c/go/+/752181 Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI --- src/runtime/metrics/doc.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/runtime') diff --git a/src/runtime/metrics/doc.go b/src/runtime/metrics/doc.go index 361e68f0b3..1e87b0a80e 100644 --- a/src/runtime/metrics/doc.go +++ b/src/runtime/metrics/doc.go @@ -302,6 +302,11 @@ Below is the full list of supported metrics, ordered lexicographically. package due to a non-default GODEBUG=gotestjsonbuildtext=... setting. + /godebug/non-default-behavior/htmlmetacontenturlescape:events + The number of non-default behaviors executed by + the html/template package due to a non-default + GODEBUG=htmlmetacontenturlescape=... setting. + /godebug/non-default-behavior/http2client:events The number of non-default behaviors executed by the net/http package due to a non-default GODEBUG=http2client=... setting. -- cgit v1.3