Security
The security model — password hashing, CSRF, sessions, Tokens and logging.
Signet is secure by default. Insecure behaviour requires an explicit Insecure* option,
which emits a warning through your logger. See Configuration.
Password verifiers
The default Argon2idHasher uses OWASP-recommended parameters: 19 MiB memory (m=19456),
2 iterations (t=2), parallelism 1 (p=1), 32-byte key and 16-byte salt. Verifiers are PHC
strings ($argon2id$v=19$m=...$...$...). Parsed parameters are bounded (max 256 MiB memory,
10 iterations, 16 threads, 128-byte key, 64-byte salt) so a tampered verifier cannot trigger
unbounded work.
On successful sign-in, NeedsRehash upgrades verifiers with stale parameters and stores the
new hash without failing the sign-in. The hash/bcrypt adapter provides Hasher{Cost: int}
with DefaultCost = 12 for interoperability.
Anti-enumeration
Sign-in failures are generic (ErrInvalidCredentials) for an unknown email, a disabled
User or a password mismatch. A dummy verifier is hashed once at New and verified on the
unknown-user path so the work is comparable. Emails are lowercased and trimmed. Email send
flows return success for unknown addresses while doing equalized work.
Sessions and cookies
Session Tokens are 32-byte opaque values; only their SHA-256 digest is stored. Session IDs
are 16-byte hex. Idle deadlines extend on success, absolute deadlines never change, and
revoked or expired Sessions — and Sessions of disabled Users — are rejected. Cookies are
HttpOnly, Secure, SameSite=Lax, with __Host- where Secure, Path=/ and no Domain.
SessionInfo never includes a token digest.
CSRF
A CSRF token is HMAC-SHA256 over <nonce>.<expiry> with a 24-byte nonce and 12-hour TTL.
It is returned by GET /csrf-token and in the sign-in response, stored in a readable
cookie, and sent in X-CSRF-Token. State-changing requests (POST/PUT/PATCH/DELETE) that
carry a session cookie are also checked against Origin (host and scheme) and
Sec-Fetch-Site (same-origin or none). Rejections log csrf_rejected. Headerless API
clients can use JWT mode instead.
Tokens
Verification, reset, OAuth state/link, magic-link, email-OTP and refresh proofs are random,
single-use and stored only as digests. ConsumeToken is an atomic conditional update, and
digests are compared in constant time. Expired Tokens are rejected. An OTP stores
Digest(email + ":" + code), so neither the raw code nor a reusable secret is persisted.
Refresh replay is containment, not just an error: all Sessions and all Token kinds for that
User are revoked and ErrRefreshReuse is returned.
Passwordless callbacks use the same exact-match allowlist as OAuth: a URL must appear in
Passwordless.AllowedRedirects, OAuth.AllowedRedirects, or equal AppURL. A same-origin
but unlisted path is rejected. Unknown emails produce a silent success with no mail and no
proof when AllowSignUp is false, and failed OTP guesses are throttled through the
RateLimiter keyed by email and client IP.
Username, account changes and Second factor
A Username is normalized and validated before it is stored as an Account; a failed sign-in is
generic whether the Username exists or the password is wrong. Unlinking requires a Session within
Accounts.FreshWindow and refuses to remove a User's last Account, because a Second factor alone
cannot sign in.
TOTP secrets are encrypted with a dedicated key and Backup codes are stored only as digests. A Two-factor challenge is a single-use Token: a wrong code does not consume it, but five failed attempts are throttled through the rate limiter. Challenges expire after five minutes, enrollment is inactive until a first code succeeds, and the JWT token exchange returns a challenge rather than tokens for enrolled Users.
Opt-in defensive controls
Signet offers four opt-in controls; none changes the default authentication path.
- A Breach check rejects passwords found in a known breach on sign-up, password change and reset. The application supplies the adapter and owns the k-anonymity call; only the first five SHA-1 hex characters leave the application.
- A Captcha check runs after rate limiting on configured endpoints. The HTTP adapter reads
X-Captcha-Responseand passes the trusted-proxy-aware client IP to the verifier. An outage returnscaptcha_unavailable(503), distinct from a rejected token (invalid_input, 400). - An Audit sink receives a deliberate security subset of events with optional actor, Session ID and safe metadata. No password, verifier, token or code is ever included, and sink failures never fail a request.
- Last sign-in method is a signed, HttpOnly cookie with a consent callback. It adds no database column, cannot be forged by the client, and can be skipped without failing sign-in.
See Defensive controls for configuration and examples.
Key rotation and redirect patterns
Signing keys can be supplied as an ordered ring for both CSRF and JWT: the first key signs and all keys verify, so rotation does not invalidate live proofs. Rings are additive — the legacy single-key fields still work. JWKS publication is a separate opt-in handler and exposes only public, asymmetric keys.
Redirect allowlists accept optional https wildcard patterns such as https://*.example.com.
Exact matches still win, the AppURL fallback is unchanged, and CSRF same-origin checks are never
widened by a pattern. An invalid pattern is rejected when the Client is built.
OAuth
Authorization Code with PKCE S256; the state is AES-GCM sealed with a 32-byte StateKey,
expires after 10 minutes and is consumed once. Redirects must match the exact allowlist at
both start and callback. Only verified provider emails are auto-linked; an unverified
identity yields an encrypted link Token for explicit linking. Provider Accounts owned by
another User return ErrOAuthAccountConflict.
Logging and hooks
Structured events go to Config.Logger. Hooks (OnSignUp, OnSignIn) receive a redacted
User with email and name blanked. Logs carry User IDs and reason codes — never passwords,
raw Tokens or session secrets. The InsecureAllowHTTPCookies and InsecureDisableCSRF
options warn explicitly when enabled.
Rate-limit keys and proxies
Rate-limit keys are endpoint+"|"+clientIP. By default clientIP is the connection address.
Config.TrustedProxies lists CIDR ranges allowed to supply X-Forwarded-For; the chain is
walked right-to-left to the first untrusted hop so a client cannot spoof its own key.