Suppress the gosec G704 SSRF false positive in Client.Do - #49
Merged
Conversation
gosec 2.28.0 added rule G704 (SSRF via taint analysis), which traces the URL from argv into
c.getHttpClient().Do(req) and fails `just pre-commit` on an otherwise unchanged tree.
The finding is a false positive by construction. SSRF requires an attacker to supply a URL to a
service holding network reach the attacker lacks. Here the URL is a command-line argument of a CLI
the operator runs themselves, so no trust boundary is crossed -- anyone who can pass that argument
can already run curl. Disabling redirects (CheckRedirect returns ErrUseLastResponse) further keeps
a response from steering the request somewhere unintended.
Previously `just pre-commit` exited 1 on the security recipe. Now it exits 0 via a call-site
annotation rather than a global -exclude, so G704 still applies to any future call site.
Out of scope: pinning the gosec version. Both the Justfile and CI install gosec@latest, so a future
release can break the pipeline again with no code change on our side.
Also corrects a typo in the adjacent G402 annotation ("askef" -> "asked").
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EMMhgmTkbzAsmeNy97PrP
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.
Problem
just pre-commitfails on a clean tree: gosec's new G704 rule flags the tool's own outbound request as SSRF. Nothing in the repo changed — gosec 2.28.0 introduced the rule, and both theJustfileand CI installgosec@latest, so the failure appeared overnight and blocks every commit and every CI run until it is addressed.The taint analysis is correct about the data flow —
args[0]does reachhttp.Client.Do. It is wrong about the conclusion, for reasons the analyzer cannot see (below).Solution
Annotate the call site with
#nosec G704and a written justification, rather than excluding the rule globally.Before / after — the
securityrecipe:Why this is a false positive, not a vulnerability
SSRF requires a trust boundary: an attacker supplies a URL to a service that holds network reach the attacker lacks. Neither half holds here.
argv[1]of a CLI the operator runsCheckRedirectreturnsErrUseLastResponse)Anyone who can pass that argument can already run
curl. Fetching an operator-supplied URL is not a side effect of this program — it is the program.Why annotate instead of
gosec -exclude=G704A global exclusion in the
Justfilewould silence the rule for code that does not yet exist. If a future change fetches a URL derived from a response body or a config file — where the trust boundary is real — a global exclusion hides it, while the call-site annotation leaves the rule armed everywhere else. The repo already uses this pattern forG402.Not in scope
This does not pin the gosec version.
Justfileand.github/workflows/build.ymlboth installgosec@latest(andgolangci-lintatversion: latest), so the next upstream release can break the pipeline again with no change on our side. Pinning both and letting dependabot bump them converts "CI broke overnight" into a reviewable PR — worth doing, but it is a build-config change with a different blast radius than this one-line annotation, so it belongs in its own PR.No visual change — this repo is a headless CLI with no rendered UI.
Other Changes
Corrects a typo in the adjacent
G402annotation (askef→asked), on the sibling line of the same kind.🤖 Generated with Claude Code