CVE-2023-39318: HTML Injection in golang package

golang Updated 02 Oct 2025

Summary

06/03/2024
Yes i
Medium
Not published

CVE-2023-39318: Improper handling of HTML-like comments in script contexts in html/template. Affects golang across 2 version ranges.

< 1.20.8 >= 1.21.0, < 1.21.1

Fixed in 1.20.8 or 1.21.1, depending on the release line you run. How to fix ↓

Also tracked for

The same CVE-2023-39318 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 golang package, developed by Bitnami, is a popular open-source programming language that provides a robust set of tools and libraries for building efficient and reliable applications. It is widely used for its simplicity, performance, and extensive standard library. However, a vulnerability has been discovered in the html/template package of golang, which can lead to HTML injection attacks.

Vulnerability Detail

The html/template package in golang fails to handle HTML-like "" comment tokens and hashbang "#!" comment tokens properly within <script> contexts. As a result, the template parser may misinterpret the content of <script> contexts, leading to improper escaping of actions. This vulnerability can be exploited to perform cross-site scripting (XSS) attacks, allowing an attacker to inject malicious code into web pages and potentially steal sensitive information or perform unauthorized actions.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 1.20.8 1.20.8
  • >= 1.21.0, < 1.21.1 1.21.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 the golang package is not immediately feasible, a temporary workaround can be implemented by manually sanitizing and escaping user-generated content within <script> contexts. This can be achieved by using appropriate HTML encoding functions or libraries to ensure that any potentially malicious code is rendered as plain text and not executed as JavaScript.

Conclusion

The golang package is susceptible to an HTML injection vulnerability in the html/template package. This can be exploited to perform cross-site scripting attacks, potentially compromising user data and application security. It is crucial to update to golang version 1.21.1 or later to mitigate this vulnerability. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for golang →

Share this vulnerability

FAQ

This vulnerability allows an attacker to inject malicious code into web pages, potentially leading to the theft of sensitive information, unauthorized actions, or the compromise of user accounts.

At the time of this report, there are no known public exploits targeting this specific vulnerability. However, it is important to promptly apply the recommended fix to mitigate any potential risks.

No, not all versions of the golang package are affected. Versions 0 and 1.20.8 are vulnerable, while versions 1.21.0 and later have been fixed. It is crucial to update to version 1.21.1 or later to address this vulnerability.

Yes, this vulnerability can be exploited remotely. An attacker can inject malicious code into web pages that are rendered by applications using the vulnerable golang package, potentially affecting any user who visits those pages.

Yes, you can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability. Vulert monitors and alerts in real-time for open-source vulnerabilities, allowing you to assess the security of your software without requiring access to the code or installation.

Related vulnerabilities

Recent vulnerabilities recorded for golang.

How To Fix

Fixed versions by release line

The minimum fixed version depends on the release line you run.

  • < 1.20.8 1.20.8
  • >= 1.21.0, < 1.21.1 1.21.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