CVE-2024-24785: Errors in JSON Marshaling Break Template Escaping in html/template

stdlib Updated 02 Oct 2025

Summary

05/03/2024
Yes i
Unrated
Not published

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

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.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Devnack Your last release was probably never penetration tested Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

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.8 1.21.8
    go get stdlib@v1.21.8
  • >= 1.22.0-0, < 1.22.1 1.22.1
    go 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 →

Share this vulnerability

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.

Related vulnerabilities

Recent vulnerabilities recorded for stdlib.

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.8 1.21.8
    go get stdlib@v1.21.8
  • >= 1.22.0-0, < 1.22.1 1.22.1
    go 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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback