Documentation
¶
Index ¶
- Constants
- func AddVaryOrigin(w http.ResponseWriter)
- func CSRFCookie(value string, sameSite http.SameSite, domain string) http.Cookie
- func CSRFCookieString(value string, sameSite http.SameSite, domain string) string
- func CSRFMiddleware(next http.Handler) http.Handler
- func CSRFMiddlewareWithExemptions(exemptSuffixes []string) func(http.Handler) http.Handler
- func DenyAllOriginsMiddleware() func(http.Handler) http.Handler
- func ExpiredRefreshCookie(sameSite http.SameSite, domain string, path string) http.Cookie
- func ExpiredRefreshCookieString(sameSite http.SameSite, domain string, path string) string
- func ExpiredSessionCookie(sameSite http.SameSite, domain string) http.Cookie
- func ExpiredSessionCookieString(sameSite http.SameSite, domain string) string
- func HasOrigin(r *http.Request) bool
- func MirrorCORSMiddleware() func(http.Handler) http.Handler
- func RefreshCookie(value string, sameSite http.SameSite, domain string, path string) http.Cookie
- func RefreshCookieString(value string, sameSite http.SameSite, domain string, path string) string
- func SelectCORSMiddleware(allowedOrigins []string, allowAll, denyAll bool) func(http.Handler) http.Handler
- func SessionCookie(value string, sameSite http.SameSite, domain string) http.Cookie
- func SessionCookieString(value string, sameSite http.SameSite, domain string) string
- func SetCORSHeaders(w http.ResponseWriter, origin string)
- func StripKerberosCookies(r *http.Request)
- func WhitelistCORSMiddleware(allowedOrigins []string) func(http.Handler) http.Handler
Constants ¶
const ( // CSRFTokenHeader is the name of the header used to send the CSRF token in requests. //nolint:gosec // really? CSRFTokenHeader = "X-Krb-Csrf-Token" SessionCookieName = "session" SessionMaxAge = 15 * time.Minute RefreshCookieName = "refresh" RefreshMaxAge = 1 * time.Hour CSRFCookieName = "csrf" CSRFMaxAge = RefreshMaxAge )
Variables ¶
This section is empty.
Functions ¶
func AddVaryOrigin ¶ added in v1.9.0
func AddVaryOrigin(w http.ResponseWriter)
AddVaryOrigin marks the response as depending on the request's Origin header, so that caches do not serve a response built for one origin to a request from another. Call it for every response whose CORS handling looks at the Origin header, including requests without one: otherwise a cached response to a request without Origin, which has no CORS headers, can be served to a browser request for the same URL.
func CSRFCookie ¶ added in v1.3.0
CSRFCookie creates a new CSRF cookie with the given value, SameSite attribute, and domain.
func CSRFCookieString ¶ added in v1.3.0
CSRFCookieString creates a new CSRF cookie with the given value, SameSite attribute, and domain, and returns its string representation.
func CSRFMiddleware ¶
CSRFMiddleware is an HTTP middleware that checks for the presence of a valid CSRF token in requests. It should be used for all endpoints that modify state (e.g., POST, PUT, DELETE).
func CSRFMiddlewareWithExemptions ¶
CSRFMiddlewareWithExemptions is an HTTP middleware that checks for the presence of a valid CSRF token in requests, with the ability to exempt certain request paths from CSRF protection.
func DenyAllOriginsMiddleware ¶ added in v1.3.0
func ExpiredRefreshCookie ¶ added in v1.3.0
ExpiredRefreshCookie returns an http.Cookie struct representing an expired refresh cookie with the given SameSite attribute, domain, and path.
func ExpiredRefreshCookieString ¶ added in v1.3.0
ExpiredRefreshCookieString returns a string representation of an expired refresh cookie with the given SameSite attribute, domain, and path.
func ExpiredSessionCookie ¶ added in v1.3.0
ExpiredSessionCookie returns an http.Cookie struct representing an expired session cookie with the given SameSite attribute and domain.
func ExpiredSessionCookieString ¶ added in v1.3.0
ExpiredSessionCookieString returns a string representation of an expired session cookie with the given SameSite attribute and domain.
func MirrorCORSMiddleware ¶ added in v1.4.0
MirrorCORSMiddleware is a middleware that adds CORS headers to the response. Input Origin are mirrored back in the Access-Control-Allow-Origin header, allowing any origin to access the resource.
func RefreshCookie ¶ added in v1.3.0
RefreshCookie returns an http.Cookie struct representing a refresh cookie with the given value, SameSite attribute, domain, and path.
func RefreshCookieString ¶ added in v1.3.0
func RefreshCookieString( value string, sameSite http.SameSite, domain string, path string, ) string
RefreshCookieString returns a string representation of a refresh cookie with the given value, SameSite attribute, domain, and path.
func SelectCORSMiddleware ¶ added in v1.3.0
func SelectCORSMiddleware( allowedOrigins []string, allowAll, denyAll bool, ) func(http.Handler) http.Handler
SelectCORSMiddleware selects the appropriate CORS middleware based on the provided configuration. If denyAll is true, it returns the DenyAllOriginsMiddleware that denies all origins. If allowAll is true, it returns the CORSMiddleware that allows all origins. If allowedOrigins is non-empty, it returns the WhitelistCORSMiddleware that allows only the specified origins. If neither condition is met, it returns a passthrough handler without any CORS validation.
func SessionCookie ¶ added in v1.3.0
SessionCookie returns an http.Cookie struct representing a session cookie with the given value, SameSite attribute, and domain.
func SessionCookieString ¶ added in v1.3.0
SessionCookieString returns a string representation of a session cookie with the given value, SameSite attribute, and domain.
func SetCORSHeaders ¶ added in v1.3.0
func SetCORSHeaders(w http.ResponseWriter, origin string)
SetCORSHeaders sets the necessary CORS headers on the response writer for the given origin.
func StripKerberosCookies ¶ added in v1.9.0
StripKerberosCookies removes the Kerberos session, refresh and CSRF cookies from the request, so they are not sent on to backends or proxied tools. Other cookies are kept.
func WhitelistCORSMiddleware ¶ added in v1.2.0
WhitelistCORSMiddleware is a middleware that adds CORS headers to the response for requests from allowed origins. Non-whitelisted origins will receive a 403 Forbidden response.
Types ¶
This section is empty.