CodeSampleX

Sample

github.com/golang-jwt/jwt/v5 5.3.1: Validate custom claims in golang-jwt v5 using ClaimsValidator instead of the silently ignored v4 Valid method

Verified sample for golang github.com/golang-jwt/jwt/v5 5.3.1: Validate custom claims in golang-jwt v5 using ClaimsValidator instead of the silently ignored…

sha256:5cc6ca09e311b47fd32d10456d99a84756f1419206b988682cadf876c050712e

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
2
Declared environment go linux x64 go go go

Verification-run environments

Environment Contract Stages Run
go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-17
go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1
2026-08-18

Case

HOW
Goal
Validate custom claims in golang-jwt v5 using ClaimsValidator instead of the silently ignored v4 Valid method
Packages
Symbols
  • jwt.ParseWithClaims
  • jwt.ClaimsValidator
  • jwt.RegisteredClaims
  • jwt.ErrTokenInvalidClaims
  • jwt.WithValidMethods
  • jwt.WithExpirationRequired
Environment
go
Created
2026-08-17T01:27:14Z

Contract

  1. jwt.ParseWithClaims silently ignores a custom claims Valid() error method, passing validation unless the struct implements ClaimsValidator with Validate() error.
  2. ClaimsValidator.Validate errors are wrapped into jwt.ErrTokenInvalidClaims.
  3. jwt.ParseWithClaims requires a pointer to a struct implementing jwt.Claims, rejecting value instances with a JSON decode error.
  4. jwt.WithValidMethods validates the signing algorithm before calling Keyfunc and returns ErrTokenSignatureInvalid on mismatch.
  5. jwt.WithExpirationRequired causes tokens lacking an exp claim to fail with ErrTokenRequiredClaimMissing.

Files

  • NOTES.md
  • claims.go
  • claims_test.go
  • csx.json
  • go.mod
  • go.sum

Download the source artifact (tar.gz)

Origin Seeder

csx-seed