Expand description
Encrypted client-side session cookies.
The primitive that lets stateless SSO plugins (openid-connect,
cas-auth, authz-casdoor) run interactive login flows without any
server-side session store: the session payload (tokens, claims, or the
transient auth-flow state) is sealed into an authenticated, encrypted
cookie with an embedded expiry. Any gateway instance sharing the signing
secret can open any cookie, so this works across a horizontally-scaled
deployment with no coordination.
Sealing uses AES-256-GCM (via ring) with a per-message random nonce; the
256-bit key is derived from the configured secret by SHA-256, so a secret
of any length is accepted. The expiry is part of the authenticated
plaintext, so it cannot be tampered with.
Trade-offs inherent to client-side sessions (shared with APISIX’s default cookie sessions): there is no cheap server-side revocation before expiry (use short lifetimes), and cookies are capped near 4 KB, so only essential data should be stored.
Structs§
- Cookie
Attrs - Attributes for building a
Set-Cookieheader value. - Cookie
Sealer - Seals and opens encrypted session cookies with a fixed derived key.
Enums§
- Cookie
Error - Failure opening a sealed cookie. Every variant means “treat the request as unauthenticated” — callers should never distinguish these to a client.
- Same
Site SameSiteattribute for aSet-Cookieheader.
Functions§
- build_
set_ cookie - Builds a
Set-Cookieheader value forname=valuewithattrs. - delete_
cookie - A
Max-Age=0deletion cookie forname. - now_
unix 🔒 - path_
covers - Whether a cookie scoped to
cookie_pathis sent by the browser on a request torequest_path(RFC 6265 §5.1.4 path-match): an exact match, orcookie_pathis a prefix ending at a/boundary./(or empty) covers everything. - read_
cookie - Reads a named cookie from a
Cookieheader value (a=1; b=2).