Skip to content

feat: add lint for no negated request_cookies#114

Open
fzipi wants to merge 4 commits intomainfrom
feat/add-lint-rule-negated-cookies
Open

feat: add lint for no negated request_cookies#114
fzipi wants to merge 4 commits intomainfrom
feat/add-lint-rule-negated-cookies

Conversation

@fzipi
Copy link
Member

@fzipi fzipi commented Jan 23, 2026

what

  • detects when SecRule directives use negated !REQUEST_COOKIES targets
  • yields clear error messages instructing users to use SecRuleUpdateTargetById instead
  • handles edge cases like multiple negated cookies, chained rules, and case-insensitive matching
  • only reports once per rule even if multiple negated REQUEST_COOKIES targets exist
  • update documentation

why

  • prevent adding new rules with old pattern

refs

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new linting rule to detect and prevent the use of negated !REQUEST_COOKIES targets in SecRule directives, enforcing a policy change that cookie exclusions should be implemented using SecRuleUpdateTargetById directives in separate post-CRS configuration files instead.

Changes:

  • Implements a new NoNegatedRequestCookies rule that detects negated REQUEST_COOKIES patterns in SecRule directives
  • Adds comprehensive test coverage with 195 lines of tests covering various edge cases
  • Enhances the documentation generator with code block formatting functionality for better rendering of ModSecurity examples

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/crs_linter/rules/no_negated_request_cookies.py New linting rule that checks for !REQUEST_COOKIES targets and yields clear error messages directing users to use SecRuleUpdateTargetById
tests/test_no_negated_request_cookies.py Comprehensive test suite covering valid/invalid patterns, case sensitivity, chained rules, and multiple negated cookies
src/crs_linter/linter.py Imports the new rule module to enable auto-registration
generate_rules_docs.py Adds format_code_blocks() function to properly format ModSecurity code examples in docstrings with markdown triple backticks
README.md Auto-generated documentation updates including the new rule description and improved code block formatting for all examples

airween
airween previously approved these changes Jan 24, 2026
@airween
Copy link
Contributor

airween commented Jan 24, 2026

Looks good to me. Probably we can merge after a new CRS release (current released version does not fit the expected rules).

@fzipi
Copy link
Member Author

fzipi commented Jan 24, 2026

Moved the enhanced documentation generator to #115, as it has nothing to do with the intended changes here.

@fzipi fzipi force-pushed the feat/add-lint-rule-negated-cookies branch 3 times, most recently from 0027130 to da2c220 Compare January 29, 2026 11:43
fzipi added 4 commits February 4, 2026 10:39
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
@fzipi fzipi force-pushed the feat/add-lint-rule-negated-cookies branch from da2c220 to 109c792 Compare February 4, 2026 13:40
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.

Add new linting rule for preventing SecRule directives to remove targets from REQUEST_COOKIES

3 participants