{"modulePath":"github.com/coder/coder-k8s","version":"v0.1.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sameorigin\n\nPackage sameorigin keeps credentials on the origin they were meant for.\n\nnet/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.\n\ncodersdk 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.\n\n## Constants\n\n```go\nconst MaxRedirects = 10\n```\nMaxRedirects matches the limit of net/http's default redirect policy.\n\n## Variables\n\n```go\nvar ErrCrossOrigin = errors.New(\"refusing redirect to a different origin than the coder URL\")\n```\nErrCrossOrigin 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.\n\n```go\nvar ErrCrossOriginRequest = errors.New(\"refusing request to a different origin than the coder URL\")\n```\nErrCrossOriginRequest 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.\n\n## Functions\n\n```go\nfunc RedirectPolicy(origin *url.URL) func(*http.Request, []*http.Request) error\n```\nRedirectPolicy returns a CheckRedirect function that follows a redirect only when it stays on the origin of origin, and stops after MaxRedirects.\n\n```go\nfunc RoundTripper(origin *url.URL, base http.RoundTripper) http.RoundTripper\n```\nRoundTripper 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.\n\n```go\nfunc Same(a, b *url.URL) bool\n```\nSame compares scheme, hostname and effective port, so that \"[https://host](https://host)\" and \"[https://host:443](https://host:443)\" are the same origin.\n\n","path":"github.com/coder/coder-k8s/internal/sameorigin","name":"sameorigin","synopsis":"Package sameorigin keeps credentials on the origin they were meant for.","isRedistributable":true}
