Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support trusted proxy configuration on each adapter #2394

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions arcjet-bun/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import core from "arcjet";
import type {
ArcjetDecision,
ArcjetOptions,
ArcjetOptions as CoreOptions,
Primitive,
Product,
ArcjetRequest,
Expand Down Expand Up @@ -107,6 +107,22 @@ export function createRemoteClient(options?: RemoteClientOptions) {
});
}

/**
* The options used to configure an {@link ArcjetBun} client.
*/
export type ArcjetOptions<
Rules extends [...Array<Primitive | Product>],
Characteristics extends readonly string[],
> = Simplify<
CoreOptions<Rules, Characteristics> & {
/**
* One or more IP Address of trusted proxies in front of the application.
* These addresses will be excluded when Arcjet detects a public IP address.
*/
proxies?: Array<string>;
}
>;

/**
* The ArcjetBun client provides a public `protect()` method to
* make a decision about how a Bun.sh request should be handled.
Expand Down Expand Up @@ -205,7 +221,7 @@ export default function arcjet<
ip: ipCache.get(request),
headers,
},
{ platform: platform(env) },
{ platform: platform(env), proxies: options.proxies },
);
if (ip === "") {
// If the `ip` is empty but we're in development mode, we default the IP
Expand Down
20 changes: 18 additions & 2 deletions arcjet-deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import core from "arcjet";
import type {
ArcjetDecision,
ArcjetOptions,
ArcjetOptions as CoreOptions,
Primitive,
Product,
ArcjetRequest,
Expand Down Expand Up @@ -108,6 +108,22 @@ export function createRemoteClient(options?: RemoteClientOptions) {
});
}

/**
* The options used to configure an {@link ArcjetDeno} client.
*/
export type ArcjetOptions<
Rules extends [...Array<Primitive | Product>],
Characteristics extends readonly string[],
> = Simplify<
CoreOptions<Rules, Characteristics> & {
/**
* One or more IP Address of trusted proxies in front of the application.
* These addresses will be excluded when Arcjet detects a public IP address.
*/
proxies?: Array<string>;
}
>;

/**
* The ArcjetDeno client provides a public `protect()` method to
* make a decision about how a Deno request should be handled.
Expand Down Expand Up @@ -207,7 +223,7 @@ export default function arcjet<
ip: ipCache.get(request),
headers,
},
{ platform: platform(env) },
{ platform: platform(env), proxies: options.proxies },
);
if (ip === "") {
// If the `ip` is empty but we're in development mode, we default the IP
Expand Down
20 changes: 18 additions & 2 deletions arcjet-nest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "reflect-metadata";
import core from "arcjet";
import type {
ArcjetDecision,
ArcjetOptions,
ArcjetOptions as CoreOptions,
Primitive,
Product,
ArcjetRequest,
Expand Down Expand Up @@ -157,6 +157,22 @@ function cookiesToString(cookies: string | string[] | undefined): string {
return cookies;
}

/**
* The options used to configure an {@link ArcjetNest} client.
*/
export type ArcjetOptions<
Rules extends [...Array<Primitive | Product>],
Characteristics extends readonly string[],
> = Simplify<
CoreOptions<Rules, Characteristics> & {
/**
* One or more IP Address of trusted proxies in front of the application.
* These addresses will be excluded when Arcjet detects a public IP address.
*/
proxies?: Array<string>;
}
>;

/**
* The ArcjetNest client provides a public `protect()` method to
* make a decision about how a NestJS request should be handled.
Expand Down Expand Up @@ -222,7 +238,7 @@ function arcjet<
socket: request.socket,
headers,
},
{ platform: platform(process.env) },
{ platform: platform(process.env), proxies: options.proxies },
);
if (ip === "") {
// If the `ip` is empty but we're in development mode, we default the IP
Expand Down
20 changes: 18 additions & 2 deletions arcjet-next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { NextMiddlewareResult } from "next/dist/server/web/types.js";
import core from "arcjet";
import type {
ArcjetDecision,
ArcjetOptions,
ArcjetOptions as CoreOptions,
Primitive,
Product,
ArcjetRequest,
Expand Down Expand Up @@ -190,6 +190,22 @@ function cookiesToString(cookies?: ArcjetNextRequest["cookies"]): string {
.join("; ");
}

/**
* The options used to configure an {@link ArcjetNest} client.
*/
export type ArcjetOptions<
Rules extends [...Array<Primitive | Product>],
Characteristics extends readonly string[],
> = Simplify<
CoreOptions<Rules, Characteristics> & {
/**
* One or more IP Address of trusted proxies in front of the application.
* These addresses will be excluded when Arcjet detects a public IP address.
*/
proxies?: Array<string>;
}
>;

/**
* The ArcjetNext client provides a public `protect()` method to
* make a decision about how a Next.js request should be handled.
Expand Down Expand Up @@ -263,7 +279,7 @@ export default function arcjet<
requestContext: request.requestContext,
headers,
},
{ platform: platform(process.env) },
{ platform: platform(process.env), proxies: options.proxies },
);
if (ip === "") {
// If the `ip` is empty but we're in development mode, we default the IP
Expand Down
20 changes: 18 additions & 2 deletions arcjet-node/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import core from "arcjet";
import type {
ArcjetDecision,
ArcjetOptions,
ArcjetOptions as CoreOptions,
Primitive,
Product,
ArcjetRequest,
Expand Down Expand Up @@ -138,6 +138,22 @@ function cookiesToString(cookies: string | string[] | undefined): string {
return cookies;
}

/**
* The options used to configure an {@link ArcjetNode} client.
*/
export type ArcjetOptions<
Rules extends [...Array<Primitive | Product>],
Characteristics extends readonly string[],
> = Simplify<
CoreOptions<Rules, Characteristics> & {
/**
* One or more IP Address of trusted proxies in front of the application.
* These addresses will be excluded when Arcjet detects a public IP address.
*/
proxies?: Array<string>;
}
>;

/**
* The ArcjetNode client provides a public `protect()` method to
* make a decision about how a Node.js request should be handled.
Expand Down Expand Up @@ -210,7 +226,7 @@ export default function arcjet<
socket: request.socket,
headers,
},
{ platform: platform(process.env) },
{ platform: platform(process.env), proxies: options.proxies },
);
if (ip === "") {
// If the `ip` is empty but we're in development mode, we default the IP
Expand Down
20 changes: 18 additions & 2 deletions arcjet-remix/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import core from "arcjet";
import type {
ArcjetDecision,
ArcjetOptions,
ArcjetOptions as CoreOptions,
Primitive,
Product,
ArcjetRequest,
Expand Down Expand Up @@ -109,6 +109,22 @@ export type ArcjetRemixRequest = {
context: { [key: string]: unknown };
};

/**
* The options used to configure an {@link ArcjetRemix} client.
*/
export type ArcjetOptions<
Rules extends [...Array<Primitive | Product>],
Characteristics extends readonly string[],
> = Simplify<
CoreOptions<Rules, Characteristics> & {
/**
* One or more IP Address of trusted proxies in front of the application.
* These addresses will be excluded when Arcjet detects a public IP address.
*/
proxies?: Array<string>;
}
>;

/**
* The ArcjetRemix client provides a public `protect()` method to
* make a decision about how a Remix request should be handled.
Expand Down Expand Up @@ -182,7 +198,7 @@ export default function arcjet<
ip: context?.ip,
headers,
},
{ platform: platform(process.env) },
{ platform: platform(process.env), proxies: options.proxies },
);
if (ip === "") {
// If the `ip` is empty but we're in development mode, we default the IP
Expand Down
20 changes: 18 additions & 2 deletions arcjet-sveltekit/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import core from "arcjet";
import type {
ArcjetDecision,
ArcjetOptions,
ArcjetOptions as CoreOptions,
Primitive,
Product,
ArcjetRequest,
Expand Down Expand Up @@ -126,6 +126,22 @@ function cookiesToString(
.join("; ");
}

/**
* The options used to configure an {@link ArcjetSvelteKit} client.
*/
export type ArcjetOptions<
Rules extends [...Array<Primitive | Product>],
Characteristics extends readonly string[],
> = Simplify<
CoreOptions<Rules, Characteristics> & {
/**
* One or more IP Address of trusted proxies in front of the application.
* These addresses will be excluded when Arcjet detects a public IP address.
*/
proxies?: Array<string>;
}
>;

/**
* The ArcjetSvelteKit client provides a public `protect()` method to
* make a decision about how a SvelteKit request should be handled.
Expand Down Expand Up @@ -197,7 +213,7 @@ export default function arcjet<
ip: event.getClientAddress(),
headers,
},
{ platform: platform(env) },
{ platform: platform(env), proxies: options.proxies },
);
if (ip === "") {
// If the `ip` is empty but we're in development mode, we default the IP
Expand Down
Loading