forwardauth

package
v0.3.2-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 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 forwardauth implements the forward-auth adapter used by Traefik's ForwardAuth middleware.

For every client request the proxy sends a subrequest to Path. The original method, URI and host arrive in X-Forwarded-* headers, the client's other headers are copied, and the body is included when the proxy is configured to forward it. A 2xx answer lets the request through; the proxy returns any other answer to the client as is.

The proxy must overwrite client-supplied X-Forwarded-* headers. In Traefik that is trustForwardHeader: false. With true, Traefik keeps a client's own X-Forwarded-Uri, and the engine would inspect a URI chosen by the attacker while the real one is forwarded.

The proxy must also forward the body (Traefik: forwardBody: true with a maxBodySize above the engine's limit). Otherwise bodies reach the application uninspected.

Index

Constants

View Source
const Path = "/v1/forward-auth"

Path is where the proxy sends its subrequests.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxBodyBytes is how much of a forwarded body is inspected. Zero
	// disables body inspection.
	MaxBodyBytes int64
	// ClientIP resolves the client address from X-Forwarded-For. The proxy
	// is the direct peer, so its address must be trusted. Nil trusts no
	// proxies.
	ClientIP *clientip.Resolver
	// Logger receives one security event per denied or logged request.
	// Nil uses slog.Default().
	Logger *slog.Logger
	// Events records each security event for the operator (nil: logged
	// only).
	Events *events.Recorder
}

Config configures a Handler.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler answers forward-auth subrequests.

func New

func New(p pipeline.Inspector, cfg Config) (*Handler, error)

New returns a Handler that inspects requests with p.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP inspects the request described by r and answers 200 to allow it, or the verdict's status to deny it.

Jump to

Keyboard shortcuts

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