CVE-2023-24539: Improper sanitization of CSS values in html/template

stdlib Updated 02 Oct 2025

Summary

05/05/2023
Yes i
Unrated
Not published

CVE-2023-24539: Improper sanitization of CSS values 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-24539 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 MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

The stdlib package in Go is a collection of standard libraries that provide fundamental functionality for Go programs. The html/template package within the stdlib package is used for generating HTML output. It allows developers to define templates with placeholders that can be filled with dynamic data. However, the package is vulnerable to improper sanitization of CSS values, which can lead to the injection of unexpected HTML if executed with untrusted input.

Vulnerability Detail

The vulnerability arises from the inadequate handling of angle brackets (<>) in CSS contexts. Normally, angle brackets are not considered dangerous characters in CSS. However, when templates containing multiple actions separated by a '/' character are used, the CSS context can unexpectedly close, enabling the injection of unexpected HTML. This can have serious security implications, as it allows for the execution of arbitrary code or the manipulation of the rendered HTML.

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 Go stdlib package is not immediately feasible, developers can implement a workaround by manually sanitizing the CSS values before using them in the html/template package. This can be done by escaping any angle brackets (<>) in the CSS values to prevent them from being interpreted as HTML tags. Here is an example of how this can be achieved in Go:

import (
	"html/template"
	"strings"
)

func sanitizeCSSValue(value string) string {
	return strings.ReplaceAll(value, "<", "\u003c").ReplaceAll(value, ">", "\u003e")
}

// Usage:
func main() {
	cssValue := "<script>alert('XSS')</script>"
	sanitizedValue := sanitizeCSSValue(cssValue)
	// Use the sanitized value in the html/template package
}

Conclusion

The improper sanitization of CSS values in the html/template package of the Go stdlib package can lead to the injection of unexpected HTML, potentially enabling various attacks. It is crucial to update to the recommended versions of the package or implement the provided workaround to mitigate the risk. For further assistance or support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for stdlib →

Share this vulnerability

FAQ

This vulnerability can allow an attacker to inject unexpected HTML into the rendered output of an application using the html/template package. This can lead to various attacks, such as cross-site scripting (XSS) or the manipulation of the rendered HTML.

No, not all versions are affected. Versions 1.19.9 and 1.20.4 (and later) include the necessary fixes to address this vulnerability. It is recommended to update to one of these versions to mitigate the risk.

Yes, if updating the Go stdlib package is not immediately feasible, developers can manually sanitize the CSS values before using them in the html/template package. This involves escaping any angle brackets (<>) in the CSS values to prevent them from being interpreted as HTML tags.

Yes, this vulnerability can be exploited remotely if an application using the vulnerable html/template package is accessible over the network. An attacker can send crafted input to the application to trigger the injection of unexpected HTML.

At the time of this report, there are no known public exploits specifically targeting this vulnerability. However, it is important to promptly update the affected package to mitigate the risk.

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