Skip to content

ascanrules: reduce false positives in boolean-based SQLi check - #7588

Open
Char0n1507 wants to merge 3 commits into
zaproxy:mainfrom
Char0n1507:fix/sql-injection-false-positives
Open

ascanrules: reduce false positives in boolean-based SQLi check#7588
Char0n1507 wants to merge 3 commits into
zaproxy:mainfrom
Char0n1507:fix/sql-injection-false-positives

Conversation

@Char0n1507

@Char0n1507 Char0n1507 commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Reduces false positives in the boolean-based (OR TRUE) SQL injection check in testBooleanBasedNoDataSqlInjection.

Problem

Fixes zaproxy/zaproxy#9289

The check fires when the OR TRUE response body is >20% larger than the original.
Dynamic pages (ads, timestamps, session tokens, random content) naturally vary
by this amount, producing false positives on non-vulnerable endpoints.

Fix

  • Raised size ratio threshold from 1.2x → 1.4x
  • Added a minimum absolute difference guard of 500 bytes
  • Both conditions must now be true before the vulnerability is flagged

Testing

  • Verified old text (20% size difference) is removed from the file
  • Verified new variables (normalLen, orTrueLen, absoluteDiff) are present
  • Existing logic inside the if block is completely unchanged

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

…#9289)

- Raise OR-TRUE response size threshold from 1.2x to 1.4x
- Add minimum absolute size difference guard (500 bytes)
- Prevents false positives on dynamic pages with variable content
  such as ads, timestamps, and session tokens
@Char0n1507
Char0n1507 force-pushed the fix/sql-injection-false-positives branch from 0b79e50 to 6219569 Compare July 28, 2026 00:20
@Char0n1507

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@psiinon

psiinon commented Jul 28, 2026

Copy link
Copy Markdown
Member

Logo
Checkmarx One – Scan Summary & Details93714c81-8642-4044-843b-6fc1d6b0aca6


Fixed Issues (1)

Medium: 1

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM CVE-2025-4949 Maven-org.eclipse.jgit:org.eclipse.jgit-6.7.0.202309050840-r

Communicate with Checkmarx by submitting a PR comment with @Checkmarx followed by one of the supported commands. Learn about the supported commands here.

@Char0n1507

Copy link
Copy Markdown
Author

Thanks for the review! Happy to make any adjustments needed.
Let me know if you'd like me to add a unit test for the new
threshold/byte-guard logic in SqlInjectionScanRuleUnitTest.java.

@kingthorin

Copy link
Copy Markdown
Member

Why 500?

That just makes things be big to start with. 500 is 40% of 1,250 so that assumes the response is over a meg to start with. I don't think this is a good mechanic.

Replace the hardcoded 500-byte absolute difference guard with a relative
check (20% of original response length), so the guard scales with response
size rather than assuming responses are over 1MB.

Add unit tests covering:
- OR-TRUE ratio below 1.4x threshold (no alert)
- OR-TRUE ratio just under boundary (no alert)
- OR-TRUE ratio and diff both exceed thresholds (alert)
@Char0n1507

Char0n1507 commented Jul 28, 2026

Copy link
Copy Markdown
Author

Good point on the 500 bytes I reconsidered and you're right, it's not a sound mechanic.

I also looked at replacing it with a relative guard (20% of normalLen), but realized that's mathematically redundant: if ratio >= 1.4x then absoluteDiff >= 40% of normalLen already, so the second condition can never actually block anything the ratio check doesn't already catch.

So I've simplified to just the ratio threshold alone (1.4x). That's the correct and sufficient fix. I've also added three unit tests to SqlInjectionScanRuleUnitTest.java:

  • OR-TRUE ratio below 1.4x → no alert
  • OR-TRUE ratio just under the 1.4x boundary → no alert
  • OR-TRUE ratio exceeds 1.4x → alert (confirms real detections still fire)

Drop the redundant absolute byte guard — since ratio >= 1.4x already
implies diff >= 40% of normalLen, the second condition added no filtering
value. The ratio threshold alone (raised from 1.2x to 1.4x) is the
correct and sufficient fix for #9289.
@thc202 thc202 changed the title fix(ascanrules): reduce false positives in boolean-based SQLi check ascanrules: reduce false positives in boolean-based SQLi check Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

False Positives of "SQL Injection"

3 participants