Documentation
¶
Index ¶
- Constants
- func CORSMiddleware() func(http.Handler) http.Handler
- 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 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 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 CORSMiddleware ¶
CORSMiddleware 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 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 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 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.