Repository navigation
fix: suppressions that suppress, and the defect one of them hid - #356
Merged
Merged
Conversation
Issue #264 lists six gosec findings annotated with //nolint:gosec, which golangci-lint honours and gosec's own run does not, so each passes lint and stays open as a code-scanning alert. Both halves of that are true. Two of the issue's premises are not, and one of the six sites was hiding a real defect. The defect is at internal/storage/s3/config.go. readyToTrip converts the configured int failure threshold to the uint32 that circuit.Counts.TotalFailures is, guarded by `if cfg.FailureThreshold <= 0` and annotated "guarded positive above". That is true and insufficient: the guard bounds the sign, not the width. On a 64-bit platform failure_threshold: 4294967296 passes it, narrows to 0, and produces the predicate `TotalFailures >= 0` — true on the zeroth failure. The breaker opens before the first request and rejects every S3 operation for the life of the mount, which is exactly the outcome the function's own zero case exists to prevent, arriving by the one path that bypassed it. 4294967297 is the quieter half: a threshold of 1, so the breaker trips on a single failure while the configuration says four billion. Measured in a standalone probe, not reasoned about. It is now clamped to math.MaxUint32, above which no count of failures can reach the threshold anyway — unreachable is the honest reading of an unreachable number, and clamping keeps this a total function rather than adding a second validation site next to internal/config's. Four mutations are detected by TestCircuitBreakerConfigReachesTheBreaker: removing the clamp, > for >=, bounding at MaxInt32, and restoring the always-true predicate. Why neither run reported it. .golangci.yml excludes G115 repo-wide, so golangci-lint never had the finding; the //nolint form meant the standalone run that did have it was not being asked to skip it, but that run was not gating anything either. A finding excluded from one runner and suppressed for the other is invisible in both directions. The two premises that do not hold, both probed: #nosec alone satisfies both runs, and writing both directives fails lint. golangci-lint runs gosec's own analyser, which strips #nosec sites before golangci-lint sees them, so the dual annotation the issue prescribes leaves the //nolint:gosec with nothing to suppress and nolintlint reports it unused. The prescription converts a suppression into a lint failure. G703 is not in the gosec golangci-lint bundles. On a two-line os.Getenv program, standalone gosec reports G703 and G304; golangci-lint reports G304 alone. The //nolint:gosec at internal/awsname could not have worked even written correctly. Twelve //nolint directives across nine files had a leading space, which makes them ordinary comments — only //nolint: is a directive — each with a paragraph of justification attached to nothing. Eleven more had no explanation, which nolintlint's require-explanation reports. Five of those were staticcheck findings that were simply fixable (two QF1008 embedded selectors, two QF1003 if-chains wanting a tagged switch, one QF1012 WriteString(Sprintf)), so they are fixed rather than annotated. The two switch rewrites needed default arms, which .golangci.yml's default-signifies-exhaustive accepts and which say why the remaining statuses and op types belong together. nolintlint: 23 findings to 0. testaws.SecretAccessKey's G101 argument was that it is AWS's own documentation example key, accepted only by the emulator. True and not the whole risk: the constant is at package scope in testaws.go, not a _test.go, so the filename keeps neither it nor the embedded emulator out of a shipped binary. What does is that no non-test package imports testaws, a property of the import graph that drifts silently. TestNoNonTestPackageImportsThisOne asserts it with `go list -deps`, whose Imports field is the non-test import set. Verifying that test took two attempts and both failure modes are recorded in it: `go test` runs each binary in its own package directory, so the first ./... saw only internal/testaws while a deliberate violation sat in internal/awsrates/offerfile; and the mutation needs -count=1, because a violation in another package leaves this binary byte-identical and the cached pass is served. The convention is written down at .golangci.yml's gosec settings, since that is where someone adding a suppression will be. Recorded there too: no directive of either form works in a cgo package, and congestion_linux.go is linux-only so a //nolint there is unverifiable from a macOS machine. The jumbo test cases are guarded by `if math.MaxInt > math.MaxUint32` and take their values from int64 variables. The guard alone is not enough: it stops the block executing, not compiling, and a constant conversion is checked at compile time — so the literal form failed `go vet` under GOARCH=386 with "overflows int". CI type-checks tests on every cross-build cell, which is where that surfaced. Whole-repo golangci-lint is unchanged at 615, standalone gosec nosec 4 to 10 with all six sites gone from its output, go test -race clean across 38 packages, and native, linux/386 and linux/arm/7 all build and vet. Closes #264
…-directives-264 # Conflicts: # CHANGELOG.md
…-directives-264 # Conflicts: # CHANGELOG.md
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.
Closes #264.
The issue is right that six gosec findings are annotated with
//nolint:gosec, which golangci-lint honours and gosec's own run does not — so each passes lint and stays open as a code-scanning alert. Two of its premises turn out not to hold, and one of the six sites was hiding a real defect.The defect
internal/storage/s3/config.go'sreadyToTripconverts the configuredintfailure threshold to theuint32thatcircuit.Counts.TotalFailuresis, guarded byif cfg.FailureThreshold <= 0and annotated "guarded positive above". That is true and insufficient: the guard bounds the sign, not the width.uint32(4294967296)is0, so the predicate becomesTotalFailures >= 0— true on the zeroth failure. The breaker opens before the first request and rejects every S3 operation for the life of the mount, which is precisely the outcome the function's own zero case exists to prevent, arriving by the one path that bypassed it.4294967297is the quieter half: a threshold of1, so the breaker trips on a single failure while the configuration says four billion. Measured in a standalone probe.Now clamped to
math.MaxUint32, above which no count of failures can reach the threshold anyway — unreachable is the honest reading of an unreachable number, and clamping keeps this a total function rather than adding a second validation site next tointernal/config's.Why neither run reported it.
.golangci.ymlexcludesG115repo-wide, so golangci-lint never had the finding; the//nolintform meant the standalone run that did have it was not being asked to skip it — but that run gates nothing. A finding excluded from one runner and suppressed for the other is invisible in both directions.Two premises corrected, both by measurement
#nosecalone satisfies both runs, and writing both directives fails lint. golangci-lint runs gosec's own analyser, which strips#nosecsites before golangci-lint sees them. So the dual annotation the issue prescribes leaves the//nolint:gosecwith nothing to suppress andnolintlintreports it unused — turning a suppression into a lint failure.G703is not in the gosec golangci-lint bundles. Probed on a two-lineos.Getenv→os.ReadFileprogram: standalone gosec reportsG703andG304; golangci-lint reportsG304alone. The//nolint:gosecatinternal/awsnamecould not have worked even written correctly.Twelve directives that were not directives
// nolint:gosecwith a leading space is an ordinary comment; only//nolint:is a directive. Twelve sites across nine files carried the spaced form, each with a paragraph of justification attached to nothing. Eleven more had no explanation at all, whichnolintlint'srequire-explanationreports. Five of those werestaticcheckfindings that were simply fixable — twoQF1008embedded selectors, twoQF1003if-chains wanting a tagged switch, oneQF1012WriteString(Sprintf(...))— so they are fixed rather than annotated.nolintlint: 23 → 0.The hardcoded credential is now provably test-only
testaws.SecretAccessKey'sG101argument was that it is AWS's own documentation example key, accepted only by the substrate emulator. True, and not the whole risk: the constant is at package scope intestaws.go, not a_test.go, so the filename keeps neither it nor the embedded emulator out of a shipped binary. What does is that no non-test package importstestaws— a property of the import graph that drifts silently.TestNoNonTestPackageImportsThisOneasserts it withgo list -deps, whoseImportsfield is the non-test import set. Verifying it took two attempts and both failure modes are recorded in the test:go testruns each binary in its own package directory, so the first./...saw onlyinternal/testawswhile a deliberate violation sat ininternal/awsrates/offerfile; and the mutation needs-count=1, since a violation in another package leaves this binary byte-identical and the cached pass is served.Verification
>→>=, bounding atMaxInt32, restoring the always-true predicate. Each fails with the message naming its own rationale.if math.MaxInt > math.MaxUint32and take their values fromint64variables. The guard alone is not enough: it stops the block executing, not compiling, and a constant conversion is checked at compile time — the literal form failedgo vetunderGOARCH=386with "overflows int". CI type-checks tests on every cross-build cell, which is where that surfaced.go test -race -timeout 25m ./...— exit 0, 38 packages.golangci-lint615, unchanged from this branch's merge base;--new-from-merge-base=origin/main0 issues.nosec4 → 10, all six sites gone from its output.go vetandgofmtclean; native,linux/386andlinux/arm/7all build and vet.markdownlintonCHANGELOG.mdat the 361 baseline — the existing[#264]link definition was reused rather than duplicated.All four of #264's acceptance criteria are addressed: each site suppressed for the run that reports it, both runners agreeing, the convention written down at
.golangci.yml's gosec settings where someone adding a suppression will be, andconfig.go's guard confirmed not to bound the conversion — and fixed.