golang/go

x/tools/go/analysis/structtag: stricter JSON tag checking

Open

#74.376 aperta il 25 giu 2025

Vedi su GitHub
 (6 commenti) (11 reazioni) (0 assegnatari)Go (19.008 fork)batch import
AnalysisProposalProposal-Acceptedhelp wanted

Metriche repository

Star
 (133.883 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Background: This recent article https://blog.trailofbits.com/2025/06/17/unexpected-security-footguns-in-gos-parsers/ describes (among other things) a number of security weaknesses in Go's encoding/json package. Some of these could be mitigated by better static checking of struct field tags; indeed, the author of the post links to two semgrep rules that enforce these checks. Specifically:

  • semgrep -c r/trailofbits.go.unmarshal-tag-is-dash
  • semgrep -c r/trailofbits.go.unmarshal-tag-is-omitempty

Proposal: Let's add these two checks to the structtag analyzer so that users get immediate feedback in their LSP-enabled editor, and whenever they run go vet.

Guida contributor