Documentation
¶
Overview ¶
Package redirect validates where the library may send a browser or a credential and where it serves routes: same-origin return paths, login locations carrying a return path, configured external URLs and redirect targets, the endpoints of identity providers and route path prefixes. Every function is safe for concurrent use; all but To are pure.
Index ¶
- func AbsoluteTarget(raw, externalURL string) (string, error)
- func ExternalURL(raw string) (string, error)
- func IsPathPrefix(prefix string) bool
- func IsSecureURL(raw string) bool
- func IsTarget(raw string) bool
- func LoginLocation(loginURL, returnPath string) string
- func ReturnPath(request *http.Request) string
- func SafeReturnPath(raw string) (string, bool)
- func To(writer http.ResponseWriter, location string)
- func WithQuery(target string, values url.Values) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsoluteTarget ¶
AbsoluteTarget validates a configured redirect target (a provider's ErrorURL or PostLogoutURL) and returns it absolute: a same-origin path (SafeReturnPath) is prefixed with externalURL (an ExternalURL result), so a forward-auth redirect reaches the browser unchanged; an absolute http(s) URL is kept. A fragment is refused, so a query appended later (ErrorURL?code=...) stays in the query. Errors never repeat the value.
func ExternalURL ¶
ExternalURL validates an absolute http(s) URL without user info, query or fragment and trims a trailing "/". Errors never repeat the value, so a misplaced credential does not end up in a log.
func IsPathPrefix ¶
IsPathPrefix reports whether prefix can prefix a provider's routes: "/"-separated segments of unreserved URL characters (A-Z a-z 0-9 . _ ~ -), no trailing "/", and no "." or ".." segment that path cleaning would remove, so the routes are neither ServeMux wildcards nor unreachable.
func IsSecureURL ¶
IsSecureURL reports whether raw is an absolute https URL with a host name, or an http URL on a loopback host (localhost, 127.0.0.0/8, ::1), without user info: credentials never travel in clear text, tests run on 127.0.0.1 (design D16).
func IsTarget ¶
IsTarget reports whether raw is a valid redirect target that takes a query: a same-origin path (SafeReturnPath) or an absolute http(s) URL with a host, without a fragment (AbsoluteTarget's rule).
func LoginLocation ¶
LoginLocation appends return_to=<returnPath> to loginURL (keeps an existing query); empty returnPath appends nothing.
func ReturnPath ¶
ReturnPath returns SafeReturnPath(request query return_to) or "/".
func SafeReturnPath ¶
SafeReturnPath accepts only same-origin relative paths: starts with "/", second byte not "/" or "\", valid UTF-8 (JSON would store each invalid byte as six), no control characters or "\" anywhere, url.Parse succeeds with empty Scheme, Host and Opaque, <= 2048 bytes. Returns the path as sent plus "?"+RawQuery when present (fragment dropped).
func To ¶
func To(writer http.ResponseWriter, location string)
To answers 302 Found to location with Cache-Control no-store.
Types ¶
This section is empty.