TrustedProxy class

Decides when to believe X-Forwarded-For / X-Forwarded-Proto.

Those headers are easy to fake. Dox only reads them when the direct client (the socket peer) is one of the configured proxies.

Constructors

TrustedProxy(List<String> proxies)

Properties

enabled → bool
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

clientIp(String remote, String? forwardedFor) → String
real client ip. walk X-Forwarded-For from the right and skip our own proxies, so a fake value added by the client on the left is ignored. * trusts only the direct peer, not the hops in the header: with it the right-most hop (added by the proxy) is the client.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
scheme(String remote, String? forwardedProto, [String? direct]) → String
https when a trusted proxy says the client used https. With no word from a trusted proxy: direct, the scheme of the port (default directScheme).
toString() → String
A string representation of this object.
inherited
trusts(String ip) → bool
is ip one of our proxies?

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

directScheme ↔ String
The scheme of a request object that did not come from a server (eg. in a unit test), with no trusted proxy in front: https when the main port has AppConfig.tls, else http. DoxServer.listen sets it, once per isolate, and sets it back to http when the server is closed. With more than one listen (only in tests), the last listen or close wins. A request of a server does not use it: see directSchemeOf.
getter/setter pair

Static Methods

directSchemeOf(HttpRequest req) → String
The scheme of req with no trusted proxy in front: https when the port it came on has TLS, else http. An app can have plain and TLS ports together (AppConfig.ports), so the port decides.
normalize(String ip) → String
::ffff:1.2.3.4 becomes 1.2.3.4. The server listens on IPv6, so IPv4 clients come in this form. Other values stay the same.
readClient(HttpRequest req, List<String> trusted) → ({String? ip, String scheme})
The client ip and scheme of req. trusted is the trustedProxies setting. It is parsed once per isolate. The answer is kept for req, so a second call is cheap.
stripPort(String hop) → String
a hop can carry a port: 1.2.3.4:5678 and [::1]:5678 become 1.2.3.4 and ::1. A bare IPv6 like ::1 has many :, so it stays.