Repository navigation
fix(rules): eliminate SLP085/SLP118 false positives on detector code - #47
Conversation
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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR refines SLP085 to avoid flagging ChangesSLP085: SQL Concatenation False-Positive Reduction
SLP118: Early-Exit Guard Recognition for Index Access Safety
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Comment |
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>
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>
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
pkg/rules/slp085.gopkg/rules/slp085_test.gopkg/rules/slp118.gopkg/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!
There was a problem hiding this comment.
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
📒 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
nonEmptyis 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!
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>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
| if strings.Contains(codeOnly, "+") && (strings.Contains(content, "'") || strings.Contains(content, "\"")) { | ||
| out = append(out, Finding{ | ||
| RuleID: r.ID(), | ||
| Severity: r.DefaultSeverity(), |
There was a problem hiding this comment.
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.
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.+as concatenated SQL. A regex literal like`\s+["']/`trips all three. Fixed: the+must appear outside string/regex literals (checked viastripCommentAndStrings).len(x) > Nguards, so an early-exit guardif len(x) == 0 { return }left a laterx[0]flagged as unguarded. Fixed: early-exit emptiness guards now mark a collection non-empty for index-0 access — Go/Pythonlen(x) == 0, JS/TSx.length === 0/!x.length, plus< 1/<= 0forms.Both changes only reduce false positives; no true-positive detection is removed.
Validation
go test -race ./...— all pass (4 new regression tests across SLP085/SLP118)./slopgate --no-color --base origin/main— no findingsslp098.goare gone, self-scan exits 0Not tied to a roadmap task (bug fix) — labeled
no-roadmap-task.🤖 Generated with Claude Code