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 ¶
const ( Setting = "http.trusted_proxies" Env = "REPUTECAST_HTTP__TRUSTED_PROXIES" )
The setting that fixes it, as the configuration file and the environment name it.
const KindUntrustedProxy = "untrusted_proxy"
KindUntrustedProxy is the instance admins' notification.
Variables ¶
This section is empty.
Functions ¶
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) Middleware ¶
Middleware notes each request; it runs before server.RealIP rewrites the address of trusted proxies' requests.
type NotifyArgs ¶
type NotifyArgs struct{}
NotifyArgs tells admins about untrusted proxies (periodic).
func (NotifyArgs) InsertOpts ¶
func (NotifyArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts.
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 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) List ¶
func (s *Service) List(ctx context.Context) (UntrustedProxies, error)
List returns the proxies seen that aren't trusted now.
func (*Service) Notify ¶
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.