Documentation
¶
Overview ¶
Package jwt implements JWT (JSON Web Token) security analysis.
Source reference: jwt_tool (MIT, ticarpi) + jwt-auditor (MIT) + PortSwigger JWT attacks research + RFC 7519. Detection logic reimplemented from scratch.
JWT vulnerabilities detected:
- "none" algorithm attack: modify header to alg=none, strip signature
- Algorithm confusion (RS256→HS256): use public key as HMAC secret
- Weak secret brute-force: try common/default secrets (HS256/384/512)
- Empty password HS256: sign with empty string secret
- Header injection: inject kid=/dev/null or jwk/jku pointing to attacker
- Expiry analysis: token already expired, or very long-lived (> 30 days)
- Sensitive claims: sub/email/admin/role fields in payload
- Missing or weak algorithm in header
Input modes:
- Token via Options["token"]
- Token extracted from Authorization: Bearer header (from target URL response)
- Cookie values starting with "eyJ" (base64 JWT prefix)
- RawContent containing JWT-like strings
Architecture:
- Check struct: ID, Run func, Severity, Tags
- parseJWT: base64url decode header + payload (no signature verification)
- No external JWT libraries — pure stdlib base64/json
- errgroup.SetLimit(Parallelism) fan-out per check
- log/slog observability
- sync.Mutex protecting findings slice
- NewWithClient(*http.Client) for testability
Index ¶
Constants ¶
View Source
const ( DefaultTimeout = 10 * time.Second DefaultParallelism = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Check ¶
type Check struct {
ID string
Severity module.Severity
Tags []string
Run func(ctx context.Context, parsed *ParsedJWT, target string) *module.Finding
}
Check defines a JWT security test.
type JWTHeader ¶
type JWTHeader struct {
Alg string `json:"alg"`
Typ string `json:"typ"`
Kid string `json:"kid,omitempty"`
Jwk interface{} `json:"jwk,omitempty"`
Jku string `json:"jku,omitempty"`
}
JWTHeader represents a decoded JWT header.
type JWTPayload ¶
type JWTPayload struct {
Sub string `json:"sub,omitempty"`
Iss string `json:"iss,omitempty"`
Aud interface{} `json:"aud,omitempty"`
Exp int64 `json:"exp,omitempty"`
Iat int64 `json:"iat,omitempty"`
Nbf int64 `json:"nbf,omitempty"`
JTI string `json:"jti,omitempty"`
Raw map[string]json.RawMessage `json:"-"`
}
JWTPayload represents a decoded JWT payload.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements JWT security analysis.
func NewWithClient ¶
NewWithClient returns a Module using the supplied HTTP client.
Click to show internal directories.
Click to hide internal directories.