Help us shape the future of Go! Take the 2026 Go Developer Survey

safehttp

package
v0.91.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package safehttp provides HTTP clients for requests to URLs taken from project files. Hosted services must never be steered into internal networks through such URLs (server-side request forgery), and credentials attached to a request must never follow a redirect to another host.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSameOriginRedirect

func CheckSameOriginRedirect(req *http.Request, via []*http.Request) error

CheckSameOriginRedirect is an http.Client redirect policy that follows at most 5 redirects, all within the origin of the original request. Every client that carries credentials on each hop must use it, so a redirect to another host never receives them.

func IsPrivateHost

func IsPrivateHost(host string) bool

IsPrivateHost returns true for hostnames that are obviously local, without resolving them. Names that resolve to private addresses are caught later by the transport's dialer.

func NewHTTPClient

func NewHTTPClient(allowPrivate bool, timeout time.Duration) *http.Client

NewHTTPClient returns an HTTP client that follows redirects only within the same origin. Unless allowPrivate is set, it refuses private network addresses.

func NewTransport

func NewTransport(allowPrivate bool, connectTimeout time.Duration) *http.Transport

NewTransport returns an HTTP transport for talking to servers configured by project files. Unless allowPrivate is set, it refuses to dial addresses on loopback, private or link-local networks, which protects hosted services from being pointed at internal services through a connector URL.

Types

This section is empty.

Jump to

Keyboard shortcuts

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