httpx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package httpx holds the HTTP hardening shared by GSEER's two web surfaces (REST API + dashboard): security response headers and trusted-proxy client-IP resolution (v0.0.2 M16 security review).

Layering: both internal/api and internal/dashboard import httpx; httpx imports only the standard library. internal/search never imports httpx (search stays transport-free).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTrustedProxies

func ParseTrustedProxies(specs []string) ([]netip.Prefix, error)

ParseTrustedProxies converts config strings into prefixes, rejecting anything that is not a valid CIDR (or bare IP, treated as /32 or /128). Invalid input is a configuration error, never silently ignored — a typo must not widen trust.

func ResolveClientIP

func ResolveClientIP(trusted []netip.Prefix) func(http.Handler) http.Handler

ResolveClientIP returns the middleware that stamps the rate-limit and audit client IP into r.RemoteAddr (host-only, like the previous realIP middleware).

Default (no trusted prefixes configured): the TCP peer address ONLY — X-Forwarded-For is ignored entirely, so a client can never spoof its identity past the rate limiter.

With trusted prefixes: when the immediate peer falls inside one, the client IP is the LAST (right-most) X-Forwarded-For hop — the hop the trusted proxy itself appended; earlier entries remain client-controlled and are never trusted. A malformed or empty XFF keeps the peer address. Loopback proxies are NOT implicitly trusted — an operator must name them explicitly (fail-closed by configuration).

func SecurityHeaders

func SecurityHeaders(next http.Handler) http.Handler

SecurityHeaders sets the conservative response headers every GSEER web surface carries (M16 regression-pinned):

  • X-Content-Type-Options: nosniff — responses are never MIME-sniffed
  • X-Frame-Options: DENY — GSEER UI is never framed
  • Referrer-Policy: no-referrer — queries (which can contain operator research) never leak via Referer to other origins
  • Content-Security-Policy: default-src 'none'; style-src 'unsafe-inline'; img-src data:; form-action 'self'; base-uri 'none'; frame-ancestors 'none' — the dashboard is server-rendered with inline CSS and zero scripts; this denies script injection even if an escaping bug ever appears.

The headers are set on every response (they are cheap and the value is failing closed).

Types

type InvalidProxyError

type InvalidProxyError struct {
	Value string
	Err   error
}

InvalidProxyError reports a malformed trusted-proxy specification.

func (*InvalidProxyError) Error

func (e *InvalidProxyError) Error() string

func (*InvalidProxyError) Unwrap

func (e *InvalidProxyError) Unwrap() error

Jump to

Keyboard shortcuts

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