trustedproxy

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 4 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 trustedproxy carries the per-request "arrived through an explicitly configured reverse proxy" signal from router.TrustedRealIP to downstream consumers that must not trust client-supplied forwarding headers on their own (cookie Secure flags, exported base URLs).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForwardedHost

func ForwardedHost(r *http.Request) string

ForwardedHost returns a validated X-Forwarded-Host value only when the request arrived through a trusted proxy. Direct clients cannot steer it.

func ForwardedProto

func ForwardedProto(r *http.Request) string

ForwardedProto returns the X-Forwarded-Proto value only when the request arrived through a trusted proxy. Direct clients can send any value they like, so their header is ignored.

func FromRequest

func FromRequest(ctx context.Context) bool

FromRequest reports whether the request's direct peer matched TRUSTED_PROXY_CIDRS. It is false for direct clients, including direct TLS clients.

func IsHTTPS

func IsHTTPS(r *http.Request) bool

IsHTTPS reports whether the browser-facing request used HTTPS: direct TLS always counts, and X-Forwarded-Proto: https is honored only behind a trusted proxy. Otherwise a direct client could spoof the header and either force Secure cookies over plain HTTP or (with a spoofed http value) weaken them.

func ValidateHost

func ValidateHost(raw string) string

ValidateHost normalizes a Host-style header value and rejects anything that is not a bare host[:port]: userinfo, paths, queries, fragments, whitespace, commas (forwarded lists) and empty values all return "". The result is safe to concatenate into "scheme://host".

func WithTrust

func WithTrust(ctx context.Context) context.Context

WithTrust marks ctx as originating from a direct peer that matched TRUSTED_PROXY_CIDRS. Only router.TrustedRealIP should set it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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