httputil

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package httputil provides shared HTTP request introspection helpers that gate the trust placed in attacker-controllable proxy headers.

ADR-0017 establishes that longue-vue reads X-Forwarded-For and X-Forwarded-Proto only when the immediate peer is in an explicit trusted-proxy CIDR list. The empty-list default ignores both headers unconditionally — that is the secure default the pentest report (AUTH-VULN-04) demands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request, trusted []*net.IPNet) net.IP

ClientIP returns the source IP for rate-limiting and audit logging.

X-Forwarded-For is honored only when the immediate peer (r.RemoteAddr) matches an entry in the trusted list. The XFF walk runs right-to-left through trusted hops and returns the first untrusted IP — the real client. Attackers can prepend arbitrary values to XFF but cannot append past trusted hops, so prepended values are unreachable.

With an empty trust list, XFF is ignored entirely. Returns nil only if r.RemoteAddr is unparseable.

func IsHTTPS

func IsHTTPS(r *http.Request, trusted []*net.IPNet) bool

IsHTTPS reports whether the request actually arrived over TLS — either natively (r.TLS != nil) or via a TLS-terminating peer in the trusted list that set X-Forwarded-Proto: https. With an empty trust list, X-Forwarded-Proto is ignored entirely.

func ParseTrustedProxies

func ParseTrustedProxies(csv string) ([]*net.IPNet, error)

ParseTrustedProxies parses a comma-separated CIDR list into IP networks. Empty input returns an empty slice and nil error. Any invalid CIDR aborts the parse and the offending value appears in the returned error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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