Skip to content

chore(lint): enable gosec in golangci-lint - #1757

Merged
mbrandenburger merged 1 commit into
hyperledger-labs:mainfrom
mbrandenburger:gosec
Sep 8, 2026
Merged

mbrandenburger merged 1 commit into
hyperledger-labs:mainfrom
mbrandenburger:gosec

Conversation

@mbrandenburger

Copy link
Copy Markdown
Member

Enables gosec and scopes it to the code that ships. make checks is green.

This is part of #1755 and #1741

Scoping

A bare enable reports 220 findings: 95 in _test.go, 72 in the integration/ nwo harness, 1 in ci/, 52 in library code. The test and harness findings describe what that code is for — 0644 fixture certs, 0755 scratch dirs, subprocess launches with generated paths, deliberately weak TLS in benchmarks — so they are excluded by path. Four rule classes are excluded globally, each with its reasoning in .golangci.yml:

Rule Why
G304, G703 file paths come from operator-supplied core.yaml / MSP config, not untrusted input; filepath.Clean would silence without securing
G404 math/rand is retry jitter and peer/orderer load-balancing, never a secret or nonce
G115 flagged conversions are vault version encoding and proto int32 fields; truncation only past 2^32 blocks

Fixes

  • platform/view/services/grpc/client.go — VerifyPeerCertificate does not run on a resumed TLS session, so a custom certificate check could be bypassed. Disables client-side session tickets to force a full handshake (G123). The one genuine security finding in the set.
  • platform/view/services/storage/driver/sql/sqlite/persistence.go — database directory was created 0777 (world-writable), now 0750.
  • node/start/profile/profile.go — profile output directory 0755 → 0750.

Annotated false positives

  • platform/fabricx/core/vault/vault.go — unsafe.Pointer comparison is deterministic lock ordering (G103).
  • platform/fabric/core/generic/delivery/delivery.go — the nil-ctx fallback is documented behaviour, not a dropped request context (G118).

Verification

make checks exits 0 — 0 issues across all four linted modules, go fix clean. Unit tests pass for every touched package.

Follow-up

Enabling gosec surfaced an unrelated remote-OOM in comm/io/reader.go (unbounded make([]byte, l) from a wire varint when fsc.p2p.maxRecvMsgSize is 0). Tracked separately in #1756 — not in this PR.

@mbrandenburger mbrandenburger added this to the 26Q3 milestone Sep 7, 2026
@mbrandenburger mbrandenburger self-assigned this Sep 7, 2026
@mbrandenburger mbrandenburger added the testing All related to testing label Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Hey @mbrandenburger 👋 thanks for the PR!
I'm your friendly PR Helper Bot 🤖 and I'll be riding shotgun on this one, keeping track of your PR's status to help you get it approved and merged.

This comment updates automatically as you push changes -- think of it as your PR's live scoreboard!
Here's the latest:


PR Checks

✅ DCO Sign-off -- All commits have valid sign-offs. Nice work!


❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:

  • de8a4ee chore(lint): enable gosec in golangci-lint

You'll need to sign your commits with GPG (e.g. git commit -S). See the Signing Guide for a step-by-step walkthrough.


✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing!


❌ Issue Link -- This PR is not linked to any issue.

Please reference an issue using a closing keyword (e.g. Fixes #123) and ensure the issue is assigned to you. Every PR needs a home!


⏳ All checks must pass before this PR can be reviewed. You've got this!

@github-actions github-actions Bot added the status: needs revision The pull request requires changes from the author before it can be reviewed or merged label Sep 7, 2026
This was referenced Sep 7, 2026

@SaidAltury-ibm SaidAltury-ibm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mbrandenburger, LGTM. just link an issue

@mergify

mergify Bot commented Sep 8, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@mbrandenburger
mbrandenburger enabled auto-merge (squash) September 8, 2026 08:33
Enables gosec and scopes it to the code that ships.

A bare enable reports 220 findings. 95 are in _test.go files and 72 in the
integration/ harness, where 0644 fixture certs, 0755 scratch directories,
subprocess launches with generated paths and deliberately weak TLS in
benchmarks describe what that code is for; those are excluded by path.
G304/G703 are excluded because the file paths come from operator-supplied
core.yaml and MSP directory configuration rather than untrusted input, G404
because math/rand is used for retry jitter and peer/orderer load-balancing
and never for a secret, and G115 because the flagged conversions are vault
version encoding and proto int32 fields. Each exclusion carries its
reasoning in .golangci.yml.

That leaves three fixes: the gRPC client disables session tickets, because
VerifyPeerCertificate does not run on a resumed session and would otherwise
be bypassed (G123); the sqlite driver creates its database directory 0750
instead of world-writable 0777; and the profiler creates its output
directory 0750 instead of 0755.

Two findings are annotated as false positives: the unsafe.Pointer
comparison in the fabricx vault is deterministic lock ordering (G103), and
the nil-ctx fallback in delivery.Run is documented behaviour, not a dropped
request-scoped context (G118).

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
@mbrandenburger
mbrandenburger merged commit 4f1a951 into hyperledger-labs:main Sep 8, 2026
13 checks passed
@mbrandenburger
mbrandenburger deleted the gosec branch September 8, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs revision The pull request requires changes from the author before it can be reviewed or merged testing All related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants