Skip to content

Commit 405fbfc

Browse files
committed
fix(security): regex-audit missing inline-literal detection for .ts/.tsx/.jsx/.mjs/.cjs
Only .js had the 'regex_literal_inline' pattern (bare /pattern/flags used directly as a call argument, e.g. .replace(/[-:T]/g, '')). Every other JS family extension — .mjs, .cjs, .ts, .tsx, .jsx — was missing it, so any inline (non-variable-assigned) regex literal in TypeScript/JSX went completely undetected. Found via real-codebase validation (Coretax-Auto-Downloader KDS backend, all .ts): regex-audit reported total_patterns:0 despite genuine inline regex literals (.replace(/[-:T]/g, ''), .replace(/\s+/g, '.')) confirmed present via grep. Fix: add the same inline-literal pattern already used for .js to the other 4 extensions. Verified: total_patterns went from 0 to 1735, vulnerable stayed 0 (no ReDoS-prone patterns in this codebase) — the inline pattern is inherently noisy for raw counting (same tradeoff .js already accepted), but doesn't affect the vulnerability-flagging logic.
1 parent e82440d commit 405fbfc

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

scripts/regexaudit_engine.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,37 @@
7979
(r'new\s+RegExp\s*\(\s*("([^"]*)"|\'([^\']*)\')', "regexp_constructor"),
8080
(r'/([^/\n]+)/[gimsuy]*', "regex_literal_inline"),
8181
],
82+
# Bug fix: only .js had "regex_literal_inline" (bare /pattern/flags used
83+
# directly as a call argument, e.g. `.replace(/[-:T]/g, '')`) — .mjs/.cjs/
84+
# .ts/.tsx/.jsx were missing it, so any inline (non-variable-assigned)
85+
# regex literal in TypeScript/JSX went completely undetected. Found via
86+
# real-codebase validation (Coretax-Auto-Downloader KDS backend, all .ts):
87+
# regex-audit reported total_patterns:0 despite genuine inline regex
88+
# literals like `.replace(/[-:T]/g, '')` and `.replace(/\s+/g, '.')`.
8289
".mjs": [
8390
(r'(?:const|let|var)\s+\w+\s*=\s*(/[^/\n]+/[gimsuy]*)', "regex_literal"),
8491
(r'new\s+RegExp\s*\(\s*("([^"]*)"|\'([^\']*)\')', "regexp_constructor"),
92+
(r'/([^/\n]+)/[gimsuy]*', "regex_literal_inline"),
8593
],
8694
".cjs": [
8795
(r'(?:const|let|var)\s+\w+\s*=\s*(/[^/\n]+/[gimsuy]*)', "regex_literal"),
8896
(r'new\s+RegExp\s*\(\s*("([^"]*)"|\'([^\']*)\')', "regexp_constructor"),
97+
(r'/([^/\n]+)/[gimsuy]*', "regex_literal_inline"),
8998
],
9099
".ts": [
91100
(r'(?:const|let|var)\s+\w+\s*(?::\s*\w+(?:<[^>]+>)?)?\s*=\s*(/[^/\n]+/[gimsuy]*)', "regex_literal"),
92101
(r'new\s+RegExp\s*\(\s*("([^"]*)"|\'([^\']*)\')', "regexp_constructor"),
102+
(r'/([^/\n]+)/[gimsuy]*', "regex_literal_inline"),
93103
],
94104
".tsx": [
95105
(r'(?:const|let|var)\s+\w+\s*(?::\s*\w+(?:<[^>]+>)?)?\s*=\s*(/[^/\n]+/[gimsuy]*)', "regex_literal"),
96106
(r'new\s+RegExp\s*\(\s*("([^"]*)"|\'([^\']*)\')', "regexp_constructor"),
107+
(r'/([^/\n]+)/[gimsuy]*', "regex_literal_inline"),
97108
],
98109
".jsx": [
99110
(r'(?:const|let|var)\s+\w+\s*=\s*(/[^/\n]+/[gimsuy]*)', "regex_literal"),
100111
(r'new\s+RegExp\s*\(\s*("([^"]*)"|\'([^\']*)\')', "regexp_constructor"),
112+
(r'/([^/\n]+)/[gimsuy]*', "regex_literal_inline"),
101113
],
102114
".py": [
103115
(r're\.compile\s*\(\s*(?:r)?["\']([^"\']+)["\']', "re_compile"),

0 commit comments

Comments
 (0)