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 stdlib package in the Go ecosystem provides a set of standard libraries for the Go programming language. One of the packages included is html/template, which offers functionality for generating HTML templates. These templates can be populated with data and rendered to produce HTML output. However, a vulnerability has been identified in the package's handling of errors returned from JSON marshaling.
Vulnerability Detail
When errors returned from MarshalJSON methods contain user-controlled data, they can be exploited to disrupt the contextual auto-escaping behavior of the html/template package. This can allow malicious actors to inject unexpected content into templates, potentially leading to cross-site scripting (XSS) attacks or other security breaches.
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
If updating to the latest version is not immediately feasible, a temporary workaround can be implemented by manually sanitizing and validating any user-controlled data before passing it to the MarshalJSON methods. This can help mitigate the risk of template escaping issues.
Conclusion
In conclusion, the html/template package in the Go stdlib is vulnerable to template escaping issues when errors returned from JSON marshaling contain user-controlled data. It is crucial to update to version 1.22.1 or later to fix this vulnerability. If immediate update is not possible, manual data sanitization can serve as a temporary workaround. For further assistance with vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for stdlib →
FAQ
The vulnerability allows for unexpected content injection into templates, which can lead to various security issues such as cross-site scripting (XSS) attacks.
Versions 0 through 1.21.8 are vulnerable. The issue was introduced in version 1.22.0-0 and fixed in version 1.22.1.
You can use the Vulert Playground at Vulert Scanner to check if your application is affected by this vulnerability. Simply provide your Gopkg.lock file and the playground will analyze it for potential vulnerabilities.
At the time of this report, there is no known public exploit for this vulnerability. However, it is important to promptly update the affected package to mitigate any potential risks.
You can find more information about this vulnerability, including the technical details and affected package versions, in the vulnerability report at https://pkg.go.dev/vuln/GO-2024-2610.
References
Related vulnerabilities
Recent vulnerabilities recorded for stdlib.