owasp-modsecurity / owasp-modsecurity/ModSecurity
Regex in setvar variables
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.8k
- Avg merge
- 2h 46m
- Merged PRs (30d)
- 1
Description
Context:
Currently, (unescaped) backslashes are forbidden in variables content.
In msre_parse_generic():
if (*p == '\\') {
if ((*(p + 1) == '\0') || ((*(p + 1) != '\'') && (*(p + 1) != '\\'))) {
[error & return]
}
p++;
The only case a backslash is accepted is when it escapes a single quote or a backslash.
Problem:
You cannot store a regex in a variable: setvar:'tx.var=\babc\b'
When doing this manually, you can escape the string obviously: setvar:'tx.var=\babc\b'
But when you use a macro like the following:
<Macro MyMacro $regex>
SecAction ...,setver:'var=$regex',...
SecRule ARG "$regex" ...
</Macro>
there's no way to call the macro with a parameter compatible with both directives
Solution:
We could be lax (and still compatible with the current behaviour):
- If it's followed by a quote or a backslash, accept and "eats" the escaping backslash
- In all other cases, accept and don't "eat" the backslash
- the code change is trivial
Does somebody see any other solution?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in msre_parse_generic(), where backslashes in variable content are currently rejected unless they escape a quote or another backslash. Exercise setvar values containing regexes and macro parameters, then verify that quote and backslash escapes are consumed while other backslashes are preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100