safehttp

package
v0.9.14 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 11 Imported by: ? 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 safehttp is the HTTP client sign-in uses to reach identity providers.

Everything it sends goes through a client that dials only the provider's own hosts, resolves them itself and refuses private, loopback and link-local addresses, so a mistake in configuration can't make backd reach inside the network.

Index

Constants

This section is empty.

Variables

View Source
var BuiltinHosts = map[string][]string{
	"google":    {"accounts.google.com", "oauth2.googleapis.com", "www.googleapis.com"},
	"microsoft": {"login.microsoftonline.com"},
	"apple":     {"appleid.apple.com"},
	"github":    {"github.com", "api.github.com"},
}

BuiltinHosts are the hosts of each built-in provider.

View Source
var ErrHostNotAllowed = errors.New("sso: the host is not one of the provider's")

ErrHostNotAllowed means a request named a host that is not one of the provider's.

Functions

func BuiltinHostAllowed

func BuiltinHostAllowed(host string) bool

BuiltinHostAllowed accepts the hosts of the built-in providers.

func ForProvider

func ForProvider(ctx context.Context, private bool, hosts ...string) context.Context

ForProvider returns a context whose requests may also reach the given hosts (a provider's own, which only its configuration names), and, when private, resolve them to private addresses: the ranges of a network (10/8, 172.16/12, 192.168/16, fc00::/7, 100.64/10), never loopback, link-local, the metadata address or anything that isn't a unicast address.

func NewClient

func NewClient(allowed func(host string) bool, allowPrivate bool) *http.Client

NewClient returns an HTTP client that connects only to hosts allowed accepts, by name (or that the request's context names with ForProvider), and, unless allowPrivate, only to public addresses (checked after the name is resolved, on the address actually dialed). It follows no redirect and uses no proxy from the environment.

func ReadBody

func ReadBody(resp *http.Response) ([]byte, error)

ReadBody reads a provider's answer, at most maxBody bytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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