{"id":"GHSA-2v9w-34q6-wpqx","summary":"jline3 leads to ReDoS in Built-in Less Viewer Search","details":"### Summary\n\nThe JLine3 built-in `less` pager compiles user-supplied search patterns directly as\nJava regular expressions with no sanitization, timeout, or backtracking bound. A\nmalicious pattern such as `(a+)+b` can trigger catastrophic backtracking and hang the\nsession thread at 100% CPU. In deployments that expose `less` over Telnet or SSH,\nthis becomes a denial-of-service issue for the affected session and can be used to\nexhaust a bounded session pool.\n\n### Details\n\n`Less.getPattern()` in `builtins/src/main/java/org/jline/builtins/Less.java` compiles\nthe user-controlled search string directly with `Pattern.compile()`:\n\n```java\nprivate Pattern getPattern(boolean doDisplayPattern) {\n    Pattern compiled = null;\n    String _pattern = doDisplayPattern ? displayPattern : pattern;\n    if (_pattern != null) {\n        boolean insensitive =\n                ignoreCaseAlways || ignoreCaseCond && _pattern.toLowerCase().equals(_pattern);\n        compiled = Pattern.compile(\n                \"(\" + _pattern + \")\", insensitive ? Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE : 0);\n    }\n    return compiled;\n}\n```\n\nThe resulting pattern is then applied repeatedly against file content with\n`compiled.matcher(line).find()` in the `less` search path. Because Java's\n`java.util.regex` engine is backtracking-based and has no built-in timeout, patterns\nwith nested quantifiers can take exponential time on non-matching input.\n\nAffected source locations:\n- `builtins/src/main/java/org/jline/builtins/Less.java`\n- `getPattern(boolean doDisplayPattern)`\n- search callers using `compiled.matcher(line).find()`\n\n### PoC\n\n1. Create a file with a long run of `a` characters:\n\n```sh\nprintf 'aaaaaaaaaaaaaaaaaaaaaaaaa\\n' \u003e /tmp/testfile.txt\n```\n\n2. Open the file with the JLine3 `less` viewer.\n3. Press `/` to enter search mode.\n4. Enter the pattern `(a+)+b` and press Enter.\n\nExpected result:\n- The `less` session stops responding.\n- The session thread consumes high CPU.\n\nVariation:\n- The same behavior can be triggered through the display-filter path using `&` because\n  that path also compiles user input as a raw Java regex.\n\nReproduction environment:\n- JLine3 on x86_64 Linux\n- OpenJDK 25.0.2\n\n### Impact\n\nThis is a denial-of-service vulnerability caused by catastrophic regex backtracking.\nAny application embedding `org.jline:jline-builtins` and exposing the `less` viewer\nis impacted. In local use, the affected user can hang their own session. In multi-user\nTelnet or SSH deployments, one attacker can occupy one session thread indefinitely and\nmultiple attackers or sessions can exhaust the server's available worker pool.\n\n### Suggested Fix\n\nThe preferred fix for the current git head is to move user-controlled regex matching\nto a linear-time engine such as RE2/J.\n\nSuggested patch:\n\n```diff\ndiff --git a/builtins/pom.xml b/builtins/pom.xml\n--- a/builtins/pom.xml\n+++ b/builtins/pom.xml\n@@\n         \u003cdependency\u003e\n+            \u003cgroupId\u003ecom.google.re2j\u003c/groupId\u003e\n+            \u003cartifactId\u003ere2j\u003c/artifactId\u003e\n+            \u003cversion\u003e1.8\u003c/version\u003e\n+        \u003c/dependency\u003e\n+        \u003cdependency\u003e\n             \u003cgroupId\u003eorg.jline\u003c/groupId\u003e\n             \u003cartifactId\u003ejline-reader\u003c/artifactId\u003e\n         \u003c/dependency\u003e\n\ndiff --git a/builtins/src/main/java/org/jline/builtins/Less.java b/builtins/src/main/java/org/jline/builtins/Less.java\n--- a/builtins/src/main/java/org/jline/builtins/Less.java\n+++ b/builtins/src/main/java/org/jline/builtins/Less.java\n@@\n-import java.util.regex.Pattern;\n+import com.google.re2j.Pattern;\n@@\n         if (_pattern != null) {\n             boolean insensitive =\n                     ignoreCaseAlways || ignoreCaseCond && _pattern.toLowerCase().equals(_pattern);\n             compiled = Pattern.compile(\n                     \"(\" + _pattern + \")\",\n                     insensitive ? Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE : 0);\n         }\n```\n\nIf introducing RE2/J is not acceptable, a weaker fallback is to perform regex matching\nin a worker with a strict timeout and reject patterns that exceed the time budget.\n\n### Credits\n\nThis issue was identified by Michał Majchrowicz and Marcin Wyczechowski, members of the AFINE Team.","aliases":["CVE-2026-77423"],"modified":"2026-11-23T21:15:06.209824297Z","published":"2026-11-23T21:02:03Z","database_specific":{"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2026-11-23T21:02:03Z","nvd_published_at":"2026-09-23T19:19:16Z","cwe_ids":["CWE-1333"]},"references":[{"type":"WEB","url":"https://github.com/jline/jline3/security/advisories/GHSA-2v9w-34q6-wpqx"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-77423"},{"type":"WEB","url":"https://github.com/jline/jline3/pull/2012"},{"type":"WEB","url":"https://github.com/jline/jline3/pull/2018"},{"type":"WEB","url":"https://github.com/jline/jline3/commit/1d5fc3099e77938b971e197211cad2d4fbb17541"},{"type":"WEB","url":"https://github.com/jline/jline3/commit/341ee69ccc57b7733c1b40d6993219b64b3206ae"},{"type":"PACKAGE","url":"https://github.com/jline/jline3"},{"type":"WEB","url":"https://github.com/jline/jline3/releases/tag/4.3.1"},{"type":"WEB","url":"https://github.com/jline/jline3/releases/tag/jline-3.30.15"}],"affected":[{"package":{"name":"org.jline:jline-builtins","ecosystem":"Maven","purl":"pkg:maven/org.jline/jline-builtins"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"3.30.15"}]}],"versions":["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.2.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.3.0","3.3.1","3.30.0","3.30.1","3.30.10","3.30.11","3.30.12","3.30.13","3.30.14","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.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"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/11/GHSA-2v9w-34q6-wpqx/GHSA-2v9w-34q6-wpqx.json"}},{"package":{"name":"org.jline:jline-builtins","ecosystem":"Maven","purl":"pkg:maven/org.jline/jline-builtins"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"4.0.0"},{"fixed":"4.3.1"}]}],"versions":["4.0.0","4.0.10","4.0.11","4.0.12","4.0.13","4.0.14","4.0.15","4.0.16","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.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/11/GHSA-2v9w-34q6-wpqx/GHSA-2v9w-34q6-wpqx.json"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"}]}