GHSA-r2xf-8xr9-62gw

Suggest an improvement
Source
https://github.com/advisories/GHSA-r2xf-8xr9-62gw
Import Source
https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/09/GHSA-r2xf-8xr9-62gw/GHSA-r2xf-8xr9-62gw.json
JSON Data
https://api.osv.dev/v1/vulns/GHSA-r2xf-8xr9-62gw
Aliases
  • CVE-2026-77422
Published
2026-09-23T18:12:35Z
Modified
2026-09-23T18:27:57Z
Severity
  • 7.5 (High) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H CVSS Calculator
Summary
JLine: ReDoS in Built-in grep Command Amplified by Automatic `.*` Wrapping
Details

Summary

The JLine3 built-in grep command wraps the user-supplied regular expression with .* before compiling it with Java's backtracking regex engine. This amplifies catastrophic backtracking and allows a short pattern such as (a+)+b to hang the command thread on non-matching input. In environments that expose the JLine shell to remote users, this is a denial-of-service issue.

Details

In builtins/src/main/java/org/jline/builtins/PosixCommands.java, the grep implementation rewrites the user pattern before compilation:

String regex = args.remove(0);
String regexp = regex;
if (opt.isSet("word-regexp")) {
    regexp = "\\b" + regexp + "\\b";
}
if (opt.isSet("line-regexp")) {
    regexp = "^" + regexp + "$";
} else {
    regexp = ".*" + regexp + ".*";
}

The transformed pattern is compiled with Pattern.compile(...) and then used to test each input line. For a payload such as (a+)+b, the automatic .* prefix and suffix increase the backtracking search space substantially.

Affected source location:

  • builtins/src/main/java/org/jline/builtins/PosixCommands.java
  • grep(...)

PoC

  1. Create a file containing a long run of a characters:
printf 'aaaaaaaaaaaaaaaaaaaaaaa\n' > /tmp/testfile.txt
  1. Run JLine3's built-in grep against that file:
grep '(a+)+b' /tmp/testfile.txt

Expected result:

  • The command stops responding.
  • The executing thread consumes high CPU.

Reproduction environment:

  • JLine3 on x86_64 Linux
  • OpenJDK 25.0.2

Impact

This is a denial-of-service vulnerability caused by catastrophic regex backtracking. Any application embedding org.jline:jline-builtins and exposing the built-in grep command is impacted. In remote shell deployments, an attacker can occupy a worker thread indefinitely and repeat the attack across multiple sessions to reduce service availability for other users.

Suggested Fix

The preferred fix for the current git head is:

  • stop rewriting non-line-regexp searches as .*...*
  • use Matcher.find() for substring semantics
  • compile user patterns with a linear-time engine such as RE2/J

Suggested patch:

diff --git a/builtins/pom.xml b/builtins/pom.xml
--- a/builtins/pom.xml
+++ b/builtins/pom.xml
@@
         <dependency>
+            <groupId>com.google.re2j</groupId>
+            <artifactId>re2j</artifactId>
+            <version>1.8</version>
+        </dependency>
+        <dependency>
             <groupId>org.jline</groupId>
             <artifactId>jline-reader</artifactId>
         </dependency>

diff --git a/builtins/src/main/java/org/jline/builtins/PosixCommands.java b/builtins/src/main/java/org/jline/builtins/PosixCommands.java
--- a/builtins/src/main/java/org/jline/builtins/PosixCommands.java
+++ b/builtins/src/main/java/org/jline/builtins/PosixCommands.java
@@
-import java.util.regex.Pattern;
+import com.google.re2j.Pattern;
@@
         if (opt.isSet("line-regexp")) {
             regexp = "^" + regexp + "$";
-        } else {
-            regexp = ".*" + regexp + ".*";
         }
@@
-        boolean m = p.matcher(line).matches();
+        boolean m = opt.isSet("line-regexp")
+                ? p.matcher(line).matches()
+                : p.matcher(line).find();

Credits

This issue was identified by MichaƂ Majchrowicz and Marcin Wyczechowski, members of the AFINE Team.

Database specific
{
    "cwe_ids":  [
        "CWE-1333"
    ],
    "github_reviewed":  true,
    "github_reviewed_at":  "2026-09-23T18:12:35Z",
    "nvd_published_at":  null,
    "severity":  "HIGH"
}
References

Affected packages

Maven / org.jline:jline-builtins

Package

Name
org.jline:jline-builtins
View open source insights on deps.dev
Purl
pkg:maven/org.jline/jline-builtins

Affected ranges

Type
ECOSYSTEM
Events
Introduced
4.0.0
Fixed
4.3.1

Affected versions

4.*
4.0.0
4.0.2
4.0.3
4.0.4
4.0.5
4.0.6
4.0.7
4.0.8
4.0.9
4.0.10
4.0.11
4.0.12
4.0.13
4.0.14
4.0.15
4.0.16
4.1.0
4.1.1
4.1.2
4.1.3
4.2.0
4.2.1
4.3.0

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/09/GHSA-r2xf-8xr9-62gw/GHSA-r2xf-8xr9-62gw.json"

Maven / org.jline:jline-builtins

Package

Name
org.jline:jline-builtins
View open source insights on deps.dev
Purl
pkg:maven/org.jline/jline-builtins

Affected ranges

Type
ECOSYSTEM
Events
Introduced
3.0.0
Fixed
3.30.15

Affected versions

3.*
3.2.0
3.3.0
3.3.1
3.4.0
3.5.0
3.5.1
3.5.2
3.6.0
3.6.1
3.6.2
3.7.0
3.7.1
3.8.0
3.8.1
3.8.2
3.9.0
3.10.0
3.11.0
3.12.0
3.12.1
3.13.0
3.13.1
3.13.2
3.13.3
3.14.0
3.14.1
3.15.0
3.16.0
3.17.0
3.17.1
3.18.0
3.19.0
3.20.0
3.21.0
3.22.0
3.23.0
3.24.0
3.24.1
3.25.0
3.25.1
3.26.0
3.26.1
3.26.2
3.26.3
3.27.0
3.27.1
3.28.0
3.29.0
3.30.0
3.30.1
3.30.2
3.30.3
3.30.4
3.30.5
3.30.6
3.30.7
3.30.8
3.30.9
3.30.10
3.30.11
3.30.12
3.30.13
3.30.14

Database specific

source
"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/09/GHSA-r2xf-8xr9-62gw/GHSA-r2xf-8xr9-62gw.json"