CVE-2021-42248: Denial of service in github.com/tidwall/gjson

github.com/tidwall/gjson Updated 02 Oct 2025

Summary

15/08/2022
Yes i
High
7.5

CVE-2021-42248: Denial of service via maliciously crafted path in github.com/tidwall/gjson. Affects github.com/tidwall/gjson versions < 1.9.3. Fixed in 1.9.3. How to fix ↓

Also tracked for

The same CVE-2021-42248 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

Background

The package github.com/tidwall/gjson is a Go library that provides a fast and simple way to parse JSON data. It offers various functions for querying and extracting data from JSON documents. However, a vulnerability has been discovered in the package that can lead to a denial of service (DoS) condition. This vulnerability can be triggered by a maliciously crafted path, causing excessive CPU and time consumption in functions like Get and query functions.

Vulnerability Detail

The vulnerability (CVE-2021-42248) in github.com/tidwall/gjson arises from the mishandling of certain input paths. When a specially crafted path is provided to functions like Get and query functions, the package fails to handle it efficiently, resulting in excessive CPU and time consumption. This can be exploited by an attacker to launch a DoS attack, causing the affected application to become unresponsive or crash. The impact of this vulnerability can be severe, especially in scenarios where the package is used in critical systems or services.

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, if updating the package is not immediately feasible, developers can implement input validation and sanitization mechanisms to filter out potentially malicious paths. By carefully validating and sanitizing user-supplied input before passing it to functions like Get and query functions, the risk of exploitation can be reduced. Here's an example of input validation in Go:

import (
	"github.com/tidwall/gjson"
	"regexp"
)

func validatePath(path string) bool {
	// Define a regular expression pattern to match valid paths
	pattern := regexp.MustCompile(`^[a-zA-Z0-9_]+$`)

	// Check if the provided path matches the pattern
	return pattern.MatchString(path)
}

In this example, the validatePath function uses a regular expression pattern to ensure that the path only contains alphanumeric characters and underscores. By validating the input before using it in functions from the github.com/tidwall/gjson package, the risk of triggering the vulnerability can be mitigated.

Conclusion

In conclusion, the github.com/tidwall/gjson package is vulnerable to a denial of service (DoS) attack due to the mishandling of certain input paths. This can be exploited by an attacker to consume excessive CPU and time, leading to application unresponsiveness or crashes. To mitigate this vulnerability, it is crucial to update the package to version 1.9.3 or later. Additionally, implementing input validation and sanitization mechanisms can provide a temporary workaround. For further support on vulnerability remediation, you can reach out to DevNack.com.

See every vulnerability recorded for github.com/tidwall/gjson →

Share this vulnerability

FAQ

This vulnerability can lead to a denial of service (DoS) condition in applications that use the github.com/tidwall/gjson package. An attacker can exploit the vulnerability by providing a maliciously crafted path, causing excessive CPU and time consumption. This can result in the affected application becoming unresponsive or crashing.

You can use the Vulert Playground at Vulert Scanner to check if your application is affected by this vulnerability. The Vulert Playground allows you to analyze your application's dependencies without requiring access to the code or installation. Simply provide your Gopkg.lock file, and Vulert will alert you in real-time if any open-source vulnerabilities, including this one, are detected.

Yes, if updating the github.com/tidwall/gjson package is not immediately feasible, you can implement input validation and sanitization mechanisms to filter out potentially malicious paths. By carefully validating and sanitizing user-supplied input before passing it to functions like Get and query functions, the risk of exploitation can be reduced.

Yes, the maintainers of the github.com/tidwall/gjson package have addressed this vulnerability in version 1.9.3. It is recommended to update to this version or later to ensure that the vulnerability is mitigated.

You can find more information about this vulnerability, including technical details and the fixed version, in the vulnerability report at https://pkg.go.dev/vuln/GO-2021-0265.

Related vulnerabilities

Recent vulnerabilities recorded for github.com/tidwall/gjson.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback