CVE-2023-29402 Overview
CVE-2023-29402 is a code injection vulnerability in the Go programming language's build system. The go command may generate unexpected code at build time when using cgo if an untrusted module contains directories with newline characters in their names. This can result in arbitrary code execution when building or running a Go program that uses cgo components from malicious sources.
Critical Impact
This vulnerability allows attackers to inject malicious code during the build process by exploiting improper handling of newline characters in directory names, potentially leading to complete system compromise.
Affected Products
- Golang Go (versions prior to patch)
- Fedora 38 (via bundled Go packages)
Discovery Timeline
- 2023-06-08 - CVE-2023-29402 published to NVD
- 2025-01-06 - Last updated in NVD database
Technical Details for CVE-2023-29402
Vulnerability Analysis
This vulnerability exists in the Go toolchain's handling of cgo during the build process. When processing module directories, the go command fails to properly sanitize directory names containing newline characters. This allows an attacker to craft a malicious module with specially named directories that can inject arbitrary commands or code into the build process.
The vulnerability is classified as CWE-94 (Improper Control of Generation of Code - Code Injection), indicating that the core issue lies in the build system's failure to properly validate and sanitize input that becomes part of generated code or commands.
Notably, modules retrieved using the standard go get command are not affected by this vulnerability. However, modules retrieved using GOPATH-mode (when GO111MODULE=off is set) may be vulnerable. This distinction is important as it affects the attack surface and potential exploitation scenarios.
Root Cause
The root cause is improper input validation in the Go toolchain's cgo processing. When the build system encounters directory names during compilation, it fails to properly escape or reject directory names containing newline characters. These newlines can be interpreted as command separators or code delimiters, allowing injected content to be executed during the build process.
Attack Vector
The attack is network-based and requires no authentication or user interaction beyond building an untrusted module. An attacker can create a malicious Go module containing directories with carefully crafted names that include newline characters. When a victim builds this module with cgo enabled, the newline characters break out of the expected context and inject malicious code or commands into the build process.
The attack scenario typically involves:
- Attacker creates a malicious Go module with directory names containing embedded newline characters
- Victim clones or downloads the module (particularly via GOPATH-mode)
- Victim attempts to build the module with cgo enabled
- The build system processes the malicious directory names without proper sanitization
- Injected code executes with the privileges of the build process
Detection Methods for CVE-2023-29402
Indicators of Compromise
- Unusual directory names in Go module dependencies containing non-printable or special characters
- Unexpected processes spawned during Go build operations
- Build logs showing unusual or injected commands
- Anomalous network activity during module compilation
Detection Strategies
- Implement file integrity monitoring on Go modules and build directories to detect suspicious directory naming patterns
- Monitor build process execution for unexpected child processes or system calls
- Use SentinelOne's behavioral AI to detect anomalous activity during development and build workflows
- Audit Go module dependencies for untrusted or suspicious sources before building
Monitoring Recommendations
- Enable verbose logging for Go build processes to capture detailed build output
- Implement runtime protection on development and CI/CD systems to detect code injection attempts
- Monitor for builds using GOPATH-mode (GO111MODULE=off) which are more susceptible to this vulnerability
- Deploy endpoint protection on build servers to detect and prevent malicious code execution
How to Mitigate CVE-2023-29402
Immediate Actions Required
- Update Go to the latest patched version immediately
- Avoid building untrusted Go modules, especially those not retrieved via go get
- Ensure GO111MODULE is not set to off to benefit from the protections in module mode
- Audit existing Go projects for any dependencies with suspicious directory names
Patch Information
Golang has released patches to address this vulnerability. The fix is available in the Go.dev Code Review and documented in the Go.dev Vulnerability Advisory. Users should update to the latest stable version of Go that includes these security fixes.
Distribution-specific updates are available:
Workarounds
- Use go get for module retrieval instead of GOPATH-mode to reduce exposure
- Implement build sandboxing to limit the impact of potential code injection
- Review and validate all third-party module sources before building
- Consider disabling cgo (CGO_ENABLED=0) for builds that don't require it
# Ensure module mode is enabled (not vulnerable to GOPATH-mode attacks)
export GO111MODULE=on
# Disable cgo if not required for your build
export CGO_ENABLED=0
# Verify Go version includes security patches
go version
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


