Skip to content

fix(rules): widen CORS regex for framework patterns and fix negation filter edge cases - #491

Merged
ajianaz merged 1 commit into
developfrom
fix/cors-overcorrection-488-489
Aug 4, 2026
Merged

fix(rules): widen CORS regex for framework patterns and fix negation filter edge cases#491
ajianaz merged 1 commit into
developfrom
fix/cors-overcorrection-488-489

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

What

Rewrites the CORS wildcard regex to cover 10 framework-specific patterns that were missed after PR #484, and fixes three edge cases in the negation filter and env-var suppression that caused false negatives.

Why

PR #484 narrowed the CORS regex to fix false positives (#483), but the narrowing was too aggressive: 13 of 14 common framework-specific CORS wildcard patterns were no longer detected. The negation filter also suppressed real findings on mixed comment/code lines, and the cors_config suppression caught bare assignments instead of only env-var reads. Additionally, is_doc_file() treated extensionless filenames like org or tex as documentation.

Closes #488, closes #489.

How

security_scanner.rs:

  • Rewrote CORS regex using (?ix) extended mode with 10 alternatives covering HTTP headers, generic assignments, Django, Spring Boot, .NET, tower-http, Express, FastAPI, nginx, and actix-web
  • Removed unsupported lookahead (?!\w) (Rust regex crate limitation) — replaced with explicit trailing delimiters
  • Fixed is_doc_file() to check for dot before extracting extension

builtin.rs:

  • Negation filter now skips suppression when comment body contains code indicators (=, fn , let , const )
  • cors_config suppression scoped to env::var()/getenv()/os.environ read patterns only
  • Pre-compiled negation regexes with LazyLock<Vec<Regex>>

Testing

  • cargo test --features tree-sitter passes — 836 tests, 0 failures (15 new tests added)
  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets --features tree-sitter -- -D warnings passes
  • cargo build --release --features tree-sitter passes
  • Manual smoke-test: verified regex against 12 framework patterns and 3 false-positive cases in isolation before integrating

New test coverage:

  • 8 framework pattern tests (nginx, Django, Spring, .NET, tower-http, Express, FastAPI, actix)
  • 3 negation/env-var edge case tests (mixed comment+code, bare assignment, env var read)
  • 1 is_doc_file extensionless file test

Related Issues

Closes #488, closes #489

Checklist

@ajianaz ajianaz changed the title fix: CORS scanner over-correction — widen regex + fix negation/env filters fix: CORS scanner misses framework-specific wildcard patterns and negation filter edge cases Aug 4, 2026
@ajianaz ajianaz added bug Something isn't working scope:core Core review engine labels Aug 4, 2026
@ajianaz
ajianaz force-pushed the fix/cors-overcorrection-488-489 branch from eacea8b to 6460809 Compare August 4, 2026 15:49
@ajianaz ajianaz changed the title fix: CORS scanner misses framework-specific wildcard patterns and negation filter edge cases fix(rules): widen CORS regex for framework patterns and fix negation filter edge cases Aug 4, 2026
…filter edge cases (#488, #489)

Rewrote CORS regex with 10 framework pattern alternatives using (?ix)
extended mode: HTTP header, generic assignment, Django, Spring Boot,
.NET, tower-http, Express, FastAPI, nginx, actix-web.

Also fixes:
- Removed unsupported lookahead (?!\w) — Rust regex crate limitation
- Negation filter skips suppression when comment has code indicators
- cors_config suppression scoped to env::var() reads only
- Pre-compiled negation regexes with LazyLock
- is_doc_file() checks for dot before extracting extension

Tests: 836 pass, 0 fail, 0 clippy warnings, fmt clean.
Closes #488, closes #489.
@ajianaz
ajianaz force-pushed the fix/cors-overcorrection-488-489 branch from 6460809 to 0ff0ead Compare August 4, 2026 15:52
@ajianaz
ajianaz merged commit e69834e into develop Aug 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working scope:core Core review engine

Projects

None yet

1 participant