一键导入
redos
Detect Regular Expression Denial of Service (ReDoS) where crafted input causes catastrophic backtracking in regex patterns applied to user-controlled strings.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Detect Regular Expression Denial of Service (ReDoS) where crafted input causes catastrophic backtracking in regex patterns applied to user-controlled strings.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Generate polished, human-sounding vulnerability disclosure reports for GHSA, HackerOne, and email. Auto-selects channel, calculates CVSS, and adapts tone.
Mine GitHub Security Advisories and CVE databases for incomplete fixes, finding variant vulnerabilities in patched code or similar patterns in related packages.
Detect authentication and authorization bypass vulnerabilities including missing auth middleware, JWT algorithm confusion, IDOR, and session fixation.
Detect code injection vulnerabilities in packages that dynamically generate or evaluate code via new Function(), eval(), vm.run*, or template literal interpolation.
Detect OS command injection via shell execution sinks where user-controlled input reaches system commands without proper sanitization.
Cross-pollination multiplier technique: find a vulnerability in one package, then search for the same pattern across all similar packages to multiply findings.
| name | redos |
| description | Detect Regular Expression Denial of Service (ReDoS) where crafted input causes catastrophic backtracking in regex patterns applied to user-controlled strings. |
| metadata | {"filePattern":["**/*.js","**/*.ts","**/*.py","**/*.rb","**/*.php","**/*.java"],"bashPattern":["grep.*(RegExp|regex|pattern|match)","semgrep.*redos"],"priority":70} |
Audit input validation libraries, URL/email/date parsers, sanitization utilities, template engines, and any package that applies regular expressions to user-controlled strings.
MUST measure actual backtracking growth rate. Do not report based on pattern structure alone. The validator.js lesson: assumed ReDoS from pattern complexity but could not confirm exponential growth. Always TIME IT.
(a+)+$ # Nested plus -- classic ReDoS
(a*)*$ # Nested star
(a+)*$ # Star of plus
(a*)+$ # Plus of star
(a{1,}){1,}$ # Nested bounded quantifiers
(a|a)+$ # Identical alternatives
(a|ab)+$ # Prefix overlap
(a|b|ab)+$ # Partial overlap
(\w|\d)+$ # \d is subset of \w -- overlap
(a+b?)+$ # Optional between repeated groups
(\s*,\s*)+$ # Common in CSV/list parsing
([^"]*"[^"]*")*[^"]*$ # Quote matching
^([a-zA-Z0-9])(([\-.]|[_]+)?([a-zA-Z0-9]+))*$ # Email local part
^((https?|ftp):\/\/)?([\w.-]+)\.([a-z.]{2,6}).*$ # URL validation
^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$ # IP (safe but often combined)
| Pattern | Evil String | Growth |
|---|---|---|
(a+)+$ | "a" * N + "!" | O(2^N) |
(a+b?)+$ | "a" * N + "!" | O(2^N) |
(a|aa)+$ | "a" * N + "!" | O(2^N) |
([a-zA-Z]+)*$ | "a" * N + "1" | O(2^N) |
(\s+$) | " " * N + "x" | O(N^2) quadratic |
(.*a){10}$ | "a" * N + "!" | O(N^10) polynomial |
Key insight: The evil string is N copies of a character the pattern CAN match, followed by one character it CANNOT. This forces the engine to try every possible split of the N characters across the quantifiers.
# JavaScript/TypeScript
grep -rn "new RegExp\|RegExp(" . --include="*.js" --include="*.ts"
grep -rn "\.match(\|\.test(\|\.replace(\|\.search(\|\.split(" . --include="*.js" --include="*.ts"
grep -rn "/[^/]*[+*][^/]*[+*][^/]*/" . --include="*.js" --include="*.ts"
# Python
grep -rn "re\.compile\|re\.match\|re\.search\|re\.findall\|re\.sub" . --include="*.py"
grep -rn "re\.DOTALL\|re\.MULTILINE\|re\.VERBOSE" . --include="*.py"
# Ruby
grep -rn "Regexp\.new\|=~\|\.match\|\.scan\|\.gsub" . --include="*.rb"
# PHP
grep -rn "preg_match\|preg_replace\|preg_split" . --include="*.php"
# Java
grep -rn "Pattern\.compile\|\.matches(\|\.replaceAll(" . --include="*.java"
Look for these red flags:
(X+)+, (X*)*, (X+)*, (X*)+(a|a)+, (a|ab)+(\s*,\s*)+$ and input doesn't matchnew RegExp(userInput) -- always exploitable// Node.js timing test -- REQUIRED before reporting
const regex = /VULNERABLE_PATTERN/;
console.log('Length | Time (ms) | Ratio');
let prevTime = 0;
for (let len = 15; len <= 35; len++) {
const evil = 'a'.repeat(len) + '!';
const start = performance.now();
regex.test(evil);
const elapsed = performance.now() - start;
const ratio = prevTime > 0 ? (elapsed / prevTime).toFixed(1) : '-';
console.log(`${String(len).padStart(6)} | ${elapsed.toFixed(2).padStart(9)} | ${ratio}`);
prevTime = elapsed;
}
Interpretation:
| Growth Rate | Ratio Pattern | Input for 1s Hang | Severity |
|---|---|---|---|
| O(2^N) exponential | ~2x per char | 25-30 chars | HIGH 7.5 |
| O(N^3+) polynomial | grows with input | 10K-100K chars | MEDIUM 5.3-6.5 |
| O(N^2) quadratic | grows slowly | 100K+ chars | LOW-MEDIUM |
| O(N) linear | constant ratio | never | NOT ReDoS |
The regex MUST be applied to user-controlled input. Check the full call chain:
String.prototype.matchAll() is lazy but still backtracks.re module uses backtracking. No built-in timeout.re2 package (Google RE2 bindings) is safe but rarely used.Regexp.timeout= global setting -- check if configured.Regexp.timeout defaults to nil (no timeout) unless explicitly set.pcre.backtrack_limit defaults to 1,000,000 -- provides some protection.ini_get('pcre.backtrack_limit') -- if lowered, may limit impact.Pattern.compile().Thread.interrupt() but rarely done.new RegExp(input)): HIGH 7.5 (always exploitable)