Skip to content

fix(rules): eliminate SLP085/SLP118 false positives on detector code - #47

Merged
messagesgoel-blip merged 4 commits into
mainfrom
fix/rule-false-positives
May 16, 2026
Merged

messagesgoel-blip merged 4 commits into
mainfrom
fix/rule-false-positives

Conversation

@messagesgoel-blip

Copy link
Copy Markdown
Collaborator

Summary

Two rules false-positive on slopgate's own rule code at block severity, which fails the dogfooding self-scan (./slopgate --base origin/main) in CI for PRs #44/#45/#46.

  • SLP085 flagged any line with a SQL keyword + quote + + as concatenated SQL. A regex literal like `\s+["']/` trips all three. Fixed: the + must appear outside string/regex literals (checked via stripCommentAndStrings).
  • SLP118 only understood len(x) > N guards, so an early-exit guard if len(x) == 0 { return } left a later x[0] flagged as unguarded. Fixed: early-exit emptiness guards now mark a collection non-empty for index-0 access — Go/Python len(x) == 0, JS/TS x.length === 0 / !x.length, plus < 1 / <= 0 forms.

Both changes only reduce false positives; no true-positive detection is removed.

Validation

Not tied to a roadmap task (bug fix) — labeled no-roadmap-task.

🤖 Generated with Claude Code

SLP085 treated any line containing a SQL keyword, a quote, and a "+"
as string-concatenated SQL. A regex literal such as `\s+["']/` trips
all three. Now the "+" must appear outside string/regex literals.

SLP118 only recognised `len(x) > N` style guards, so an early-exit
guard `if len(x) == 0 { return }` left a following `x[0]` flagged as
unguarded. Now early-exit emptiness guards (Go/Python `len(x) == 0`,
JS/TS `x.length === 0`, `!x.length`, plus `< 1` / `<= 0` forms) mark
the collection non-empty for subsequent index-0 access.

Both surfaced as block-severity findings when slopgate scans its own
rule code, breaking the dogfooding self-scan in CI.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@messagesgoel-blip messagesgoel-blip added the no-roadmap-task Allowed exception: no roadmap task required label May 16, 2026
@coderabbitai

coderabbitai Bot commented May 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Rate limit exceeded

@messagesgoel-blip has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 31 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1d8dde21-fa55-414b-8158-6f47aebf1def

📥 Commits

Reviewing files that changed from the base of the PR and between 10bc66b and 48f8bf2.

📒 Files selected for processing (2)
  • pkg/rules/slp118.go
  • pkg/rules/slp118_test.go
📝 Walkthrough

Walkthrough

This PR refines SLP085 to avoid flagging + inside comments/strings/regexes and extends SLP118 to recognize early-exit emptiness guards so some x[0] accesses are treated as safe.

Changes

SLP085: SQL Concatenation False-Positive Reduction

Layer / File(s) Summary
SQL concatenation operator detection refinement
pkg/rules/slp085.go, pkg/rules/slp085_test.go
The + operator check now operates on a codeOnly version of the line stripped of comments and string/regex literals, while the existing quote-based condition remains against the original content. A new test validates the rule does not flag SQL-like keywords inside Go regex literals.

SLP118: Early-Exit Guard Recognition for Index Access Safety

Layer / File(s) Summary
Pattern definitions and guard-detection helpers
pkg/rules/slp118.go
New regex patterns detect empty-collection comparisons and early-exit statements. Helpers extract collection identifiers from empty checks and detect lookahead exits used to prove non-emptiness.
Core logic: early-exit information integration
pkg/rules/slp118.go
The index-guarding function is refactored to accept a nonEmpty map and gains a shortcut: when [0] access is guarded by early-exit proof, no standard length guards are required. The Check method precomputes nonEmpty once and threads it through the access validation call site.
Early-exit guard test cases
pkg/rules/slp118_test.go
Four new tests verify that index-access warnings are suppressed after return/continue guards on empty checks and after JavaScript early-exit patterns, and confirm findings are still reported when empty checks lack early exits.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

In burrowed code where warnings play,
I strip the strings that led astray.
A guard that jumps and leaves no trace,
Lets zero-index find its place.
Hoppity checks—now tidy and gay! 🐰

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description does not follow the required template with Roadmap Task section. Missing 'Closes/Fixes/Resolves #' issue reference and required Validation/Review sections. Add required Roadmap Task section with issue reference or confirm 'no-roadmap-task' label usage is documented. Include all template sections: Summary (what/why), Validation checklist with test commands, and Review checklist.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main objective: fixing false positives in SLP085 and SLP118 rules on detector code.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rule-false-positives

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • LINEAR integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Comment @coderabbitai help to get the list of available commands and usage tips.

The new slp118EmptyCheckCollections accessed m[1] on regexp submatch
slices without a length guard, which SLP118 itself flags at block
severity during the dogfooding self-scan.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread pkg/rules/slp118.go Resolved
A closure tripped SLP051 (undefined function). Inline guarded loops
keep the m[1] submatch access length-checked without that.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/rules/slp118.go`:
- Around line 250-272: The current non-empty tracking in
slp118NonEmptyAfterGuards uses a map keyed only by collection name (out
map[string]bool), causing proofs to be applied file-wide and suppress valid
findings; change the key to include program position (e.g., line/index or a
composite of collection+line index) so the non-empty fact is scoped to the
specific program location; update slp118NonEmptyAfterGuards to record keys like
"<index>|<collection>" (or use a nested map map[string]map[int]bool) when
setting out and checking it, and apply the same positional-scoped key change to
the related logic referenced around lines 291-295 to avoid cross-function/block
bleed.
- Around line 233-247: slp118LookaheadExit currently treats any
return/break/continue within the next three non-blank lines as an exit, which
misattributes exits that are outside the empty-check guard; modify
slp118LookaheadExit to track brace depth while scanning (increment on '{',
decrement on '}') and only treat a matched slp118ExitRe as a guard exit if it
occurs while the depth indicates we are inside the guard body (i.e., after an
opening '{' for the if/guard and before its matching '}'); also handle same-line
braces by updating depth from the scanned line's contents so single-line guards
like "if ... { return }" are detected correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5b07a79c-a8e8-4fc8-88f5-caf562fbb98f

📥 Commits

Reviewing files that changed from the base of the PR and between 6e5f231 and 4067b20.

📒 Files selected for processing (4)
  • pkg/rules/slp085.go
  • pkg/rules/slp085_test.go
  • pkg/rules/slp118.go
  • pkg/rules/slp118_test.go
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Seer Code Review
🧰 Additional context used
🪛 GitHub Actions: CI / 0_build-and-test.txt
pkg/rules/slp085.go

[warning] 1-1: [SLP113] source file changed without corresponding test file — expected pkg/rules/slp085_test.go


[warning] 72-72: [SLP127] rule file changed without matching test updates in this diff — add regression coverage in pkg/rules/slp085_test.go


[warning] 75-75: [SLP148] inconsistent naming for 'content': Content, content; consider standardizing to one convention

pkg/rules/slp118.go

[warning] 1-1: [SLP113] source file changed without corresponding test file — expected pkg/rules/slp118_test.go


[warning] 26-26: [SLP127] rule file changed without matching test updates in this diff — add regression coverage in pkg/rules/slp118_test.go


[warning] 29-29: [SLP116] regex with nested quantifiers detected — potential ReDoS vulnerability


[warning] 30-30: [SLP116] regex with nested quantifiers detected — potential ReDoS vulnerability


[warning] 146-146: [SLP050] function slp118AllIndicesGuarded accepts guards without validation — add nil/empty check


[warning] 146-146: [SLP050] function slp118AllIndicesGuarded accepts nonEmpty without validation — add nil/empty check


[warning] 146-146: [SLP050] function slp118AllIndicesGuarded accepts content without validation — add nil/empty check


[warning] 204-204: [SLP050] function slp118CheckAccess accepts guards without validation — add nil/empty check


[warning] 204-204: [SLP050] function slp118CheckAccess accepts nonEmpty without validation — add nil/empty check


[warning] 204-204: [SLP050] function slp118CheckAccess accepts content without validation — add nil/empty check


[info] 216-216: [SLP055] function slp118EmptyCheckCollections has 4 conditionals with no comments — explain the complex logic


[warning] 216-216: [SLP050] function slp118EmptyCheckCollections accepts line without validation — add nil/empty check


[warning] 216-216: [SLP148] inconsistent naming for 'line': Line, line; consider standardizing to one convention


[warning] 219-219: [SLP065] error return ignored — handle or explicitly suppress with _


[error] 220-220: [SLP118] direct index access without length guard — may panic on empty collection


[warning] 222-222: [SLP065] error return ignored — handle or explicitly suppress with _


[error] 223-223: [SLP118] direct index access without length guard — may panic on empty collection


[warning] 227-227: [SLP065] error return ignored — handle or explicitly suppress with _


[error] 228-228: [SLP118] direct index access without length guard — may panic on empty collection


[warning] 235-235: [SLP050] function slp118LookaheadExit accepts stripped without validation — add nil/empty check


[info] 237-237: [SLP017] magic number 3 — define a named constant for clarity


[warning] 253-253: [SLP050] function slp118NonEmptyAfterGuards accepts lines without validation — add nil/empty check


[warning] 253-253: [SLP050] function slp118NonEmptyAfterGuards accepts filePath without validation — add nil/empty check


[warning] 253-253: [SLP148] inconsistent naming for 'lines': Lines, lines; consider standardizing to one convention


[warning] 261-261: [SLP016] variable "cols" shadows outer-scope declaration

🪛 GitHub Actions: CI / build-and-test
pkg/rules/slp085.go

[warning] 1-1: SLP113: source file changed without corresponding test file — expected pkg/rules/slp085_test.go


[warning] 72-72: SLP127: rule file changed without matching test updates in this diff — add regression coverage in pkg/rules/slp085_test.go


[warning] 75-75: SLP148: inconsistent naming for 'content': Content, content (consider standardizing)

pkg/rules/slp118.go

[warning] 1-1: SLP113: source file changed without corresponding test file — expected pkg/rules/slp118_test.go


[warning] 26-26: SLP127: rule file changed without matching test updates in this diff — add regression coverage in pkg/rules/slp118_test.go


[warning] 29-30: SLP116: regex with nested quantifiers detected — potential ReDoS vulnerability


[warning] 146-146: SLP050: function slp118AllIndicesGuarded accepts guards without validation — add nil/empty check


[warning] 146-146: SLP050: function slp118AllIndicesGuarded accepts nonEmpty without validation — add nil/empty check


[warning] 146-146: SLP050: function slp118AllIndicesGuarded accepts content without validation — add nil/empty check


[warning] 204-204: SLP050: function slp118CheckAccess accepts guards without validation — add nil/empty check


[warning] 204-204: SLP050: function slp118CheckAccess accepts nonEmpty without validation — add nil/empty check


[warning] 204-204: SLP050: function slp118CheckAccess accepts content without validation — add nil/empty check


[warning] 216-216: SLP050: function slp118EmptyCheckCollections accepts line without validation — add nil/empty check


[warning] 216-216: SLP148: inconsistent naming for 'line': Line, line (consider standardizing)


[warning] 219-219: SLP065: error return ignored — handle or explicitly suppress with _


[error] 220-220: SLP118: direct index access without length guard — may panic on empty collection


[warning] 222-223: SLP065: error return ignored — handle or explicitly suppress with _


[error] 223-223: SLP118: direct index access without length guard — may panic on empty collection


[warning] 227-228: SLP065: error return ignored — handle or explicitly suppress with _


[error] 228-228: SLP118: direct index access without length guard — may panic on empty collection


[warning] 235-235: SLP050: function slp118LookaheadExit accepts stripped without validation — add nil/empty check


[warning] 216-216: SLP118: function slp118EmptyCheckCollections has 4 conditionals with no comments — explain the complex logic


[info] 237-237: SLP017: magic number 3 — define a named constant for clarity


[warning] 253-253: SLP050: function slp118NonEmptyAfterGuards accepts lines without validation — add nil/empty check


[warning] 253-253: SLP050: function slp118NonEmptyAfterGuards accepts filePath without validation — add nil/empty check


[warning] 253-253: SLP148: inconsistent naming for 'lines': Lines, lines (consider standardizing)


[warning] 261-261: SLP016: variable "cols" shadows outer-scope declaration

🔇 Additional comments (2)
pkg/rules/slp085.go (1)

72-78: LGTM!

pkg/rules/slp085_test.go (1)

93-105: LGTM!

Comment thread pkg/rules/slp118.go Resolved
Comment thread pkg/rules/slp118.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/rules/slp118.go`:
- Around line 297-301: The current flattening of hunks into allLines causes
slp118LookaheadExit to treat lines from different hunks as contiguous; instead
preserve real file positions and avoid cross-hunk lookahead by passing line
numbers or processing per-hunk with offsets: update callers (the loop building
allLines and the call to slp118NonEmptyAfterGuards) so you either (a) pass a
slice of lines that includes their original file line number (e.g., augment
diff.Line or wrap it in a struct with LineNumber) and make
slp118NonEmptyAfterGuards / slp118LookaheadExit use those numbers, or (b)
iterate each hunk and call slp118NonEmptyAfterGuards per hunk while supplying
the hunk start offset so lookahead checks compute absolute file positions
instead of relying on slice indices; change references to allLines,
slp118NonEmptyAfterGuards, and slp118LookaheadExit accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fced1b8c-789a-4e8f-8ddb-05beb7c67bc6

📥 Commits

Reviewing files that changed from the base of the PR and between 4067b20 and 10bc66b.

📒 Files selected for processing (1)
  • pkg/rules/slp118.go
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Seer Code Review
🔇 Additional comments (7)
pkg/rules/slp118.go (7)

239-254: Scope-tracking concern already flagged.

The past review correctly identified that this function doesn't track brace depth or indentation, so exits outside the guard body may be misattributed as proving non-emptiness.


256-279: File-wide scope concern already flagged.

The past review correctly identified that nonEmpty is computed once for the entire file and keyed only by collection name, which can cause false negatives for accesses in different functions or earlier in the file.


26-31: LGTM!


146-167: LGTM!


204-211: LGTM!


214-237: LGTM!


340-340: LGTM!

Comment thread pkg/rules/slp118.go Resolved
Comment thread pkg/rules/slp118.go Resolved
Addresses CodeRabbit review of #47. The first cut computed proven-
non-empty collections once per file, keyed only by name, so any
`if len(x) == 0 { return }` suppressed every `x[0]` in the file —
including accesses before the guard or in a different function.

Early-exit guards are now tracked per hunk and per block: a guard
takes effect only after its closing line and only while execution
stays at or below the guard's indentation. The guard body must be
exactly one control-flow exit, so `if len(x) == 0 { log() }` is no
longer mistaken for a guard. Handles brace and indentation blocks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@messagesgoel-blip

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@messagesgoel-blip
messagesgoel-blip merged commit 2d74a73 into main May 16, 2026
4 checks passed
@messagesgoel-blip
messagesgoel-blip deleted the fix/rule-false-positives branch May 16, 2026 23:08
Comment thread pkg/rules/slp085.go
Comment on lines +78 to 81
if strings.Contains(codeOnly, "+") && (strings.Contains(content, "'") || strings.Contains(content, "\"")) {
out = append(out, Finding{
RuleID: r.ID(),
Severity: r.DefaultSeverity(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The SQL injection rule SLP085 can trigger a false positive by detecting SQL keywords in comments while checking for concatenation operators only in the code.
Severity: LOW

Suggested Fix

The SQL keyword check should be performed on the code-only version of the line content (codeOnly), after comments and strings have been stripped. This will ensure that keywords found within comments do not trigger the rule.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: pkg/rules/slp085.go#L78-L81

Potential issue: The SLP085 rule for detecting SQL injection incorrectly analyzes
different parts of a line. It checks for SQL keywords in the full line content,
including comments, but checks for the `+` concatenation operator only in the code part
after stripping comments and strings. This inconsistency can lead to a false positive if
a line of code uses a `+` operator for a non-SQL-related purpose, but has a comment on
the same line that happens to contain an SQL keyword and a quote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-roadmap-task Allowed exception: no roadmap task required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant