Skip to content

feat(942440): reduce false positive#4346

Merged
azurit merged 25 commits into
coreruleset:mainfrom
touchweb-vincent:patch-20
Dec 8, 2025
Merged

feat(942440): reduce false positive#4346
azurit merged 25 commits into
coreruleset:mainfrom
touchweb-vincent:patch-20

Conversation

@touchweb-vincent
Copy link
Copy Markdown
Contributor

@touchweb-vincent touchweb-vincent commented Nov 17, 2025

Hello,

Since we’re now handling a few false positives using a chained rule, I suggest excluding [\w\-]+ to avoid common false positives from this rule against tokens or URL slugs

I didn’t add \. "just in case", but we could if needed. As far as I know, it’s impossible to have a full and dangerous injection within a [\w\-]+ scope - at best it could catch fragmented injections or very exotic use cases, which I’ve never encountered in 20 years.

This will certainly weaken the rule when it comes to capturing this type of payload (1--x-) but 942100 stay in backup.

curl -H "x-format-output: txt-matched-rules" -H "x-crs-paranoia-level:4" "https://sandbox.coreruleset.org/?test=1--1-"`
942100 PL1 SQL Injection Attack Detected via libinjection
942440 PL2 SQL Comment Sequence Detected
942432 PL4 Restricted SQL Character Anomaly Detection (args): # of special characters exceeded (2)
949110 PL? Inbound Anomaly Score Exceeded (Total Score: 13)
980170 PL? Anomaly Scores: (Inbound Scores: blocking=13, detection=13, per_pl=5-5-0-3, threshold=5) - (Outbound Scores: blocking=0, detection=0, per_pl=0-0-0-0, threshold=4) - (SQLI=13, XSS=0, RFI=0, LFI=0, RCE=0, PHPI=0, HTTP=0, SESS=0, COMBINED_SCORE=13)

What do you think?

touchweb-vincent and others added 2 commits November 17, 2025 15:22
Removed exclusion rules for Facebook and Google click identifiers to reduce false positives.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 17, 2025

📊 Quantitative test results for language: eng, year: 2023, size: 10K, paranoia level: 1:
🚀 Quantitative testing did not detect new false positives

Copy link
Copy Markdown
Member

@EsadCetiner EsadCetiner left a comment

Choose a reason for hiding this comment

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

Can you make your changes via the regex assembly file instead of deleting it? More complex regexes like you have here are harder to read and maintain which is why we have the format.

Can you add some positive/negative tests to make sure your change doesn't accidently break anything?

@touchweb-vincent
Copy link
Copy Markdown
Contributor Author

If you have an existing use case that shows how to create this regex in .ra, I’d be happy to look at it; otherwise, no. I feel I’ve already wasted enough time trying to implement this use case in .ra and nothing works.

@EsadCetiner
Copy link
Copy Markdown
Member

You can always refer to regex assembly and the crs-toolchain docs to get an idea as to how they work.

I feel I’ve already wasted enough time trying to implement this use case in .ra and nothing works.

Keep in mind that crs-toolchain auto-optimizes the regex, so the output might not be exactly what you want although the behavior should be the same. I'm not entirely sure what false positive your targeting specifically, but based on the regex I'm seeing I think this is what you want:

##! Please refer to the documentation at
##! https://coreruleset.org/docs/development/regex_assembly/.

##! This chained rule is used to match on JWT base64-urlencoded tokens.
##! See https://www.rfc-editor.org/rfc/rfc4648#section-5 for details.

##! JWTs consist of base64-urlencoded encoded JSON, and a JSON structure 
##! just starts with '{"', which becomes 'ey' when encoded with a base64-urlencoded encoder.

##!> define base64-urlencoded-charset [a-zA-Z0-9_-]+
##!> define dot [.]

##!^ ^

##!> assemble
ey{{base64-urlencoded-charset}}{{dot}}ey{{base64-urlencoded-charset}}{{dot}}{{base64-urlencoded-charset}}
##!<

##!> assemble
[\w-]+
##!<

##!$ $

Also can you add some positive/negative tests, and especially tests for the false positive that this PR is meant to fix?

touchweb-vincent and others added 6 commits December 7, 2025 09:47
Added a chained rule for matching JWT base64-urlencoded tokens with detailed documentation.
Added multiple test cases for false positives against various tokens.
@touchweb-vincent
Copy link
Copy Markdown
Contributor Author

Thanks @EsadCetiner for your feedback. I updated the PR accordingly and added unit tests.

I'm having an issue with the .ra file that I don't understand, and the debugging output is really not verbose. Could you please help me?

Updated descriptions for multiple tests to include truncation note for the linter.
Copy link
Copy Markdown
Member

@EsadCetiner EsadCetiner left a comment

Choose a reason for hiding this comment

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

If you run crs-toolchain regex format --all with crs-toolchain then that should resolve the errors for the assembly file

Also see my comments on the tests you need to fix

Comment thread tests/regression/tests/REQUEST-942-APPLICATION-ATTACK-SQLI/942440.yaml Outdated
Comment thread tests/regression/tests/REQUEST-942-APPLICATION-ATTACK-SQLI/942440.yaml Outdated
Comment thread tests/regression/tests/REQUEST-942-APPLICATION-ATTACK-SQLI/942440.yaml Outdated
Comment thread tests/regression/tests/REQUEST-942-APPLICATION-ATTACK-SQLI/942440.yaml Outdated
@touchweb-vincent
Copy link
Copy Markdown
Contributor Author

I have absolutely no idea how to do that through the GitHub interface.

@EsadCetiner
Copy link
Copy Markdown
Member

@touchweb-vincent You need to run the command locally on your machine then push your changes to GitHub via the CLI. I've fixed this one for you.

@touchweb-vincent
Copy link
Copy Markdown
Contributor Author

Thanks @EsadCetiner

EsadCetiner
EsadCetiner previously approved these changes Dec 8, 2025
@EsadCetiner EsadCetiner requested a review from a team December 8, 2025 08:44
@EsadCetiner
Copy link
Copy Markdown
Member

I can't merge since I pushed a commit to this PR

@touchweb-vincent
Copy link
Copy Markdown
Contributor Author

@azurit @fzipi ping :)

Comment thread tests/regression/tests/REQUEST-942-APPLICATION-ATTACK-SQLI/942440.yaml Outdated
@azurit
Copy link
Copy Markdown
Member

azurit commented Dec 8, 2025

@touchweb-vincent Happened again - no information in the PR description. I had to read the code and tests to understand what are you trying to achieve and only AFTER that i was able to start a real review. Recently, you were asking on Slack what can you do to speed up reviewing of your PRs, so now i'm telling it to you for the second time: Write full and complete descriptions and provide all information which you are asked for. It's that simple.

@touchweb-vincent
Copy link
Copy Markdown
Contributor Author

@azurit I understand, and I will try to do better, but I don’t have the required skills to clearly distinguish what seems obvious from what isn’t.

So if I add more explanations, you might think I’m treating you like idiots - please don’t hold it against me; I’m just not good at gauging this, and communication really isn’t one of my strong points.

…440.yaml

Co-authored-by: azurit <jozef@sudolsky.sk>
@dune73
Copy link
Copy Markdown
Member

dune73 commented Dec 8, 2025

Rule of thumb: Additional information and redundancy in a PR description is almost always a good thing. I see that it can look a bit idiotic at a given level, but it's definitely better to write too many explanations than not enough.

PR descriptions are also for future reference when Slack conversations, other PRs and even issues are long forgotten. People should be able to make sense of a PR without any other explanation. Optional links welcome, but the information better be with the PR.

And agreed: It takes practice.

@azurit azurit added this pull request to the merge queue Dec 8, 2025
@azurit
Copy link
Copy Markdown
Member

azurit commented Dec 8, 2025

@touchweb-vincent Thank you.

Merged via the queue into coreruleset:main with commit ac24671 Dec 8, 2025
10 checks passed
@touchweb-vincent touchweb-vincent deleted the patch-20 branch December 8, 2025 12:47
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.

4 participants