fix(942200): False Positive#4236
Conversation
|
📊 Quantitative test results for language: |
|
|
||
| ##! Helpers | ||
| ##!> define punctuation-hexnumbers ,.*?[)\da-f\"'`] | ||
| ##!> define punctuation-hexnumbers ,\S*?[)\da-f\"'`] |
There was a problem hiding this comment.
I don't think that's correct. I'm pretty sure spaces after the comma are possible.
There was a problem hiding this comment.
I thought so. What do you think is a better solution for this? I suggest moving this to PL2 until a fix is found.
There was a problem hiding this comment.
We need to properly analyse what punctuation-hexnumbers is supposed to match. It looks like something like select a, b '... but I don't understand the role of the hexadecimal and parenthesis. The a-f doesn't even make much sense, since hexadecimals must be preceded by either X' or 0x in MySQL. I have the feeling that we might be able to split up the character class into a more restrictive sequence, which would fix the issue.
There was a problem hiding this comment.
If you check the regex, all of the below statements are exact matches.
SELECT * FROM users WHERE name = 'admin', --
SELECT * FROM users WHERE username = 'admin', '1'='1'
INSERT INTO logs (ip, comment) VALUES ('192.168.0.1', 'test')
SELECT * FROM data WHERE hash = 'abc', 0x1a
SELECT * FROM orders WHERE product = 'item', (5)The fourth statement above provides a hexadecimal syntax usage.
There was a problem hiding this comment.
Thanks. So the main issue appears to be that the regex doesn't match quotes. We could expand the regex with three additional expressions that match every type of quote, e.g.,
...'[^']*'...|..."[^"]*"...|...`[^`]*`...
There was a problem hiding this comment.
Making quotes optional would lead to the same FP as above.
There was a problem hiding this comment.
No, I mean matching quote pairs. To do that, you need one expression per quote type. Currently, punctuation-hexnumbers is paired with ticks but that doesn't work as it's supposed to, I believe. punctuation-hexnumbers may not have match a quote, but a letter, so ticks will not match a closing quote but an opening one. If we matched quote pairs, we could reduce FPs. Although it's common enough in french to have a name with more than one quote, e.g., rue d'Arlon sur l'avon, so that would still remain an FP.
Honestly, I think the regex is just too generic. It's combined with detection for SQL keywords, which doesn't make much sense. The quote detection stuff is clearly more prone to FPs and should live in a separate rule. Could you modify the PR to split the rule into two distinct rules? That will also make it easier to test different detections.
There was a problem hiding this comment.
That makes sense, separating based on quote pairs will surely reduce FP, since the phrase like rue d'Arlon uses single quotes.
There was a problem hiding this comment.
Fixed the issue. Actually the regex was wrong, and we were matching {{ticks}} after {{ticks}} which is not correct.
There was a problem hiding this comment.
I don't agree with your latest change, but I'll need some time to look into it properly.
There was a problem hiding this comment.
Pull request overview
This PR adjusts the SQL injection detection regex for rule 942200 to eliminate a specific false positive on valid postal addresses, and adds regression coverage to guard against regressions.
Changes:
- Updated the assembled regex for rule 942200 (
regex-assembly/942200.ra) to change the trailing alternatives so that a comma+quote pattern must be followed by either a closing parenthesis, end-of-input, or a balanced closing quote/backtick, reducing false positives like999, rue d'Arlon. - Regenerated/synchronized the concrete ModSecurity rule in
rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conffrom the updated regex assembly so the deployed rule reflects the new behavior. - Extended regression tests for rule 942200: tweaked the header-based positive test and added a new negative test to assert that the
address=999, rue d'Arloncase no longer triggers rule 942200.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/regression/tests/REQUEST-942-APPLICATION-ATTACK-SQLI/942200.yaml | Adjusts existing positive header test and adds a new negative test reproducing Issue #3838 to ensure rule 942200 no longer fires on a valid postal address string. |
| rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf | Updates the compiled regex for rule 942200 to incorporate the refined comma+quote/backtick pattern, aiming to avoid the documented false positive while keeping the rest of the detection intact. |
| regex-assembly/942200.ra | Modifies the regex assembly for 942200 so that the generated pattern requires either a closing parenthesis, end-of-line, or a trailing quote/backtick after non-quote characters, bringing the rule’s behavior in line with the intended fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Fixes FPs against French addresses, such as `999, rue d'Arlon` - Additional tests and enhanced regex Fixes coreruleset#4236
|
Closed in favor of #4476 |
- Fixes FPs against French addresses, such as `999, rue d'Arlon` - Additional tests and enhanced regex Fixes coreruleset#3838 Replaces coreruleset#4236
…4476) * fix(942200): FP against comma and single quote in French addresses - Fixes FPs against French addresses, such as `999, rue d'Arlon` - Additional tests and enhanced regex Fixes #3838 Replaces #4236 * Update regex-assembly/942200.ra --------- Co-authored-by: Felipe Zipitría <[email protected]>
Closes #3838.
Additional Reference: https://g.co/gemini/share/85718028c2c5