Skip to content

Refactor AST traversal for improved performance and accuracy - #12

Merged
akanthed merged 2 commits into
mainfrom
add-python-ast
Aug 5, 2026
Merged

Refactor AST traversal for improved performance and accuracy#12
akanthed merged 2 commits into
mainfrom
add-python-ast

Conversation

@akanthed

@akanthed akanthed commented Aug 5, 2026

Copy link
Copy Markdown
Owner
  • Introduced a file indexing mechanism to reduce redundant AST walks across multiple rules, significantly improving scan performance.
  • Replaced direct descendant traversal with indexed methods for retrieving call expressions and function nodes.
  • Updated various rules to utilize the new indexing functions, ensuring consistent behavior and performance gains.
  • Added tests to validate the correctness of the new indexing methods against traditional traversal methods.
  • Introduced new test fixtures to cover edge cases and ensure robustness of the scanning process.
  • Enhanced Python AST parsing to correctly identify and handle calls, attributes, and other constructs, improving vulnerability detection.

What and why

Detection logic changes (delete this section if not applicable)

  • npm run regression was run and every proven/likely finding it printed was reviewed against its source line
  • A new/updated rule has fixtures in both test-fixtures/vulnerable/ and test-fixtures/safe/
  • src/scanner/catalog.ts and src/scanner/explainer.ts both have an entry for any new rule ID
  • test/corpus.test.js's EXPECTED_VULNERABLE was updated for any new rule

CLI changes (delete this section if not applicable)

  • test/cli.test.js has a new or updated case exercising the built binary (src/cli.ts changes aren't covered by any other test file)

Checklist

  • npm run build && npm test passes
  • Before/after behavior is described above, with a concrete example if the change affects scan output

- Introduced a file indexing mechanism to reduce redundant AST walks across multiple rules, significantly improving scan performance.
- Replaced direct descendant traversal with indexed methods for retrieving call expressions and function nodes.
- Updated various rules to utilize the new indexing functions, ensuring consistent behavior and performance gains.
- Added tests to validate the correctness of the new indexing methods against traditional traversal methods.
- Introduced new test fixtures to cover edge cases and ensure robustness of the scanning process.
- Enhanced Python AST parsing to correctly identify and handle calls, attributes, and other constructs, improving vulnerability detection.
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

…t process, and revise documentation for improved clarity and accuracy
@akanthed
akanthed merged commit 2f57689 into main Aug 5, 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.

2 participants