proxycheck

package
v1.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package proxycheck notices requests that reach ReputeCast through a reverse proxy it doesn't trust, and tells the instance's admins how to fix it (review AN-8).

Behind a proxy ReputeCast doesn't trust, every request carries the proxy's address instead of the reader's (server.RealIP ignores the forwarding headers of untrusted peers, as it must). Opens and clicks then all look like they come from one address: the bot filter can't tell Apple's privacy proxy or a mail scanner's network from a person, and rate limits treat every reader as one. The fix is configuration: http.trusted_proxies (REPUTECAST_HTTP__TRUSTED_PROXIES) lists the proxy.

Anyone on the internet can send forwarding headers, and a trusted address can make up readers' addresses (rate limits, the audit log, the bot filter). So only an address on a private network is ever named as one to add, and only once it has behaved like a proxy for a while: nearly all its requests carried a forwarding header, minute after minute. A NAT in front of ReputeCast passes on the headers of the few clients that send one, and a burst through it names nobody. A public address that forwarded most of the traffic for a long time may be a CDN or load balancer: admins are asked to check whose it is and, if it is theirs, to add the ranges its provider publishes (security review).

Index

Constants

View Source
const (
	Setting = "http.trusted_proxies"
	Env     = "REPUTECAST_HTTP__TRUSTED_PROXIES"
)

The setting that fixes it, as the configuration file and the environment name it.

View Source
const KindUntrustedProxy = "untrusted_proxy"

KindUntrustedProxy is the instance admins' notification.

Variables

This section is empty.

Functions

func Register

func Register(h huma.API, s *Service)

Register adds the instance admin's view of untrusted proxies.

Types

type Detector

type Detector struct {
	Q       *store.Queries
	Log     *slog.Logger
	Trusted []netip.Prefix
	Now     func() time.Time
	// contains filtered or unexported fields
}

Detector watches requests for forwarding headers from peers that aren't trusted. It is safe for concurrent use.

func (*Detector) Flush

func (d *Detector) Flush(ctx context.Context) error

Flush writes what the current window saw now (tests, shutdown).

func (*Detector) Middleware

func (d *Detector) Middleware(next http.Handler) http.Handler

Middleware notes each request; it runs before server.RealIP rewrites the address of trusted proxies' requests.

func (*Detector) Observe

func (d *Detector) Observe(r *http.Request)

Observe notes a request and, once a window is over, writes what it saw.

type NotifyArgs

type NotifyArgs struct{}

NotifyArgs tells admins about untrusted proxies (periodic).

func (NotifyArgs) InsertOpts

func (NotifyArgs) InsertOpts() river.InsertOpts

InsertOpts implements river.JobArgsWithInsertOpts.

func (NotifyArgs) Kind

func (NotifyArgs) Kind() string

Kind implements river.JobArgs.

type NotifyWorker

type NotifyWorker struct {
	river.WorkerDefaults[NotifyArgs]
	S *Service
}

NotifyWorker runs NotifyArgs.

func (*NotifyWorker) Work

func (w *NotifyWorker) Work(ctx context.Context, _ *river.Job[NotifyArgs]) error

Work implements river.Worker.

type Seen

type Seen struct {
	Peer     netip.Addr
	Header   string
	Requests int64
	At       time.Time
}

Seen is a proxy's requests in a window.

type Service

type Service struct {
	Pool    *pgxpool.Pool
	Q       *store.Queries
	Trusted []netip.Prefix
	Now     func() time.Time
}

Service tells the instance's admins about untrusted proxies and lists them for the admin API.

func (*Service) Flagged

func (s *Service) Flagged(ctx context.Context) bool

Flagged reports whether a proxy http.trusted_proxies doesn't list forwarded requests often in the last day (the proxies admins are told about), so the client addresses ReputeCast sees may be that proxy's. API keys' allowed IPs warn about it.

func (*Service) List

func (s *Service) List(ctx context.Context) (UntrustedProxies, error)

List returns the proxies seen that aren't trusted now.

func (*Service) Notify

func (s *Service) Notify(ctx context.Context) (int, error)

Notify tells every instance admin about each proxy seen often enough in the last day that they weren't told about this week, and forgets proxies that are trusted now or gone. It tells about maxTold proxies a run and maxToldDaily a day, those on a private network first. It returns how many proxies the admins were told about.

type UntrustedProxies

type UntrustedProxies struct {
	Proxies []UntrustedProxy `json:"proxies"`
	Setting string           `json:"setting" doc:"The configuration setting that lists trusted proxies"`
	Env     string           `json:"env" doc:"The same setting as an environment variable"`
	Trusted []string         `json:"trusted" doc:"The proxies trusted now"`
	Advice  string           `json:"advice" doc:"What to do, in the reader's language"`
}

UntrustedProxies is what the admin API shows: the proxies seen, the setting that fixes it, and what is trusted now.

type UntrustedProxy

type UntrustedProxy struct {
	Address    string     `json:"address"`
	Header     string     `json:"header" doc:"The forwarding header it sent"`
	Requests   int64      `json:"requests"`
	FirstSeen  time.Time  `json:"firstSeen"`
	LastSeen   time.Time  `json:"lastSeen"`
	NotifiedAt *time.Time `json:"notifiedAt,omitempty" doc:"When admins were last told"`
}

UntrustedProxy is one proxy seen forwarding requests.

Jump to

Keyboard shortcuts

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