sameorigin

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const MaxRedirects = 10

MaxRedirects matches the limit of net/http's default redirect policy.

Variables

View Source
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.

View Source
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

func RedirectPolicy(origin *url.URL) func(*http.Request, []*http.Request) error

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

func Same(a, b *url.URL) bool

Same compares scheme, hostname and effective port, so that "https://host" and "https://host:443" are the same origin.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL