CVE-2024-24785: Errors in JSON Marshaling Break Template Escaping in html/template
Summary
CVE-2024-24785: Errors returned from JSON marshaling may break template escaping in html/template. Affects stdlib across 2 version ranges.
< 1.21.8
>= 1.22.0-0, < 1.22.1
Fixed in 1.21.8 or 1.22.1, depending on the release line you run. How to fix ↓
Also tracked for
- golang · Bitnami
- golang-1.15 · Debian:11
The same CVE-2024-24785 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 Go standard library (stdlib) is a collection of packages that provide fundamental functionality for Go programs. One of these packages is html/template, which is used for generating HTML output. The html/template package includes a feature called auto-escaping, which helps prevent cross-site scripting (XSS) attacks by automatically escaping user-controlled data before it is rendered in HTML templates. However, a vulnerability has been discovered in the way errors returned from JSON marshaling are handled, which can break the contextual auto-escaping behavior of the html/template package.
Vulnerability Detail
When errors returned from MarshalJSON methods contain user-controlled data, they can be exploited to bypass the auto-escaping mechanism of the html/template package. This allows an attacker to inject unexpected content into templates, potentially leading to XSS vulnerabilities. The vulnerability affects versions 0.0.0 to 1.21.8 and 1.22.0-0 to 1.22.1 of the Go standard library.
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.21.81.21.8go get stdlib@v1.21.8 -
>= 1.22.0-0, < 1.22.11.22.1go get stdlib@v1.22.1
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
There is no known workaround for this vulnerability. It is recommended to update to a fixed version of the Go standard library as soon as possible.
Conclusion
In conclusion, the vulnerability in the Go standard library's html/template package allows for the injection of unexpected content into HTML templates, potentially leading to cross-site scripting (XSS) vulnerabilities. It is crucial for developers to update their applications to a fixed version of the Go standard library to mitigate this risk. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for stdlib →
FAQ
This vulnerability allows an attacker to inject unexpected content into HTML templates, potentially leading to cross-site scripting (XSS) vulnerabilities.
Versions 0.0.0 to 1.21.8 and 1.22.0-0 to 1.22.1 of the Go standard library are affected.
You can use the Vulert Playground (https://vulert.com/scanner) to check if your application is affected by this vulnerability. Simply provide your Gopkg.lock file and the playground will analyze it for vulnerabilities.
No, there is no known workaround for this vulnerability. It is recommended to update to a fixed version of the Go standard library.
You can find more information about this vulnerability in the Go vulnerability database at https://pkg.go.dev/vuln/GO-2024-2610.
References
Related vulnerabilities
Recent vulnerabilities recorded for stdlib.