CVE-2025-61731: CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') in Go toolchain cmd/go
Building a malicious file with cmd/go can cause can cause a write to an attacker-controlled file with partial control of the file content. The "#cgo pkg-config:" directive in a Go source file provides command-line arguments to provide to the Go pkg-config command. An attacker can provide a "--log-file" argument to this directive, causing pkg-config to write to an attacker-controlled location.
AI Analysis
Technical Summary
CVE-2025-61731 is an OS command injection vulnerability classified under CWE-78 affecting the Go toolchain, specifically the cmd/go command. The vulnerability stems from the way the Go build system processes the "#cgo pkg-config:" directive within Go source files. This directive passes command-line arguments to the pkg-config tool, which is used to retrieve compiler and linker flags for libraries. An attacker can craft a malicious Go source file containing a "#cgo pkg-config:" directive with a "--log-file" argument. This argument instructs pkg-config to write logs to a file at a location controlled by the attacker. Due to insufficient sanitization or neutralization of special characters and command-line arguments, this can lead to writing arbitrary content to attacker-chosen file paths. The vulnerability affects all Go versions from 0 up to and including 1.25.0. Exploitation requires local access with low privileges and no user interaction, making it relatively easy to exploit in environments where untrusted Go code can be built. The impact includes potential arbitrary file writes, which can be leveraged for privilege escalation, code execution, or persistent backdoors. The CVSS v3.1 score is 7.8, indicating high severity with high impact on confidentiality, integrity, and availability. Although no known exploits have been reported in the wild, the vulnerability poses a significant risk to developers and organizations relying on Go for software builds. No official patches are listed yet, so mitigation may require restricting build environments or sanitizing inputs until fixes are released.
Potential Impact
The vulnerability allows attackers to write files to arbitrary locations with partial control over the content, potentially enabling privilege escalation, unauthorized code execution, or persistent compromise. Since Go is widely used for building software across various industries, this flaw can affect a broad range of development environments and production systems. Attackers with local access can exploit this vulnerability to manipulate build artifacts or inject malicious code, undermining software integrity and trust. The compromise of build systems can cascade into supply chain attacks, affecting downstream consumers of the built software. Confidentiality is at risk due to potential exposure or alteration of sensitive files. Integrity is compromised as attackers can alter build outputs or configuration files. Availability may also be impacted if critical files are overwritten or corrupted. The ease of exploitation combined with the widespread use of Go increases the threat level for organizations globally.
Mitigation Recommendations
1. Immediately restrict build environments to trusted users and sources to prevent untrusted code execution. 2. Monitor and audit build logs and file writes for suspicious activity, especially unexpected writes to unusual file paths. 3. Until patches are available, consider disabling or restricting the use of "#cgo pkg-config:" directives in Go source files from untrusted sources. 4. Employ sandboxing or containerization for build processes to limit filesystem and process access. 5. Validate and sanitize all inputs that influence build commands or directives to prevent injection of malicious arguments. 6. Keep Go toolchain versions updated and apply official patches promptly once released. 7. Implement file integrity monitoring on critical build and system files to detect unauthorized modifications. 8. Educate developers and build engineers about the risks of processing untrusted Go source files and enforce strict code review policies.
Affected Countries
United States, Germany, China, India, United Kingdom, Japan, South Korea, France, Canada, Australia
CVE-2025-61731: CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') in Go toolchain cmd/go
Description
Building a malicious file with cmd/go can cause can cause a write to an attacker-controlled file with partial control of the file content. The "#cgo pkg-config:" directive in a Go source file provides command-line arguments to provide to the Go pkg-config command. An attacker can provide a "--log-file" argument to this directive, causing pkg-config to write to an attacker-controlled location.
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
CVE-2025-61731 is an OS command injection vulnerability classified under CWE-78 affecting the Go toolchain, specifically the cmd/go command. The vulnerability stems from the way the Go build system processes the "#cgo pkg-config:" directive within Go source files. This directive passes command-line arguments to the pkg-config tool, which is used to retrieve compiler and linker flags for libraries. An attacker can craft a malicious Go source file containing a "#cgo pkg-config:" directive with a "--log-file" argument. This argument instructs pkg-config to write logs to a file at a location controlled by the attacker. Due to insufficient sanitization or neutralization of special characters and command-line arguments, this can lead to writing arbitrary content to attacker-chosen file paths. The vulnerability affects all Go versions from 0 up to and including 1.25.0. Exploitation requires local access with low privileges and no user interaction, making it relatively easy to exploit in environments where untrusted Go code can be built. The impact includes potential arbitrary file writes, which can be leveraged for privilege escalation, code execution, or persistent backdoors. The CVSS v3.1 score is 7.8, indicating high severity with high impact on confidentiality, integrity, and availability. Although no known exploits have been reported in the wild, the vulnerability poses a significant risk to developers and organizations relying on Go for software builds. No official patches are listed yet, so mitigation may require restricting build environments or sanitizing inputs until fixes are released.
Potential Impact
The vulnerability allows attackers to write files to arbitrary locations with partial control over the content, potentially enabling privilege escalation, unauthorized code execution, or persistent compromise. Since Go is widely used for building software across various industries, this flaw can affect a broad range of development environments and production systems. Attackers with local access can exploit this vulnerability to manipulate build artifacts or inject malicious code, undermining software integrity and trust. The compromise of build systems can cascade into supply chain attacks, affecting downstream consumers of the built software. Confidentiality is at risk due to potential exposure or alteration of sensitive files. Integrity is compromised as attackers can alter build outputs or configuration files. Availability may also be impacted if critical files are overwritten or corrupted. The ease of exploitation combined with the widespread use of Go increases the threat level for organizations globally.
Mitigation Recommendations
1. Immediately restrict build environments to trusted users and sources to prevent untrusted code execution. 2. Monitor and audit build logs and file writes for suspicious activity, especially unexpected writes to unusual file paths. 3. Until patches are available, consider disabling or restricting the use of "#cgo pkg-config:" directives in Go source files from untrusted sources. 4. Employ sandboxing or containerization for build processes to limit filesystem and process access. 5. Validate and sanitize all inputs that influence build commands or directives to prevent injection of malicious arguments. 6. Keep Go toolchain versions updated and apply official patches promptly once released. 7. Implement file integrity monitoring on critical build and system files to detect unauthorized modifications. 8. Educate developers and build engineers about the risks of processing untrusted Go source files and enforce strict code review policies.
Technical Details
- Data Version
- 5.2
- Assigner Short Name
- Go
- Date Reserved
- 2025-09-30T15:05:03.605Z
- Cvss Version
- null
- State
- PUBLISHED
Threat ID: 697a653b4623b1157cea4ee6
Added to database: 1/28/2026, 7:36:27 PM
Last enriched: 2/27/2026, 7:32:06 AM
Last updated: 3/23/2026, 10:59:44 PM
Views: 44
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.