Repository navigation
Description
Two gosec runs exist in this repo and they read different suppression directives:
- golangci-lint's gosec (
.golangci.yml) honors//nolint:gosec. This is thelintjob, and it is a required check. - The standalone gosec (
.github/workflows/security.yml:58,gosec -fmt sarif -no-fail ./...) honors only#nosec. Its SARIF becomes GitHub code scanning, which surfaces as thegoseccheck on every PR.
So a finding suppressed for one and not the other passes lint and stays open in the security tab. Found while fixing PR #263, where two such sites failed the gosec check while lint reported 0 issues.
The six sites
Each carries a //nolint:gosec with a reason, and each is an open code-scanning alert on main today:
| site | rule | alert |
|---|---|---|
internal/difftest/fs.go:70 |
G304 | #52 |
internal/awsname/awsname.go:127 |
G703 | #48 |
internal/network/congestion_linux.go:67 |
G304 | #51 |
internal/network/congestion_linux.go:84 |
G304 | #50 |
internal/storage/s3/config.go:202 |
G115 | #41 |
internal/testaws/testaws.go:33 |
G101 | #47 |
Two more were fixed in PR #263 (internal/awsrates/offerfile/cmd/genrates/main.go G306, internal/fuse/unmount_path.go G204) by adding #nosec alongside the existing //nolint.
Why this is worth fixing rather than living with
The gosec check reports new alerts in code changed by this pull request, so it only fires when a PR touches one of these lines or adds a new one. That makes it a check that passes for months and then fails on an unrelated change, in a file whose comment already explains the finding is not real. The reviewer's reasonable conclusion is that the security check is noise, which is the state a gate should never reach.
It also cuts the other way: because these alerts are permanently open, a genuine finding in the same rule family arrives into a security tab that already has six entries nobody acts on.
What to do
Not a blanket #nosec sweep. Each needs its own judgment, and two of the six look like they may be more than a suppression:
s3/config.go:202(G115,uint32(cfg.FailureThreshold)) is suppressed as "guarded positive above". Worth confirming the guard actually bounds it below 2^32 rather than only above zero — the comment claims less than the conversion needs.testaws.go:33(G101, hardcoded credential) is a test fixture, and the comment says so. But the suppression is at package scope in a file that a non-test package imports, which is a different question from whether the constant matters.
The other four read as genuinely-not-findings (procfs constants, t.TempDir() paths, an operator-supplied AWS_CONFIG_FILE) and want #nosec alongside the existing comment.
Consider also whether the two runs should be reconciled rather than double-annotated — for example, having the security workflow consume golangci-lint's gosec output, or documenting the dual-directive convention in .golangci.yml so the next person hits it in the file rather than in CI. The dual annotation is the smaller change; a single run is the one that stops this recurring.
Acceptance criteria
- Each of the six sites is either suppressed for both tools with its reason, or fixed
-
~/go/bin/gosec -no-fail ./...andgolangci-lint runagree on which findings remain - The convention is written down where someone adding a suppression will see it
- The corresponding code-scanning alerts are closed or dismissed with a reason
-
s3/config.go:202's guard is confirmed to bound the conversion, not just its sign
Activity
v0.11.0: subcommands, a security gate, and prices that know their region
fix: suppress the two gosec findings in both directive dialects
scttfrdmn commentedon Aug 3, 2026
This bit for real on #270, which is worth recording since the issue was filed from reading the two
configurations rather than from an incident.
I added
//nolint:gosecto two deliberate findings ininternal/distributed/auth.goand its test,and verified locally with
golangci-lint run --new-from-merge-base=origin/main: 0 issues. Thepull request was then blocked by a
goseccheck-run reporting1 new alert including 1 error, whichis GitHub code scanning gating on the SARIF from the standalone gosec in
security.yml— adifferent tool reading a different directive.
Two details worth having written down, because neither is obvious from either tool's documentation:
//nolint:gosecand#nosecare not interchangeable, which the issue already says.//nolint:gosec // #nosec G304 -- reasonsatisfies golangci-lint and is still reported by standalone gosec. It wants
#nosecin thetrailing comment on its own, with
//nolinton a separate line above — which is whatinternal/fuse/unmount_path.go:89-90andinternal/awsrates/offerfile/cmd/genrates/main.go:111-117already do. Both of those files carrycomments explaining the trap, so this has been learned before and is easy to re-learn the slow way.
Neither finding was fixable by changing the code: one reads a file at an operator-supplied path,
which is the function; the other writes a 0644 secret file because that is the insecure file the
loader has to refuse, so satisfying G306 would delete the test.
Whatever this issue settles on, the useful outcome is that a suppression cannot be half-applied. A
lint job reporting 0 issues while code scanning blocks the merge is the specific failure mode.
feat: authenticate gossip messages, and refuse to start without a sec…
scttfrdmn commentedon Aug 5, 2026
Two measurements from #200 that change this issue's premise. Both were made with the versions this repo uses today —
golangci-lint 2.12.2, gosec installed from@latestassecurity.ymldoes — and both were probed rather than reasoned about.#nosecalone satisfies both runs, so the dual annotation is more than is neededThe issue says golangci-lint's gosec "honors
//nolint:gosec" and the standalone run "honors only#nosec", and prescribes writing both. Only half of that holds.Probed with four sites in one package —
//nolint:gosecalone,#nosecalone, both, and neither://nolint:goseconly#noseconlygolangci-lint honors
#nosecas well, because it runs gosec's own analyser and gosec strips#nosecsites before reporting. So#nosecalone is sufficient for both runs, and the dual annotation this issue asks for adds a directive that is never the one doing the work.That doesn't change the acceptance criteria much — the six sites still need something they don't have today — but it changes what to write at each one. A single
#nosecwith its reason, rather than two directives whose relationship the next reader has to reconstruct.Worth noting the asymmetry is fully explained by which annotation each tool owns:
//nolintis golangci-lint's own mechanism and gosec has never heard of it, while#nosecis gosec's and golangci-lint inherits it by delegation.Neither directive works at all inside a cgo package
This is the part with no workaround, and it is why #200 could not be closed by suppression.
sdks/c/main.gois the module's only cgo package. Probed there with four placements — the directive on the line above the call, first of a comment block, last of a block, and trailing the call itself. In a pure-Go package all four suppress. In the cgo package none do, and gosec reportsnosec: 0, meaning it recognised no directive at all.The cause is in what gosec is given to analyse. cgo rewrites every
C.f(...)call into an inline closure carrying/*line :N:C*/directives:The call and any comment near it end up on the same synthetic position, so the association a suppression depends on is gone.
The two runs then diverge in what they do with findings neither can suppress, and the divergence is not the one this issue describes:
runner/invalid_issue: issue related to file <go-build cache path> is skipped. The analysed file is a build-cache artifact rather than a repository path. This is not the.golangci.ymlG115 exclusion doing it — lifting that exclusion still yields 0 issues for the package."artifactLocation": {}. GitHub's SARIF ingester rejects a result with no location and fails the whole upload, sosecurity.ymlwas filtering them out by hand.So for cgo the failure mode is worse than "passes lint, stays open as an alert" — the findings were reachable by neither run. Three integer conversions across a C ABI went unreviewed, and one of them was a real defect:
objectfs_putnarrowed asize_tlength to aC.int, so a 4 GiB PUT returnedOBJECTFS_OKand stored an empty object (fixed in #355).#355 also fixes the reporting half —
security.ymlnow back-fillssdks/c/main.gorather than dropping those results, since cgo's//linedirectives mean the reported line numbers are already correct andsdks/cis the only cgo package in the module. Verified by inserting eight blank lines after the import block, which moved all three findings by exactly eight.Consequence for this issue's last section
The issue asks whether the two runs should be reconciled rather than double-annotated, and calls the dual annotation "the smaller change". Given the above, the dual annotation is not just larger than necessary — it is a no-op at one of the two directives everywhere, and a no-op at both inside
sdks/c. Reconciling to a single run looks better than it did when this was filed.sdks/cshould be carved out either way, and stated as such wherever the convention is documented: no suppression directive works there, so a finding in that package has to be fixed or the reason recorded in a plain comment.main.go's header comment now says this, including the negative result thatCGO_ENABLED=0 gosec ./sdks/c/...analyses zero files (the package cannot build without cgo) and so is a vacuous pass rather than an escape hatch.Also, on the two sites this issue flags as possibly more than suppressions —
s3/config.go:202(whether the G115 guard bounds below 2^32, not only above zero) andtestaws.go:33(G101 at package scope in a file a non-test package imports) — neither was examined as part of #200. They stay open here.scttfrdmn commentedon Aug 5, 2026
Fixed in #356. Three notes for anyone reading this issue rather than the PR, since two of them contradict what the issue asks for.
The prescribed fix fails lint. This issue says to write both
#nosec Gxxxand//nolint:gosecso that each run sees a directive it understands. golangci-lint runs gosec's own analyser, which strips#nosecsites before golangci-lint sees them — so#nosecalone already satisfies both runs, and adding the//nolint:gosecleaves it with nothing to suppress, at which pointnolintlintreports it unused. Writing both converts a suppression into a lint failure.#nosecalone is the convention, now written down at.golangci.yml's gosec settings.G703is not in the gosec golangci-lint bundles. Probed on a two-line program that readsos.Getenvand passes the result toos.ReadFile: standalone gosec reportsG703andG304; golangci-lint reportsG304alone. So the//nolint:gosecatinternal/awsname/awsname.gowas not merely suppressing for the wrong run — the run it targeted never had that finding to suppress.One of the six was hiding a real defect, which is the half of this issue I had explicitly left open above.
internal/storage/s3/config.go's//nolintjustification read "guarded positive above", referring toif cfg.FailureThreshold <= 0. That guard bounds the sign and not the width.failure_threshold: 4294967296passes it, narrows to0through theuint32conversion, and yields the predicateTotalFailures >= 0— true on the zeroth failure, so the circuit breaker opens before the first request and rejects every S3 operation for the life of the mount.4294967297narrows to1, which is quieter and worse: a breaker tripping on one failure while the config says four billion. Now clamped, with four mutations of the clamp detected by test.It was invisible to both runners at once, in opposite ways:
.golangci.ymlexcludesG115repo-wide so golangci-lint never had the finding, and the standalone run that did have it is not gating anything. That combination — excluded from one runner, suppressed for the other — is the general hazard behind this issue, and it is worth more than the six sites named here.Also fixed along the way: twelve
// nolintdirectives across nine files had a leading space, which makes them ordinary comments rather than directives. Every one was inert, each with a full paragraph of justification attached to nothing. Eleven further//nolints had no explanation; five of those werestaticcheckfindings that were simply fixable, so they are fixed rather than annotated.nolintlintis at 0, down from 23.