Skip to content

Allow \ in setvar#3519

Open
JonathanBerrew wants to merge 1 commit intoowasp-modsecurity:v2/masterfrom
JonathanBerrew:Allow-backslash-in-setvar
Open

Allow \ in setvar#3519
JonathanBerrew wants to merge 1 commit intoowasp-modsecurity:v2/masterfrom
JonathanBerrew:Allow-backslash-in-setvar

Conversation

@JonathanBerrew
Copy link

This is a Marc Stern modification, I don't have much more insight on the code he made. To be reviewed with caution and check if this is still relevant

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
E Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@airween
Copy link
Member

airween commented Mar 18, 2026

Hi @JonathanBerrew,

it would be nice to explain the reason with an example, why it is necessary and in which case is it useful to allow \ in setvar action.

@JonathanBerrew
Copy link
Author

Sadly I don't know why Marc made those modifications, I wasn't working on the project at the time. If this seem unnecessary, you can close the PR

@airween
Copy link
Member

airween commented Mar 19, 2026

Sadly I don't know why Marc made those modifications, I wasn't working on the project at the time. If this seem unnecessary, you can close the PR

I see. I don't want to close this PR without any reason. If Marc made this modification, that means it's possible useful, but I would like to understand it. Beside of that, we need to documentation the behavior, and give examples to users, so this is why it would be good.

@fzipi
Copy link
Collaborator

fzipi commented Mar 19, 2026

No tests, and no use cases. 🤷 I'll close.

@JonathanBerrew
Copy link
Author

This could be useful to have a setvar with a windows path for example or any regex. This keep the previous behaviour that was working for the escaping of the single quote

@airween
Copy link
Member

airween commented Mar 23, 2026

This could be useful to have a setvar with a windows path for example or any regex. This keep the previous behaviour that was working for the escaping of the single quote

Thanks for this explanation. Anyway, it could be very good to add a real-world example. Eg. if you use this feature, just a small part any of your rule where you use that.

@JonathanBerrew
Copy link
Author

In our rules, we have:

<Macro SecObsolete_ @target $pattern $msg>
 Use NotInsideLocation
 Use SecRule ENV:PathToIgnore @unconditionalMatch  "phase:1,t:none,tag:specific,~{skipAfter}:AfterObsoleteLocation"
  Use SecRule @target  "(?i)$pattern"  "phase:1,t:none,tag:specific,setvar:'TX.obsolete_$pattern',ctl:auditLogParts=-CEGI,~{localFile}=/SecError/obsolete.html,~{noErrorHeader},msg:'Obsolete $msg'"
  Use RuleLogSome IP "obsolete_$pattern" 100
 Use SecMarker AfterObsoleteLocation
</Macro>

<Macro SecObsoleteLocation @pattern>
 Use SecObsolete_ TX:url   @pattern location
</Macro>

<Macro SecObsoleteHost                 @pattern>
 Use SecObsolete_ REQUEST_HEADERS:Host @pattern location
</Macro>

Here we have setvar:'TX.obsolete_$pattern'
Where pattern could be any regex for a locationMatch for example.
Is this a good example? If not I'll try to look if we have other better ones

@airween
Copy link
Member

airween commented Mar 23, 2026

Is this a good example? If not I'll try to look if we have other better ones

Uhm, without the mentioned <Location> syntax, I think this is hard to understand. Could you get a more exact example?

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.

3 participants