Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

fix(core): resolve CORS regex logic bug and implement value-based regex testing

Open jess-tech-lab opened this issue 8 months ago • 4 comments

Proposed change

This PR fixes a logic bug in the CORS reflection module and upgrades the testing infrastructure to prevent "silent failures" in YAML modules.

  1. Security Module Fix (nettacker/modules/vuln/http_cors.yaml)
  • Removed a trailing space in the Access-Control-Allow-Origin regex to ensure the module correctly identifies vulnerabilities when the origin is reflected.
  1. Testing Suite Enhancement (tests/test_yaml_regexes.py)
  • Improved the test suite to validate regex patterns against actual header value with reflection header mapping - added logic to extract the Origin from the request fuzzer and verify the response regex against it.

Closes #1374

Type of change

  • [ ] New core framework functionality
  • [x] Bugfix (non-breaking change which fixes an issue)
  • [ ] Code refactoring without any functionality changes
  • [ ] New or existing module/payload change
  • [ ] Documentation/localization improvement
  • [ ] Test coverage improvement
  • [ ] Dependency upgrade
  • [ ] Other improvement (best practice, cleanup, optimization, etc)

Checklist

  • [x] I've followed the contributing guidelines
  • [x] I have digitally signed all my commits in this PR
  • [x] I've run make pre-commit and confirm it didn't generate any warnings/changes
  • [x] I've run make test, I confirm all tests passed locally
  • [ ] I've added/updated any relevant documentation in the docs/ folder
  • [x] I've linked this PR with an open issue
  • [x] I've tested and verified that my code works as intended and resolves the issue as described
  • [ ] I have attached screenshots demonstrating my code works as intended
  • [x] I've checked all other open PRs to avoid submitting duplicate work
  • [x] I confirm that the code and comments in this PR are not direct unreviewed outputs of AI
  • [x] I confirm that I am the Sole Responsible Author for every line of code, comment, and design decision

jess-tech-lab avatar Mar 08 '26 22:03 jess-tech-lab

Summary by CodeRabbit

  • Bug Fixes

    • Improved CORS vulnerability detection to avoid false positives by tightening header-matching behavior.
  • Tests

    • Strengthened test validations for response-header patterns, including checks that response rules align with corresponding request header values.

Walkthrough

Removed a trailing space from the Access-Control-Allow-Origin regex in http_cors.yaml and extended test logic to validate response-header regexes against resolved expected request header values.

Changes

Cohort / File(s) Summary
HTTP CORS Regex Fix
nettacker/modules/vuln/http_cors.yaml
Fixed the origin reflected payload regex by removing a trailing space in the Access-Control-Allow-Origin pattern (`"(http
Header-aware regex tests
tests/test_yaml_schema_and_regex.py
Added REFLECTED_HEADERS mapping and resolve_input_format(); changed regex helpers to return (regex, expected_header_value) tuples; extended is_valid_regex() to optionally check that a regex matches a provided header value; updated test loop and failure messages accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • arkid15r
  • securestep9
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately captures the main changes: fixing a CORS regex bug and implementing value-based regex testing.
Description check ✅ Passed The PR description clearly explains both the security module fix and testing suite enhancement, directly addressing the bug and improvements.
Linked Issues check ✅ Passed The PR fully addresses both objectives from issue #1374: removing the trailing space from the CORS regex and enhancing test suite validation.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the linked issue: only the CORS regex fix and test suite enhancements are included.
Docstring Coverage ✅ Passed Docstring coverage is 93.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Mar 08 '26 22:03 coderabbitai[bot]

Hi @securestep9 and @arkid15r, I've rebased this branch against the latest changes to resolve conflicts with PR #1319. Please review when you have a chance. Thanks.

jess-tech-lab avatar Mar 26 '26 22:03 jess-tech-lab

@arkid15r and @securestep9 - can you review? Thanks.

jess-tech-lab avatar May 08 '26 14:05 jess-tech-lab

@securestep9 - please review when you have a chance. Thanks.

jess-tech-lab avatar Jun 07 '26 19:06 jess-tech-lab