How to test JWT security in Go

Use Go to confirm your API rejects forged JWTs. Generate educational attack variants with the browser JWT Fuzzer (tampered payloads, expired exp, alg:none), then assert failures with golang-jwt Parse with alg checks. Only test systems you own or have written authorization to assess — never attack third-party production.

Last updated August 26, 2026

Steps

  1. 1

    Paste a development JWT you own into the JWT Fuzzer and generate test variants.

  2. 2

    Note which variants you will try: invalid signature, expired exp, and algorithm confusion (alg:none).

  3. 3

    In Go, call your verifier with golang-jwt Parse with alg checks and assert each variant is rejected.

  4. 4

    Pin an explicit algorithm allowlist in production so unexpected algs cannot slip through.

  5. 5

    Document results in your security checklist; do not run these tests against unauthorized targets.

Code Example

Go
import (
    "fmt"

    "github.com/golang-jwt/jwt/v5"
)

// AUTHORIZED / LAB USE ONLY — paste variants from the JWT Fuzzer
token, err := jwt.Parse(tokenString, func(t *jwt.Token) (interface{}, error) {
    if t.Method.Alg() != "HS256" {
        return nil, fmt.Errorf("unexpected alg %s", t.Method.Alg())
    }
    return []byte(secret), nil
})
if err == nil && token.Valid {
    panic("expected fuzzer variant to be rejected")
}
// Never run against systems you do not own or lack written authorization to test
Open JWT Fuzzer

Other languages

Related Articles

Frequently Asked Questions

Is JWT fuzzing legal?

Only test systems you own or have explicit written authorization to test. Unauthorized probing can violate laws and terms of service.

How should Go reject bad JWTs?

Use golang-jwt Parse with alg checks with an algorithm allowlist, validate exp/nbf, and treat any verify failure as 401. Never fall back to decode-only when authentication fails.

What does the JWT Fuzzer simulate?

Common failure modes: tampered payloads, invalid signatures, expired tokens, and algorithm confusion such as alg:none. It is an educational helper for development labs.

Should my API accept alg:none?

Never. Always specify allowed algorithms in your JWT library and reject tokens that advertise none or any algorithm outside the allowlist.