CVE-2023-29400: Improper handling of empty HTML attributes in html/template
Summary
CVE-2023-29400: Improper handling of empty HTML attributes in html/template. Affects stdlib across 2 version ranges.
< 1.19.9
>= 1.20.0-0, < 1.20.4
Fixed in 1.19.9 or 1.20.4, depending on the release line you run. How to fix ↓
Also tracked for
- golang · Bitnami
- golang-1.15 · Debian:11
The same CVE-2023-29400 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The stdlib package in the Go ecosystem provides a set of standard libraries for the Go programming language. One of the packages within stdlib is html/template, which is used for generating HTML output. The html/template package allows developers to define templates with placeholders that can be filled with dynamic data. These templates can contain actions in unquoted HTML attributes, such as "attr={{.}}". However, when these templates are executed with empty input, the output may have unexpected results due to HTML normalization rules. This can potentially lead to the injection of arbitrary attributes into HTML tags.
Vulnerability Detail
The vulnerability arises from the improper handling of empty HTML attributes in the html/template package. When a template with actions in unquoted HTML attributes is executed with empty input, the resulting output may be parsed incorrectly due to HTML normalization rules. This can be exploited by an attacker to inject arbitrary attributes into HTML tags, potentially leading to cross-site scripting (XSS) attacks or other security vulnerabilities.
How To Fix
Latest published version: go1.25.5 as of 22 Oct 2026
go get stdlib@vgo1.25.5
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 1.19.91.19.9go get stdlib@v1.19.9 -
>= 1.20.0-0, < 1.20.41.20.4go get stdlib@v1.20.4
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
If upgrading to the fixed version is not immediately feasible, developers can implement a workaround by manually sanitizing and validating the input data before executing the template. This involves ensuring that the input data for the template does not contain any malicious or unexpected content. Here's an example of how to sanitize the input data using the html/template package:
import (
"html/template"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
// Sanitize and validate the input data
input := sanitizeInput(r.FormValue("input"))
// Create a new template
tmpl := template.New("mytemplate")
// Parse the template
tmpl, err := tmpl.Parse("<div attr={{.}}></div>")
if err != nil {
// Handle error
return
}
// Execute the template with the sanitized input
err = tmpl.Execute(w, input)
if err != nil {
// Handle error
return
}
}
Conclusion
In conclusion, the stdlib package in the Go ecosystem is vulnerable to improper handling of empty HTML attributes in the html/template package. This can result in the injection of arbitrary attributes into HTML tags, potentially leading to security vulnerabilities. To fix this issue, developers should upgrade to version 1.19.9 or later of the stdlib package. If immediate upgrading is not possible, a workaround can be implemented by sanitizing and validating the input data before executing the template. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for stdlib →
FAQ
This vulnerability allows an attacker to inject arbitrary attributes into HTML tags, which can lead to cross-site scripting (XSS) attacks or other security vulnerabilities. It is important to fix this vulnerability to prevent potential exploitation.
You can use the Vulert Playground at Vulert Scanner to check if your application is affected by this vulnerability. The Vulert Playground allows you to analyze your application's dependencies without requiring access to the code or installation. Simply enter your Gopkg.lock file and the Vulert Playground will provide real-time alerts for open-source vulnerabilities, including this one.
Yes, if upgrading to the fixed version is not immediately feasible, you can implement a workaround by manually sanitizing and validating the input data before executing the template. This involves ensuring that the input data for the template does not contain any malicious or unexpected content. Refer to the "workaround" section for an example of how to sanitize the input data using the html/template package.
Versions 0.0.0 to 1.19.8 of the stdlib package are affected by this vulnerability. It is recommended to upgrade to version 1.19.9 or later to fix the issue.
This vulnerability was discovered by Juho Nurminen of Mattermost.
References
Related vulnerabilities
Recent vulnerabilities recorded for stdlib.