fix(G202): don't flag strings.Builder built from constants - #1707
Merged
ccojocar merged 2 commits intoJul 20, 2026
Merged
Conversation
…1701) Signed-off-by: Ravi Sastry Kadali <ravisastryk@gmail.com>
ravisastryk
had a problem deploying
to
security-review
July 18, 2026 18:36 — with
GitHub Actions
Failure
ravisastryk
marked this pull request as ready for review
July 18, 2026 18:40
Contributor
Author
|
Heads-up: the barry-ai-security-review job is failing on the new actions/checkout@v7 "pull_request_target" guard, not on this PR's changes, the checkout step needs |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1707 +/- ##
==========================================
+ Coverage 80.53% 80.56% +0.02%
==========================================
Files 110 110
Lines 10255 10337 +82
==========================================
+ Hits 8259 8328 +69
- Misses 1512 1519 +7
- Partials 484 490 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: Ravi Sastry Kadali <ravisastryk@gmail.com>
ravisastryk
had a problem deploying
to
security-review
July 19, 2026 17:32 — with
GitHub Actions
Failure
ccojocar
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(G202): don't flag
strings.Builderbuilt from constantsProblem
G202 (SQL string concatenation) reports a false positive when a query is built by concatenating the result of a
strings.Builder(orbytes.Buffer) whose content is only constant literals — the common, efficient idiom for buildingSQL
IN (...)placeholder lists.The inconsistency: the equivalent
+=construction is not flagged, but thestrings.Builderreplacement (recommended for efficiency) is.Fixes: #1701
Root cause
TryResolvetreats any function-call result as unresolved (tainted), sobuilder.String()was always considered non-constant, regardless of what was written into the builder.Fix
resolveCallExprnow recognizesstrings.Builder.String()/bytes.Buffer.String()and resolves it to a constant only when every write into that builder is a constant. It stays conservative - a non-constant write, an opaque initializer, an escaping address, or a package-level builder all keep the query flagged. Genuinely tainted builders are still detected.How to test (quick)
Unit tests (covers the new positive + negative samples):
go test -run TestRules ./rules/End-to-end — drop this into a file and scan it:
Expected: exactly 1 issue — the tainted builder is reported, the constant-only builder is not. Before this change, both were reported.