mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-28 16:58:31 +01:00
Loopback trust (no-auth access, recovery tokens and sessions, unauthenticated config transfer, the rate-limit exemption) now needs more than a loopback peer: no reverse-proxy forwarding header, a Host that is localhost, *.localhost or a loopback literal, and a browser request that is same-origin by Fetch Metadata or names exactly this origin. A same-host proxy passing a public Host, a page whose name resolves to 127.0.0.1, or a page on another origin no longer counts as a local user. GetClientIP now takes the right-most X-Forwarded-For hop that is not in PULSE_TRUSTED_PROXY_CIDRS, reading every header line and accepting entries with ports, instead of the first entry. A proxy that appends keeps the client's own entries on the left, so the first entry is client-chosen. Lockout, rate limits, audit addresses and recovery-token binding use this. The reverse-proxy guide explains multi-hop setups: list upstream hops as trusted or have the final proxy replace the header.
15 lines
267 B
Go
15 lines
267 B
Go
package api
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
)
|
|
|
|
func newLoopbackRequest(method, target string, body io.Reader) *http.Request {
|
|
req := httptest.NewRequest(method, target, body)
|
|
req.RemoteAddr = "127.0.0.1:12345"
|
|
req.Host = "localhost"
|
|
return req
|
|
}
|