Documentation
¶
Overview ¶
Package sameorigin keeps credentials on the origin they were meant for.
net/http copies custom request headers, such as Coder-Session-Token, to every redirect target. It strips only Authorization, Cookie and similar headers on a cross-domain hop. Every Coder client that sends the operator token sets RedirectPolicy as its CheckRedirect, so a redirect to another origin fails instead of sending the token there.
codersdk dials websockets with a new http.Client that copies only the Transport, so CheckRedirect does not apply there. A client that can dial a websocket also wraps its Transport with RoundTripper, which refuses every request that leaves the origin.
Index ¶
Constants ¶
const MaxRedirects = 10
MaxRedirects matches the limit of net/http's default redirect policy.
Variables ¶
var ErrCrossOrigin = errors.New("refusing redirect to a different origin than the coder URL")
ErrCrossOrigin is the error that RedirectPolicy returns for a redirect to a different origin. The message does not name the redirect target. net/http still wraps it in a *url.Error that names the target.
var ErrCrossOriginRequest = errors.New("refusing request to a different origin than the coder URL")
ErrCrossOriginRequest is the error that RoundTripper returns for a request to a different origin. The request can be a redirect that a client without RedirectPolicy follows, or a direct call, so the message does not say "redirect". net/http wraps it in a *url.Error that names the target.
Functions ¶
func RedirectPolicy ¶
RedirectPolicy returns a CheckRedirect function that follows a redirect only when it stays on the origin of origin, and stops after MaxRedirects.
func RoundTripper ¶
func RoundTripper(origin *url.URL, base http.RoundTripper) http.RoundTripper
RoundTripper returns an http.RoundTripper that sends a request through base only when the request URL is on the origin of origin. It returns ErrCrossOriginRequest for every other request, so a redirect that a caller follows without RedirectPolicy still cannot send the token to another origin.
func Same ¶
Same compares scheme, hostname and effective port, so that "https://host" and "https://host:443" are the same origin.
Types ¶
This section is empty.