Documentation
¶
Overview ¶
Code generated by apic; DO NOT EDIT.
Package csrfx implements stateless, HMAC-signed, session-bound CSRF tokens using the signed double-submit pattern (OWASP). A token embeds a random nonce, an expiry, and an HMAC binding it to a session identifier; the generated middleware additionally requires the cookie value to equal the header value (double-submit) before verifying the signature. Code generated by apic; DO NOT EDIT.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCSRFMalformed indicates the token is not valid base64url or has the // wrong length/version. ErrCSRFMalformed = errors.New("csrfx: malformed token") // ErrCSRFExpired indicates the token's embedded expiry is in the past. ErrCSRFExpired = errors.New("csrfx: token expired") // ErrCSRFMismatch indicates the HMAC did not verify (tampered token or // wrong key) or the double-submit cookie/header pair did not match. ErrCSRFMismatch = errors.New("csrfx: token signature mismatch") // ErrCSRFSessionMismatch indicates the token was issued for a different // session than the one presenting it. ErrCSRFSessionMismatch = errors.New("csrfx: token session mismatch") // ErrCSRFUnbound indicates Verify was called with an empty sessionID. // Issue("") still mints a token bound to "" (used for the best-effort // pre-login /csrf mint, see api.go.tmpl) but Verify refuses to accept // ANY token — even one whose signature is otherwise valid — against an // empty session: every caller lacking a session would collapse onto the // same "" binding, making a pre-login-minted token replayable by anyone // who never authenticates (SEC-0061). Callers must resolve a real // session id (typically the verified JWT "sub") before Verify. ErrCSRFUnbound = errors.New("csrfx: token not bound to a session") // ErrKeyTooShort indicates the signing key is shorter than the 32-byte // minimum. ErrKeyTooShort = errors.New("csrfx: signing key must be at least 32 bytes") )
Functions ¶
This section is empty.
Types ¶
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer issues and verifies signed, session-bound CSRF tokens.
func (*Signer) Verify ¶
Verify checks the token's signature, session binding, and expiry. A token minted for a different session fails the HMAC check and returns ErrCSRFMismatch (the binding is cryptographic, so wrong-session and tamper are indistinguishable at this layer).
SEC-0061: an empty sessionID is refused unconditionally with ErrCSRFUnbound, before the token is even decoded. Issue("") remains legal (the pre-login /csrf mint binds to "" and re-mints once the caller authenticates), but Verify treating "" as a valid binding would let every unauthenticated caller share and replay the same token.