CVE-2024-24785
Medium · 5.4CVSS
5.4
EPSS
0.8%
Published
Mar 5, 2024
CISA due date
—
Cloudanix analysis
A flaw in a common web development language could allow an attacker to inject malicious code into a website by tricking it into generating a specific type of error message.
- Exploitation
- Remote Authenticated
- Attacker needs
- Low Privilege
- Complexity
- Low
- Impact
- Data Tampering
- Component
- Library
- Class
- XSS
- Remediation
- Upgrade
- Effort
- Medium
- Patch risk
- Low
What it actually does
A vulnerability in Go's html/template package allows for Cross-Site Scripting (XSS). When a MarshalJSON method returns an error containing user-controlled data, the auto-escaping mechanism can be bypassed. This allows an attacker to inject arbitrary HTML and script content into the rendered web page, as the template engine fails to properly sanitize the content within the error.
Why it matters to the business
Successful exploitation can lead to the compromise of user accounts, theft of sensitive session data (like cookies), and unauthorized actions performed on behalf of the user. This can result in reputational damage, loss of customer trust, and potential regulatory penalties if sensitive data is exposed. The application could also be used as a platform for phishing or distributing malware to its users.
How an attack unfolds
An attacker, authenticated as a low-privileged user, identifies an input field in a Go-based web application that can trigger an error during JSON marshaling. The attacker crafts a malicious input containing a script payload (e.g., `<script>alert(1)</script>`) designed to be reflected within the resulting error message. When the application processes this input, the MarshalJSON function fails and returns an error containing the attacker's payload. The html/template engine then renders this error on a page, but due to the vulnerability, it fails to escape the script tags. The malicious script then executes in the browser of any user who views the page containing the rendered error.
How to fix it
The vulnerability is fixed in Go versions 1.22.1 and 1.21.8. To remediate, upgrade the Go toolchain to a patched version and recompile all affected applications. As a defense-in-depth measure, developers should review custom MarshalJSON implementations and avoid including raw, user-controlled data in returned error strings. If user data must be included, it should be sanitized or encoded before being placed in the error.
How to confirm the fix worked
To validate the fix, verify that applications have been recompiled using a patched Go version (1.22.1+ or 1.21.8+). This can be confirmed by running `go version -m <binary_name>` on the compiled artifact. Additionally, perform penetration testing or dynamic application security testing (DAST) to confirm the XSS vector is no longer exploitable. Testers should attempt to trigger JSON marshaling errors with payloads in user-controlled fields and verify that any reflected output is properly escaped.
Typical attack path
- Attacker identifies an input field in a Go web application that can trigger an error during JSON marshaling.
- Attacker crafts a malicious input containing a script payload, designed to be reflected in the error message.
- Attacker submits the malicious input to the application.
- The application's MarshalJSON method fails and returns an error containing the attacker's payload.
- The html/template engine renders the error page, but due to the flaw, it does not escape the attacker's script.
- The malicious script executes in the victim's browser when they view the resulting page.
How to detect it
To detect potential exploitation, monitor web server access logs and application logs for HTTP requests that appear crafted to trigger errors, followed by server responses (HTTP 5xx or 2xx with error content) containing unescaped HTML or script tags. Web Application Firewall (WAF) logs may also contain alerts for XSS patterns targeting API endpoints or form submissions handled by a Go backend. Focus on error pages or API responses that unexpectedly render HTML content.
What your security team should do
- Identify all applications built with Go and prioritize upgrading the Go toolchain to version 1.22.1 or 1.21.8, followed by recompilation and deployment.
- Instruct development teams to perform static analysis to find custom MarshalJSON implementations that may be vulnerable to this pattern.
- Ensure Web Application Firewall (WAF) rules are enabled and configured to detect and block common XSS attack patterns as a mitigating control.
The record
If errors returned from MarshalJSON methods contain user controlled data, they may be used to break the contextual auto-escaping behavior of the html/template package, allowing for subsequent actions to inject unexpected content into templates.
Affected packages
| Ecosystem | Package | Introduced | Fixed |
|---|---|---|---|
| Go | stdlib | 0 | 1.21.8 |
| AlmaLinux:8 | delve | 0 | 1.21.2-3.module_el8.10.0+3760+4dd778f9 |
| AlmaLinux:8 | go-toolset | 0 | 1.21.9-1.module_el8.10.0+3840+edaca3c3 |
| AlmaLinux:8 | golang | 0 | 1.21.9-1.module_el8.10.0+3840+edaca3c3 |
| AlmaLinux:8 | golang-bin | 0 | 1.21.9-1.module_el8.10.0+3840+edaca3c3 |
| AlmaLinux:8 | golang-docs | 0 | 1.21.9-1.module_el8.10.0+3840+edaca3c3 |
| AlmaLinux:8 | golang-misc | 0 | 1.21.9-1.module_el8.10.0+3840+edaca3c3 |
| AlmaLinux:8 | golang-src | 0 | 1.21.9-1.module_el8.10.0+3840+edaca3c3 |
| AlmaLinux:8 | golang-tests | 0 | 1.21.9-1.module_el8.10.0+3840+edaca3c3 |
| AlmaLinux:9 | go-toolset | 0 | 1.21.9-2.el9_4 |
| AlmaLinux:9 | golang | 0 | 1.21.9-2.el9_4 |
| AlmaLinux:9 | golang-bin | 0 | 1.21.9-2.el9_4 |
| AlmaLinux:9 | golang-docs | 0 | 1.21.9-2.el9_4 |
| AlmaLinux:9 | golang-misc | 0 | 1.21.9-2.el9_4 |
| AlmaLinux:9 | golang-src | 0 | 1.21.9-2.el9_4 |
| AlmaLinux:9 | golang-tests | 0 | 1.21.9-2.el9_4 |
| AlmaLinux:9 | toolbox | 0 | 0.0.99.5-5.el9 |
| AlmaLinux:9 | toolbox-tests | 0 | 0.0.99.5-5.el9 |
| Bitnami | golang | 0 | 1.21.8 |
| Chainguard | actions-runner-controller | 0 | 0.8.3-r1 |
| Chainguard | actions-runner-controller-compat | 0 | 0.8.3-r1 |
| Chainguard | amass | 0 | 4.2.0-r4 |
| Chainguard | argo-cd-2.7 | 0 | 2.7.17-r1 |
| Chainguard | argo-cd-2.7-compat | 0 | 2.7.17-r1 |
| Chainguard | argo-cd-2.7-repo-server | 0 | 2.7.17-r1 |
| Chainguard | argo-cd-fips-2.10 | 0 | 2.10.2-r1 |
| Chainguard | argo-cd-fips-2.10-compat | 0 | 2.10.2-r1 |
| Chainguard | argo-cd-fips-2.10-repo-server | 0 | 2.10.2-r1 |
| Chainguard | argo-cd-fips-2.9 | 0 | 2.9.6-r1 |
| Chainguard | argo-cd-fips-2.9-compat | 0 | 2.9.6-r1 |
| Chainguard | argo-cd-fips-2.9-repo-server | 0 | 2.9.6-r1 |
| Chainguard | argo-workflow-cli | 0 | 3.6.5-r2 |
| Chainguard | argo-workflow-cli-fips | 0 | 3.5.5-r1 |
| Chainguard | argo-workflow-controller | 0 | 3.6.5-r2 |
| Chainguard | argo-workflow-controller-compat | 0 | 3.6.5-r2 |
| Chainguard | argo-workflow-controller-compat-fips | 0 | 3.5.5-r1 |
| Chainguard | argo-workflow-controller-fips | 0 | 3.5.5-r1 |
| Chainguard | argo-workflow-executor | 0 | 3.6.5-r2 |
| Chainguard | argo-workflow-executor-compat | 0 | 3.6.5-r2 |
| Chainguard | argo-workflow-executor-compat-fips | 0 | 3.5.5-r1 |
| Chainguard | argo-workflow-executor-fips | 0 | 3.5.5-r1 |
| Chainguard | argo-workflows | 0 | 3.6.5-r2 |
| Chainguard | argo-workflows-fips | 0 | 3.5.5-r1 |
| Chainguard | argo-workflows-known-hosts | 0 | 3.6.5-r2 |
| Chainguard | argo-workflows-known-hosts-fips | 0 | 3.5.5-r1 |
| Chainguard | argo-workflows-ui | 0 | 3.6.5-r2 |
| Chainguard | atlantis-fips | 0 | 0.33.0-r6 |
| Chainguard | aws-ebs-csi-driver | 0 | 1.28.0-r1 |
| Chainguard | aws-ebs-csi-driver-1.18 | 0 | 1.18.0-r11 |
| Chainguard | aws-ebs-csi-driver-1.19 | 0 | 1.19.0-r11 |
| Chainguard | aws-ebs-csi-driver-fips | 0 | 1.28.0-r1 |
| Chainguard | aws-efs-csi-driver | 0 | 1.7.6-r1 |
| Chainguard | aws-efs-csi-driver-fips | 0 | 1.7.0-r4 |
| Chainguard | aws-efs-csi-driver-fips-1.6 | 0 | 1.6.0-r4 |
| Chainguard | aws-flb-cloudwatch | 0 | 1.9.4-r7 |
| Chainguard | aws-flb-cloudwatch-compat | 0 | 1.9.4-r7 |
| Chainguard | aws-flb-firehose | 0 | 1.7.2-r7 |
| Chainguard | aws-flb-firehose-compat | 0 | 1.7.2-r7 |
| Chainguard | aws-flb-kinesis | 0 | 1.10.2-r7 |
| Chainguard | aws-flb-kinesis-compat | 0 | 1.10.2-r7 |
| Chainguard | aws-load-balancer-controller | 0 | 2.7.1-r1 |
| Chainguard | aws-load-balancer-controller-2.4.5 | 0 | 2.4.5-r9 |
| Chainguard | aws-load-balancer-controller-2.5 | 0 | 2.5.4-r2 |
| Chainguard | aws-load-balancer-controller-compat | 0 | 2.7.1-r1 |
| Chainguard | aws-load-balancer-controller-compat-2.4.5 | 0 | 2.5.4-r2 |
| Chainguard | aws-load-balancer-controller-fips | 0 | 2.7.1-r1 |
| Chainguard | azure-aad-pod-identity-mic | 0 | 1.8.17-r5 |
| Chainguard | azure-aad-pod-identity-nmi | 0 | 1.8.17-r5 |
| Chainguard | bank-vaults-fips | 0 | 1.20.4-r5 |
| Chainguard | bank-vaults-template-fips | 0 | 1.20.4-r5 |
| Chainguard | bazelisk | 0 | 1.19.0-r1 |
| Chainguard | bazelisk-default | 0 | 1.19.0-r1 |
| Chainguard | bom | 0 | 0.6.0-r1 |
| Chainguard | boring-registry-fips | 0 | 0.13.2-r1 |
| Chainguard | buildctl | 0 | 0.13.1-r2 |
| Chainguard | buildkitd | 0 | 0.13.1-r2 |
| Chainguard | caddy | 0 | 2.7.6-r3 |
| Chainguard | caddy-man | 0 | 2.7.6-r3 |
| Chainguard | caddy-src | 0 | 2.7.6-r3 |
| Chainguard | cadvisor | 0 | 0.49.1-r3 |
| Chainguard | cadvisor-compat | 0 | 0.49.1-r3 |
| Chainguard | calico | 0 | 3.27.2-r2 |
| Chainguard | calico-apiserver | 0 | 3.27.2-r2 |
| Chainguard | calico-app-policy | 0 | 3.27.2-r2 |
| Chainguard | calico-cni | 0 | 3.27.2-r2 |
| Chainguard | calico-cni-compat | 0 | 3.27.2-r2 |
| Chainguard | calico-cni-fips-compat | 0 | 3.27.2-r1 |
| Chainguard | calico-felix | 0 | 3.27.2-r2 |
| Chainguard | calico-fips | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-apiserver | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-app-policy | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-cni | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-felix | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-key-cert-provisioner | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-kube-controllers | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-node | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-pod2daemon | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-typha-client | 0 | 3.27.2-r1 |
| Chainguard | calico-fips-typhad | 0 | 3.27.2-r1 |
| Chainguard | calico-key-cert-provisioner | 0 | 3.27.2-r2 |
| Chainguard | calico-kube-controllers | 0 | 3.27.2-r2 |
| Chainguard | calico-node | 0 | 3.27.2-r2 |
| Chainguard | calico-pod2daemon | 0 | 3.27.2-r2 |
| Chainguard | calico-pod2daemon-flexvol-compat | 0 | 3.27.2-r2 |
| Chainguard | calico-typha-client | 0 | 3.27.2-r2 |
| Chainguard | calico-typhad | 0 | 3.27.2-r2 |
| Chainguard | calicoctl | 0 | 3.27.2-r2 |
| Chainguard | calicoctl-fips | 0 | 3.27.2-r1 |
| Chainguard | capslock | 0 | 0.2.1-r1 |
| Chainguard | cass-operator | 0 | 1.18.2-r4 |
| Chainguard | cass-operator-compat | 0 | 1.18.2-r4 |
| Chainguard | cass-operator-compat-fips | 0 | 1.18.2-r3 |
| Chainguard | cass-operator-config | 0 | 1.18.2-r4 |
| Chainguard | cass-operator-fips | 0 | 1.18.2-r3 |
| Chainguard | cass-operator-fips-no-pvc-delete | 0 | 1.18.2-r4 |
| Chainguard | cass-operator-fips-no-pvc-delete-compat | 0 | 1.18.2-r4 |
| Chainguard | cert-exporter | 0 | 2.12.0-r1 |
| Chainguard | cert-exporter-fips | 0 | 2.12.0-r1 |
| Chainguard | cert-manager-fips-1.13 | 0 | 1.13.4-r1 |
| Chainguard | cert-manager-fips-1.13-acmesolver | 0 | 1.13.4-r1 |
| Chainguard | cert-manager-fips-1.13-cainjector | 0 | 1.13.4-r1 |
| Chainguard | cert-manager-fips-1.13-cmctl | 0 | 1.13.4-r1 |
| Chainguard | cert-manager-fips-1.13-controller | 0 | 1.13.4-r1 |
| Chainguard | cert-manager-fips-1.13-webhook | 0 | 1.13.4-r1 |
| Chainguard | cert-manager-fips-1.14 | 0 | 1.14.3-r1 |
| Chainguard | cert-manager-fips-1.14-acmesolver | 0 | 1.14.3-r1 |
| Chainguard | cert-manager-fips-1.14-cainjector | 0 | 1.14.3-r1 |
| Chainguard | cert-manager-fips-1.14-cmctl | 0 | 1.14.3-r1 |
| Chainguard | cert-manager-fips-1.14-controller | 0 | 1.14.3-r1 |
| Chainguard | cert-manager-fips-1.14-startupapicheck | 0 | 1.14.3-r1 |
| Chainguard | cert-manager-fips-1.14-webhook | 0 | 1.14.3-r1 |
| Chainguard | cfssl | 0 | 1.6.5-r0 |
| Chainguard | cfssl-bundle | 0 | 1.6.5-r0 |
| Chainguard | cfssl-certinfo | 0 | 1.6.5-r0 |
| Chainguard | cfssl-cfssl-bundle | 0 | 1.6.5-r0 |
| Chainguard | cfssl-cfssl-certinfo | 0 | 1.6.5-r0 |
| Chainguard | cfssl-cfssl-newkey | 0 | 1.6.5-r0 |
| Chainguard | cfssl-cfssl-scan | 0 | 1.6.5-r0 |
| Chainguard | cfssl-cfssljson | 0 | 1.6.5-r0 |
| Chainguard | cfssl-json | 0 | 1.6.5-r0 |
| Chainguard | cfssl-mkbundle | 0 | 1.6.5-r0 |
| Chainguard | cfssl-multirootca | 0 | 1.6.5-r0 |
| Chainguard | cfssl-newkey | 0 | 1.6.5-r0 |
| Chainguard | cfssl-scan | 0 | 1.6.5-r0 |
| Chainguard | chainctl | 0 | 0.2.59-r0 |
| Chainguard | chartmuseum | 0 | 0.16.1-r4 |
| Chainguard | cloud-sql-proxy | 0 | 2.9.0-r1 |
| Chainguard | cloud-sql-proxy-compat | 0 | 2.9.0-r1 |
| Chainguard | cloud-sql-proxy-fips | 0 | 2.8.2-r1 |
| Chainguard | cloud-sql-proxy-fips-compat | 0 | 2.8.2-r1 |
| Chainguard | cluster-api-controller | 0 | 1.6.3-r0 |
| Chainguard | cluster-autoscaler-1.25 | 0 | 1.25.3-r10 |
| Chainguard | cluster-autoscaler-1.25-compat | 0 | 1.25.3-r10 |
| Chainguard | cluster-autoscaler-1.27 | 0 | 1.27.5-r2 |
| Chainguard | cluster-autoscaler-1.27-compat | 0 | 1.27.5-r2 |
| Chainguard | cluster-autoscaler-1.28 | 0 | 1.28.2-r2 |
| Chainguard | cluster-autoscaler-1.28-compat | 0 | 1.28.2-r2 |
| Chainguard | cluster-autoscaler-1.29 | 0 | 1.29.0-r1 |
| Chainguard | cluster-autoscaler-1.29-compat | 0 | 1.29.0-r1 |
| Chainguard | cluster-autoscaler-fips-1.25 | 0 | 1.25.3-r5 |
| Chainguard | cluster-autoscaler-fips-1.25-compat | 0 | 1.25.3-r5 |
| Chainguard | cluster-autoscaler-fips-1.26 | 0 | 1.26.6-r2 |
| Chainguard | cluster-autoscaler-fips-1.26-compat | 0 | 1.26.6-r2 |
| Chainguard | cluster-autoscaler-fips-1.27 | 0 | 1.27.5-r1 |
| Chainguard | cluster-autoscaler-fips-1.27-compat | 0 | 1.27.5-r1 |
| Chainguard | cluster-autoscaler-fips-1.28 | 0 | 1.28.2-r2 |
| Chainguard | cluster-autoscaler-fips-1.28-compat | 0 | 1.28.2-r2 |
| Chainguard | cluster-proportional-autoscaler | 0 | 1.8.11-r1 |
| Chainguard | cluster-proportional-autoscaler-compat | 0 | 1.8.11-r1 |
| Chainguard | clusterctl | 0 | 1.6.3-r0 |
| Chainguard | cmctl-1.13-fips | 0 | 1.13.4-r1 |
| Chainguard | cmctl-1.14-fips | 0 | 1.14.3-r1 |
| Chainguard | cni-plugins | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-aws-k8s-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-bandwidth | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-bandwidth-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-bridge | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-bridge-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-dhcp | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-dhcp-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-dummy | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-dummy-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-bandwidth | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-bandwidth-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-bridge | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-bridge-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-dhcp | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-dhcp-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-dummy | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-dummy-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-firewall | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-firewall-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-host-device | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-host-device-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-host-local | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-host-local-compat | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-ipam | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-ipvlan | 0 | 1.4.0-r2 |
| Chainguard | cni-plugins-fips-ipvlan-compat | 0 | 1.4.0-r2 |
Related vulnerabilities
- CVE-2025-68121 During session resumption in crypto/tls, if the underlying Config has its ClientCAs or… Also affects stdlib
- CVE-2025-22873 It was possible to improperly access the parent directory of an os.Root by opening a… Also affects stdlib
- GO-2026-4403 Improper access to parent directory of root in os Also affects stdlib
- CVE-2025-61726 The net/url package does not set a limit on the number of query parameters in a query. Also affects stdlib
- CVE-2025-61728 archive/zip uses a super-linear file name indexing algorithm that is invoked the first… Also affects stdlib
- CVE-2025-61730 During the TLS 1.3 handshake if multiple messages are sent in records that span… Also affects stdlib
- CVE-2025-61727 An excluded subdomain constraint in a certificate chain does not restrict the usage of… Also affects stdlib
- CVE-2025-61729 Within HostnameError.Error(), when constructing an error string, there is no limit to the… Also affects stdlib