CVE-2022-1962: Stack exhaustion due to deeply nested types in go/parser
Summary
CVE-2022-1962: Stack exhaustion due to deeply nested types in go/parser. Affects stdlib across 2 version ranges.
< 1.17.12
>= 1.18.0-0, < 1.18.4
Fixed in 1.17.12 or 1.18.4, depending on the release line you run. How to fix ↓
Also tracked for
- golang · Bitnami
- golang-1.15 · Debian:11
The same CVE-2022-1962 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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.
No signup required · Results in about 60 seconds
Background
The stdlib package in the Go ecosystem provides a set of standard libraries for the Go programming language. It includes various modules and functionalities that developers can utilize in their applications. One of the packages within stdlib is go/parser, which is responsible for parsing Go source code. This package allows developers to analyze and manipulate Go code programmatically. However, a vulnerability has been discovered in go/parser that can lead to stack exhaustion when parsing Go source code containing deeply nested types or declarations.
Vulnerability Detail
The vulnerability (CVE-2022-1962) arises when any of the Parse functions in go/parser are called on Go source code with deeply nested types or declarations. This can trigger a panic due to stack exhaustion, potentially causing the application to crash. The issue originates from the parser's inability to handle excessive nesting levels, leading to an uncontrolled growth of the call stack. Attackers could potentially exploit this vulnerability to disrupt the functioning of affected applications or launch denial-of-service attacks.
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.17.121.17.12go get stdlib@v1.17.12 -
>= 1.18.0-0, < 1.18.41.18.4go get stdlib@v1.18.4
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a workaround, developers can manually limit the nesting levels in their Go source code to avoid triggering the stack exhaustion issue. By reducing the depth of nested types or declarations, the vulnerability can be mitigated. Here's an example of how to limit nesting levels in Go code:
package main
// Limit the nesting level of types
type Level1 struct {
Level2 struct {
Level3 struct {
// ... Continue nesting as needed
}
}
}
func main() {
// Code using the limited nesting level types
}
Conclusion
The stack exhaustion vulnerability in go/parser (CVE-2022-1962) can cause applications to crash when parsing Go source code with deeply nested types or declarations. To mitigate this issue, developers should update their Go version to 1.17.12 or 1.18.4. Additionally, manually limiting nesting levels in the code can serve as a temporary workaround. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for stdlib →
FAQ
The vulnerability can lead to stack exhaustion, causing the application to crash. This can result in service disruptions and potential denial-of-service attacks.
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, using Gopkg.lock as input.
No, not all versions of Go are affected. Versions 1.17.12 and 1.18.4 include the necessary fixes to mitigate the vulnerability. It is recommended to update to these versions or later.
No, this vulnerability does not allow remote code execution. However, it can be exploited by an attacker who can provide Go source code with deeply nested types or declarations to the affected application.
Currently, limiting nesting levels is the recommended workaround. It is important to update to the fixed versions of Go to fully mitigate the vulnerability.
References
Related vulnerabilities
Recent vulnerabilities recorded for stdlib.