Skip to content

fix(scan): stop reading C pointer casts as ReDoS - #141

Merged
ralyodio merged 1 commit into
masterfrom
fix/redos-rule-language-scope
Aug 14, 2026
Merged

fix(scan): stop reading C pointer casts as ReDoS#141
ralyodio merged 1 commit into
masterfrom
fix/redos-rule-language-scope

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

redos-nested-quantifier carried no languages, so it ran on every file the
walker handed it. Its pattern looks for (, text, *, ), * — which is
exactly how C spells a cast followed by a dereference.

const pattern = /\([^)\n]*[+*]\s*\)\s*[+*]|\([^)\n]*\{\d+,\}\s*\)\s*[+*{]/;
pattern.test('x = *(char *)*p;');                              // true
pattern.test('sizeof(void *), (void *)*memptr64');             // true

Found while scanning inspektor-gadget:
across 1186 files the rule fired exactly once, on a bpf_probe_read_user call
in an eBPF C program. Not a regex, in a language that has no regex literals.

Scoping is the fix rather than a cleverer pattern — there is nothing in a C
file for this rule to legitimately find, no matter how the pattern is written.
other also covers C++, Rust and Zig, which share the cast-then-deref
spelling.

Verification

  • pnpm test in packages/scan — 253 passed (10 files), including the new case.
  • pnpm typecheck — clean.
  • Rescanned inspektor-gadget with the patched CLI: 45 findings → 44. The only
    delta is redos-nested-quantifier at gadgets/trace_malloc/program.bpf.c:238.
    Nothing else moved.

🤖 Generated with Claude Code

`redos-nested-quantifier` carried no `languages`, so it ran on every file
the walker handed it. Its pattern looks for `(`, text, `*`, `)`, `*` — which
is exactly how C spells a cast followed by a dereference. `*(char *)*p` is a
nested quantifier as far as the rule is concerned.

Found by scanning inspektor-gadget: across 1186 files the rule fired once,
on a `bpf_probe_read_user` call in an eBPF C program. Not a regex, in a
language that has no regex literals.

Scoped to the languages where a regex literal can appear rather than
narrowing the pattern, because no pattern helps here — there is nothing in a
C file for this rule to legitimately find. `other` also covers C++, Rust and
Zig, which share the cast-then-deref spelling.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

ThreatCrush Security Scan

69 finding(s)

HIGH/CRITICAL: 12 | MEDIUM: 56 | LOW: 1

Severity Rule Location
HIGH secret-aws-access-key prd/0003-detect-hardcoded-secrets-before-they-are-committed-or-served.md:126
HIGH sh-eval-expansion .githooks/pre-commit:26
HIGH js-electron-node-integration apps/desktop/src/main/index.ts:22
HIGH sh-remote-script-execution apps/web/public/install.sh:272
HIGH sh-remote-script-execution apps/web/public/install.sh:320
HIGH secret-generic-credential modules/spend-guard/config/example.conf.toml:13
HIGH secret-generic-credential modules/spend-guard/README.md:84
HIGH secret-generic-credential PRD.md:268
HIGH tls-verification-disabled prd/0004-find-dangerous-code-patterns-without-pretending-to-be-a-compiler.md:121
HIGH tls-verification-disabled prd/0004-find-dangerous-code-patterns-without-pretending-to-be-a-compiler.md:122
HIGH sh-remote-script-execution scripts/smoke-test.sh:46
HIGH sh-remote-script-execution scripts/smoke-test.sh:47
MEDIUM insecure-temp-file .githooks/commit-msg:16
MEDIUM insecure-temp-file .githooks/post-commit:20
MEDIUM js-shell-exec-interpolation apps/cli/src/commands/init.ts:70
MEDIUM js-shell-exec-interpolation apps/cli/src/commands/init.ts:79
MEDIUM js-shell-exec-interpolation apps/cli/src/commands/service.ts:88
MEDIUM js-shell-exec-interpolation apps/cli/src/commands/service.ts:111
MEDIUM sql-template-interpolation apps/cli/src/core/state.ts:121
MEDIUM sql-template-interpolation apps/cli/src/core/state.ts:125
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:31
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:33
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:34
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:35
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:36
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:43
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:49
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:56
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:63
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:82
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:84
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:85
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:93
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:98
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:105
MEDIUM js-shell-exec-interpolation apps/cli/src/daemon/firewall/adapters.ts:112
MEDIUM js-shell-exec-interpolation apps/cli/src/index.ts:425
MEDIUM js-unescaped-html-sink apps/web/src/app/about/page.tsx:180
MEDIUM js-unescaped-html-sink apps/web/src/app/about/page.tsx:184
MEDIUM js-open-redirect apps/web/src/app/auth/login/page.tsx:50
MEDIUM js-unescaped-html-sink apps/web/src/app/blog/[slug]/page.tsx:125
MEDIUM js-unescaped-html-sink apps/web/src/app/blog/[slug]/page.tsx:153
MEDIUM js-unescaped-html-sink apps/web/src/app/blog/[slug]/page.tsx:157
MEDIUM js-unescaped-html-sink apps/web/src/app/get-whitepaper/page.tsx:346
MEDIUM js-unescaped-html-sink apps/web/src/app/layout.tsx:211
MEDIUM js-unescaped-html-sink apps/web/src/app/layout.tsx:215
MEDIUM js-unescaped-html-sink apps/web/src/app/layout.tsx:219
MEDIUM js-unescaped-html-sink apps/web/src/app/page.tsx:120
MEDIUM js-unescaped-html-sink apps/web/src/app/store/[slug]/page.tsx:107
MEDIUM js-open-redirect apps/web/src/components/funding/FundingClient.tsx:97

…and 19 more. Full results in the Security tab.

Snippets are redacted; ThreatCrush never prints matched credential material.

@ralyodio
ralyodio merged commit adbdb93 into master Aug 14, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant