CVE-2021-42248: Denial of Service in github.com/tidwall/gjson
Summary
GO-2022-0592: A maliciously crafted path can cause Get and other query functions to consume excessive amounts of CPU and time. Affects github.com/tidwall/gjson versions < 1.9.3. Fixed in 1.9.3. How to fix ↓
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 package github.com/tidwall/gjson is a Go library that provides a fast and simple way to parse JSON data. It offers functions like Get, GetBytes, GetMany, GetManyBytes, Result.Get, parseObject, and queryMatches to extract values from JSON documents. However, a vulnerability has been discovered in this package that can lead to a denial of service (DoS) attack when processing a maliciously crafted path. This vulnerability affects versions 0 through 1.9.2 of the package.
Vulnerability Detail
The vulnerability in github.com/tidwall/gjson arises from a flaw in the handling of certain paths during JSON parsing. An attacker can exploit this flaw by providing a specially crafted path that triggers excessive CPU and time consumption when using functions like Get and other query functions. This can result in a DoS condition, causing the application to become unresponsive or crash. The impact of this vulnerability can be severe, as it allows an attacker to disrupt the availability of the affected application.
How To Fix
Latest published version: v1.20.0 as of 23 Oct 2026
go get github.com/tidwall/gjson@v1.20.0
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
1.9.3
This is the first release that contains the fix.
go get github.com/tidwall/gjson@v1.9.3
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a workaround, developers can implement input validation and sanitization to ensure that the paths provided to the affected functions are not maliciously crafted. By validating and sanitizing user input, the risk of triggering the vulnerability can be mitigated. Here is an example of input validation and sanitization for the Get function:
def validatePath(path string) (string, error) {
// Perform input validation and sanitization
// Return sanitized path or error if validation fails
}
func main() {
path := validatePath(userInput)
if path != nil {
value := gjson.Get(jsonData, path)
// Process the value
}
}
Conclusion
In conclusion, the github.com/tidwall/gjson package is vulnerable to a denial of service (DoS) attack due to a flaw in path handling. This vulnerability can be mitigated by upgrading to version 1.9.3 or later of the package and implementing input validation and sanitization. Developers should take immediate action to protect their applications from this vulnerability. For further support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for github.com/tidwall/gjson →
FAQ
This vulnerability can lead to a denial of service (DoS) condition in the affected application, causing it to become unresponsive or crash. It can be exploited by an attacker to disrupt the availability of the application.
Versions 0 through 1.9.2 of the github.com/tidwall/gjson package are affected by this vulnerability.
To fix this vulnerability, it is recommended to upgrade to version 1.9.3 or later of the github.com/tidwall/gjson package. Updating the package to the latest secure version will prevent the excessive CPU and time consumption caused by the flaw in path handling.
Yes, developers can implement input validation and sanitization to mitigate the risk of triggering the vulnerability. By validating and sanitizing user input before passing it to the affected functions, the impact of the vulnerability can be reduced.
For more information about this vulnerability, you can refer to the official vulnerability report at https://pkg.go.dev/vuln/GO-2021-0265.
References
Related vulnerabilities
Recent vulnerabilities recorded for github.com/tidwall/gjson.