Skip to content

fix: ctl:ruleRemoveTargetByTag not removing XML attribute targets - #3592

Merged
airween merged 2 commits into
owasp-modsecurity:v2/masterfrom
fzipi:v2/fix-3591-xml-attr-target-removal
Jul 2, 2026
Merged

fix: ctl:ruleRemoveTargetByTag not removing XML attribute targets#3592
airween merged 2 commits into
owasp-modsecurity:v2/masterfrom
fzipi:v2/fix-3591-xml-attr-target-removal

Conversation

@fzipi

@fzipi fzipi commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • fetch_target_exception() only read a target's parameter from a :-suffix embedded in var->name, which is how most variables (ARGS, TX, REQUEST_HEADERS, ...) represent their parameter.
  • XML variables keep the XPath expression in the separate var->param field instead, so their parameter was never compared, and ctl:ruleRemoveTargetBy* could never match an XPath target like XML://@*.
  • Falls back to var->param when var->name has no embedded parameter, so target-exception matching also works for XML XPath targets.

Fixes #3591

Test plan

  • Added a regression test in tests/regression/rule/10-xml.t covering: (1) baseline match of XML://@* against an XML attribute value, and (2) ctl:ruleRemoveTargetByTag correctly suppressing that match once the target is removed.
  • Verified the change compiles (gcc -fsyntax-only) with no new warnings.
  • Verified the test file parses correctly as Perl and the new qr///qq() escaping renders the expected literal strings.

@airween airween added the 2.x Related to ModSecurity version 2.x label Jul 1, 2026
fetch_target_exception() only derived a target's parameter from a
":"-suffix embedded in var->name, which is how most variables (ARGS,
TX, REQUEST_HEADERS, ...) represent their parameter. XML variables
keep the XPath expression in the separate var->param field instead,
so their parameter was never compared, and ctl:ruleRemoveTargetBy*
could never match an XPath target like XML://@*.

Fall back to var->param when var->name has no embedded parameter, so
target-exception matching also works for XML XPath targets.

Fixes owasp-modsecurity#3591

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@fzipi
fzipi force-pushed the v2/fix-3591-xml-attr-target-removal branch from bfd5a6e to 091ba17 Compare July 1, 2026 21:19
@airween
airween requested a review from Copilot July 2, 2026 07:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes target-exception matching for XML XPath targets by teaching fetch_target_exception() to use var->param when the variable name doesn’t embed a :param suffix, enabling ctl:ruleRemoveTargetBy* to correctly remove targets like XML://@* during a transaction.

Changes:

  • Update fetch_target_exception() to fall back to var->param for parameter comparison when var->name has no embedded parameter.
  • Add a regression test proving ctl:ruleRemoveTargetByTag can suppress matches on XML://@* attribute-value inspection.

Reviewed changes

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

File Description
apache2/re.c Uses var->param as the parameter source when var->name lacks an embedded :param, allowing XPath targets to be matched/removed.
tests/regression/rule/10-xml.t Adds baseline + regression coverage for removing XML://@* via ctl:ruleRemoveTargetByTag.

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

Comment thread apache2/re.c
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

@airween
airween requested a review from theseion July 2, 2026 11:23
@airween
airween merged commit 16cbd50 into owasp-modsecurity:v2/master Jul 2, 2026
92 checks passed
@fzipi
fzipi deleted the v2/fix-3591-xml-attr-target-removal branch July 2, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.x Related to ModSecurity version 2.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants