fix: anchor exclusion regex patterns (empty CPG on jssrc2cpg); bump Joern to v4.0.581#24
Merged
Merged
Conversation
The default `cpg.exclusion_patterns` assumed `--exclude-regex` is full-matched against the path. That holds for the JVM frontends (c2cpg, javasrc2cpg, pysrc2cpg — Scala `Regex.matches` against the RELATIVE path) but not for astgen frontends like jssrc2cpg, which run plain `RegExp.test()` — an UNANCHORED substring search — against the file's ABSOLUTE path. Under substring search a bare token such as `\..*` degenerates into "any path containing a `.`", so `index.js` (and effectively every real source file) was silently excluded, producing a completely empty CPG that load-verification then flagged as broken. Anchor every token with a leading `(?:^|.*/)` boundary (start-of-string OR a literal `/`) and collapse the old `.*/X` + bare-`X` pairs into one entry each. This matches a whole path component under both regimes, is a no-op for the JVM frontends, and additionally fixes a pre-existing gap where root-level dirs (e.g. `vendor/`, `tmp/`) weren't matched because the bare `.*/` prefix required a leading path segment. Also aligns config.example.yaml's `doc?` -> `docs?` with src/defaults.py. Bump JOERN_VERSION 4.0.555 -> 4.0.581. Fixes #23 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #23. The default
cpg.exclusion_patternswere written assuming--exclude-regexis full-matched against a path. That holds for the JVM-native frontends (c2cpg,javasrc2cpg,pysrc2cpg— ScalaRegex.matchesagainst the relative path) but not for astgen frontends likejssrc2cpg, which apply the same string via plainRegExp.test()— an unanchored substring search — against the file's absolute path.Under substring search a bare token such as
\..*degenerates into "any path containing a.", soindex.js(and effectively every real source file) was silently excluded, yielding a completely empty CPG that codebadger's own load-verification then flagged as broken (0 user-defined methods).Fix
Anchor every token with a leading
(?:^|.*/)boundary (start-of-string or a literal/), collapsing the old.*/X+ bare-Xpairs into one entry each:This matches a whole path component under both regimes. It is a no-op for the JVM frontends and additionally closes a pre-existing gap where root-level dirs (e.g.
vendor/,tmp/,docs/) weren't matched because the bare.*/prefix required a leading path segment.Applied to both sources of the defaults:
src/defaults.py(EXCLUSION_PATTERNS) andconfig.example.yaml(cpg.exclusion_patterns). Also alignedconfig.example.yaml'sdoc?→docs?withsrc/defaults.py.The consumers (
cpg_generator._escape_regex_pattern,core_tools) only validate that each pattern compiles and pass it through joined with|;(?:^|.*/)is valid regex, so it is preserved intact.Also
JOERN_VERSION4.0.555→4.0.581inDockerfile(image rebuilt).Verification
Simulated both regimes (JVM
fullmatchon relative paths, astgensearchon absolute paths):index.js,src/math.js,latest.js,attestation.go,main.c,README_index.js.git/,test/,src/test/,node_modules/,vendor/,spec.js,docs/,build/out/,tmp/Existing
tests/test_cpg_generator.py(13 tests) still pass.🤖 Generated with Claude Code