CVE-2023-24540: Improper handling of JavaScript whitespace in html/template

stdlib Updated 02 Oct 2025

Summary

05/05/2023
Yes i
Unrated
Not published

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

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.

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 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.9 1.19.9
    go get stdlib@v1.19.9
  • >= 1.20.0-0, < 1.20.4 1.20.4
    go 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 →

Share this vulnerability

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.

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.19.9 1.19.9
    go get stdlib@v1.19.9
  • >= 1.20.0-0, < 1.20.4 1.20.4
    go 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 →

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