cookie

package
v2.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenCookieName         = "__Host-token" // #nosec G101: cookie name label, not a credential
	InsecureTokenCookieName = "token"        // #nosec G101: cookie name label, not a credential
	OidcStateCookieName     = "oidc_state"
)

Functions

func BuildClearOidcStateCookieString

func BuildClearOidcStateCookieString(secure bool) string

BuildClearOidcStateCookieString builds a Set-Cookie header string to clear the OIDC state cookie.

func BuildClearTokenCookieStringsFor

func BuildClearTokenCookieStringsFor(secure bool) []string

BuildClearTokenCookieStringsFor builds Set-Cookie header strings to clear token cookies matching the current request security context. Secure contexts also clear the HTTP fallback cookie so stale sessions from older releases are flushed instead of being re-presented forever.

func BuildOidcStateCookieString

func BuildOidcStateCookieString(value string, maxAgeInSeconds int, secure bool) string

BuildOidcStateCookieString builds a Set-Cookie header string for the OIDC state cookie.

func BuildTokenCookieStringFor

func BuildTokenCookieStringFor(maxAgeInSeconds int, token string, secure bool) []string

BuildTokenCookieStringFor builds Set-Cookie header strings matching the current request security context. Compact browser tokens use one cookie; legacy oversized tokens are chunked for upgrade compatibility. Unused chunk slots are cleared so stale legacy chunks cannot corrupt reassembly. Callers must pass the trusted secure flag from SecureCookieFromContext / SecureCookieFromRequest so the cookie name (__Host-token vs. token) round-trips correctly behind HTTPS reverse proxies.

func ClearTokenCookie

func ClearTokenCookie(w http.ResponseWriter, r *http.Request)

func GetTokenCookie

func GetTokenCookie(r *http.Request) (string, error)

func GetTokenCookieFromHeader added in v2.10.0

func GetTokenCookieFromHeader(cookieHeader string) (string, error)

func SecureCookieFromContext

func SecureCookieFromContext(ctx context.Context) bool

SecureCookieFromContext returns the secure-cookie decision that router middleware derived from TLS or trusted proxy headers.

func SecureCookieFromRequest

func SecureCookieFromRequest(r *http.Request) bool

SecureCookieFromRequest returns true when the request was made over TLS or router middleware marked it as forwarded from HTTPS by a trusted proxy.

Types

type SecureCookieContextKey added in v2.7.0

type SecureCookieContextKey struct{}

SecureCookieContextKey is the context key under which router middleware records its trusted secure-cookie decision (a bool derived from TLS or trusted proxy headers).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL