CVE-2023-24540: Improper handling of JavaScript whitespace in html/template
Summary
CVE-2023-24540: Improper handling of JavaScript whitespace 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-24540 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 Go is a collection of standard libraries that provide essential functionality for Go programs. The html/template package within the stdlib package is used for generating HTML and other text-based templates. It allows developers to define templates with placeholders that can be filled with dynamic data. However, a vulnerability exists in the way the html/template package handles JavaScript whitespace characters outside of the predefined set of whitespace characters. This vulnerability can lead to improper sanitization of templates containing whitespace characters in JavaScript contexts that also contain actions.
Vulnerability Detail
The vulnerability arises from the incomplete handling of JavaScript whitespace characters in the html/template package. While the package considers certain whitespace characters as valid, it fails to recognize all valid JavaScript whitespace characters. As a result, templates containing whitespace characters outside of the predefined set of whitespace characters may not be properly sanitized during execution. This can potentially allow an attacker to inject malicious code or manipulate the behavior of the template execution. The vulnerability affects versions 0.0.0 to 1.19.9 and 1.20.0-0 to 1.20.4 of the stdlib package.
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 updating the stdlib package is not immediately feasible, a temporary workaround can be implemented by manually sanitizing templates containing whitespace characters outside of the predefined set of whitespace characters. This can be done by removing or replacing the whitespace characters with the appropriate whitespace characters from the predefined set. However, it is strongly advised to update to the fixed versions of the stdlib package as soon as possible.
Conclusion
The vulnerability in the html/template package of the stdlib package in Go arises from the incomplete handling of JavaScript whitespace characters. It can potentially allow an attacker to inject malicious code or manipulate template execution. To mitigate this vulnerability, it is crucial to update the stdlib package to the fixed versions. If immediate update is not possible, manual sanitization of templates can serve as a temporary workaround. Regularly monitoring for updates and promptly applying them is essential to maintain the security of Go applications.
See every vulnerability recorded for stdlib →
FAQ
The vulnerability can allow an attacker to inject malicious code or manipulate the behavior of template execution, potentially leading to security breaches, data leaks, or unauthorized access to sensitive information.
The vulnerability affects versions 0.0.0 to 1.19.9 and 1.20.0-0 to 1.20.4 of the stdlib package.
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 without requiring access to the code or installation.
At the time of this report, there are no known exploits for this vulnerability. However, it is important to promptly update the stdlib package to the fixed versions to mitigate the risk.
For further support on vulnerability remediation, you can reach out to info@devnack.com. The Devnack team can provide guidance and assistance in addressing this vulnerability.
References
Related vulnerabilities
Recent vulnerabilities recorded for stdlib.