Skip to content

Commit 6339591

Browse files
committed
network of proxies trusted by the server
1 parent f7bfc72 commit 6339591

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Network} from "@cldn/ip";
12
import EventEmitter from "node:events";
23
import http from "node:http";
34
import packageJson from "../package.json" with {type: "json"};
@@ -35,6 +36,10 @@ class Server<A> extends EventEmitter<Server.Events> {
3536
private readonly port?: number;
3637
private readonly copyOrigin: boolean;
3738
private readonly handleConditionalRequests: boolean;
39+
/**
40+
* The network of remote addresses of proxies to trust/
41+
*/
42+
public readonly trustedProxies: Network;
3843

3944
/**
4045
* Create a new HTTP server.
@@ -54,6 +59,7 @@ class Server<A> extends EventEmitter<Server.Events> {
5459
this.copyOrigin = options?.copyOrigin ?? false;
5560
this.handleConditionalRequests = options?.handleConditionalRequests ?? true;
5661
this._authenticators = options?.authenticators ?? [];
62+
this.trustedProxies = options?.trustedProxies ?? new Network();
5763

5864
if (this.port !== undefined) this.listen(this.port).then();
5965

@@ -237,6 +243,12 @@ namespace Server {
237243
* Authenticators for handling request authentication.
238244
*/
239245
readonly authenticators?: Authenticator<A>[];
246+
247+
/**
248+
* The network of trusted proxies. If specified, headers such as `Forwarded`, `X-Forwarded-For`, and `X-Real-IP`
249+
* will be trusted and automatically processed.
250+
*/
251+
readonly trustedProxies?: Network;
240252
}
241253

242254
/**

0 commit comments

Comments
 (0)