Skip to content

Conversation

@fzipi
Copy link
Member

@fzipi fzipi commented Nov 25, 2025

what

  • add check for TX.N usage without capture

why

  • well, the above

refs

Fixes #69.

@fzipi
Copy link
Member Author

fzipi commented Jan 2, 2026

Now that we fixed this upstream, can you take a look @airween ?

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 linter check to detect usage of TX.N (captured transaction variables TX:0 through TX:9) without a corresponding capture action in ModSecurity rules. The check extends beyond the existing functionality that only checked TX.N as rule targets to also detect TX.N in action arguments (msg, logdata, setvar, tag) and operator arguments.

Key changes:

  • Enhanced the capture check to detect TX.N references in variable expansions like %{TX.1} in addition to target references like TX:1
  • Added comprehensive test coverage for different TX.N usage scenarios
  • Fixed a bug in variables_usage.py where re.I was incorrectly passed as a positional argument to re.sub()

Reviewed changes

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

Show a summary per file
File Description
src/crs_linter/rules/check_capture.py Enhanced capture check to detect TX.N in expansions (%{TX.N}), operator arguments, and action arguments (msg, logdata, setvar, tag)
tests/test_check_capture.py Added comprehensive test suite with 13 test cases covering various TX.N usage scenarios including valid and invalid cases
README.md Updated documentation to reflect the expanded scope of the capture check with examples
src/crs_linter/rules/variables_usage.py Fixed incorrect regex flag usage by using flags= keyword argument
.github/workflows/test.yml Updated CRS version from 4.18.0 to 4.21.0 for testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI commented Jan 6, 2026

@fzipi I've opened a new pull request, #99, to work on those changes. Once the pull request is ready, I'll request review from you.

@fzipi
Copy link
Member Author

fzipi commented Jan 6, 2026

Ugh, last change broke it.

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

@fzipi
Copy link
Member Author

fzipi commented Jan 14, 2026

@copilot Your previous suggestion broke the tests. Take a look at: https://github.com/coreruleset/crs-linter/actions/runs/20751085465/job/59580380141?pr=87

Copy link
Contributor

Copilot AI commented Jan 14, 2026

@fzipi I've opened a new pull request, #108, to work on those changes. Once the pull request is ready, I'll request review from you.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

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

@fzipi fzipi force-pushed the feat/check-capture-tx branch from ce38235 to 08deeec Compare January 24, 2026 17:47
fzipi and others added 10 commits January 25, 2026 22:34
Add test case that covers scenario where TX.N appears both as a target
variable and in an expansion (e.g., in msg or logdata) within same rule.
This test would have caught the bug where use_captured_var_in_expansion
was not set correctly when use_captured_var was already True.

Also fix the bug by moving use_captured_var_in_expansion assignment
outside the guard condition, following the same pattern as c598d31.

Co-authored-by: fzipi <[email protected]>
Signed-off-by: Felipe Zipitria <[email protected]>
@fzipi fzipi force-pushed the feat/check-capture-tx branch from 08deeec to 03214f6 Compare January 26, 2026 01:34
@fzipi fzipi requested a review from airween January 26, 2026 01:39
@fzipi fzipi merged commit 8f9e541 into main Jan 26, 2026
4 checks passed
@fzipi fzipi deleted the feat/check-capture-tx branch January 26, 2026 20:37
fzipi added a commit that referenced this pull request Jan 27, 2026
feat: add check for TX.N usage without capture
Signed-off-by: Felipe Zipitria <[email protected]>
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.

Addition of check for existence of capture action

3 participants