@arcjet/ip
Advanced tools
+29
-30
| import { ProxyService } from "./index.js"; | ||
| //#region src/cloudflare.d.ts | ||
| /** | ||
| * Cloudflare IPv4 ranges. | ||
| * | ||
| * Source: https://www.cloudflare.com/ips-v4/ | ||
| */ | ||
| * Cloudflare IPv4 ranges. | ||
| * | ||
| * Source: https://www.cloudflare.com/ips-v4/ | ||
| */ | ||
| declare const cloudflareIpv4Ranges: ReadonlyArray<string>; | ||
| /** | ||
| * Cloudflare IPv6 ranges. | ||
| * | ||
| * Source: https://www.cloudflare.com/ips-v6/ | ||
| */ | ||
| * Cloudflare IPv6 ranges. | ||
| * | ||
| * Source: https://www.cloudflare.com/ips-v6/ | ||
| */ | ||
| declare const cloudflareIpv6Ranges: ReadonlyArray<string>; | ||
| /** | ||
| * Configuration for {@linkcode cloudflare}. | ||
| */ | ||
| * Configuration for {@linkcode cloudflare}. | ||
| */ | ||
| interface CloudflareOptions { | ||
| /** | ||
| * IP addresses and CIDR ranges that identify Cloudflare | ||
| * (optional; defaults to the ranges bundled with this package). | ||
| * | ||
| * Override this only if the bundled ranges are out of date for your setup. | ||
| */ | ||
| * IP addresses and CIDR ranges that identify Cloudflare | ||
| * (optional; defaults to the ranges bundled with this package). | ||
| * | ||
| * Override this only if the bundled ranges are out of date for your setup. | ||
| */ | ||
| ranges?: ReadonlyArray<string> | null | undefined; | ||
| } | ||
| /** | ||
| * Describe Cloudflare as a trusted proxy in front of your application. | ||
| * | ||
| * Pass the result in the `proxies` array. When a request reaches your platform | ||
| * from a Cloudflare IP, Arcjet will read the real client IP from the | ||
| * `CF-Connecting-IP` / `CF-Connecting-IPv6` header instead of treating the | ||
| * Cloudflare edge address as the client. The header is only trusted when the | ||
| * connecting address is within Cloudflare's ranges, so it cannot be spoofed by | ||
| * clients connecting directly to your platform. | ||
| * | ||
| * @param options | ||
| * Configuration (optional). | ||
| * @returns | ||
| * Proxy service descriptor to include in the `proxies` array. | ||
| */ | ||
| * Describe Cloudflare as a trusted proxy in front of your application. | ||
| * | ||
| * Pass the result in the `proxies` array. When a request reaches your platform | ||
| * from a Cloudflare IP, Arcjet will read the real client IP from the | ||
| * `CF-Connecting-IP` / `CF-Connecting-IPv6` header instead of treating the | ||
| * Cloudflare edge address as the client. The header is only trusted when the | ||
| * connecting address is within Cloudflare's ranges, so it cannot be spoofed by | ||
| * clients connecting directly to your platform. | ||
| * | ||
| * @param options | ||
| * Configuration (optional). | ||
| * @returns | ||
| * Proxy service descriptor to include in the `proxies` array. | ||
| */ | ||
| declare function cloudflare(options?: CloudflareOptions | null | undefined): ProxyService; | ||
| //#endregion | ||
| export { CloudflareOptions, cloudflare, cloudflareIpv4Ranges, cloudflareIpv6Ranges }; |
+93
-94
| import { CloudflareOptions, cloudflare } from "./cloudflare.js"; | ||
| //#region src/index.d.ts | ||
@@ -23,27 +22,27 @@ type Ipv4Tuple = [number, number, number, number]; | ||
| /** | ||
| * Parse CIDR addresses and keep non-CIDR IP addresses. | ||
| * | ||
| * @param value | ||
| * Value to parse. | ||
| * @returns | ||
| * Parsed {@linkcode Cidr} if range or given `value` if IP. | ||
| */ | ||
| * Parse CIDR addresses and keep non-CIDR IP addresses. | ||
| * | ||
| * @param value | ||
| * Value to parse. | ||
| * @returns | ||
| * Parsed {@linkcode Cidr} if range or given `value` if IP. | ||
| */ | ||
| declare function parseProxy(value: string): string | Cidr; | ||
| /** | ||
| * Parse a list of trusted proxies. | ||
| * | ||
| * CIDR range strings are parsed to {@linkcode Cidr} (so they match by range); | ||
| * plain IP strings and {@linkcode ProxyService} objects (such as those created | ||
| * by {@linkcode cloudflare}) are passed through unchanged. Use this to | ||
| * normalize the `proxies` option before handing it to {@linkcode findIp}. | ||
| * | ||
| * @param proxies | ||
| * Trusted proxies to parse. | ||
| * @returns | ||
| * Parsed proxies. | ||
| */ | ||
| * Parse a list of trusted proxies. | ||
| * | ||
| * CIDR range strings are parsed to {@linkcode Cidr} (so they match by range); | ||
| * plain IP strings and {@linkcode ProxyService} objects (such as those created | ||
| * by {@linkcode cloudflare}) are passed through unchanged. Use this to | ||
| * normalize the `proxies` option before handing it to {@linkcode findIp}. | ||
| * | ||
| * @param proxies | ||
| * Trusted proxies to parse. | ||
| * @returns | ||
| * Parsed proxies. | ||
| */ | ||
| declare function parseProxies(proxies: ReadonlyArray<string | ProxyService>): Array<string | Cidr | ProxyService>; | ||
| /** | ||
| * Socket-like interface. | ||
| */ | ||
| * Socket-like interface. | ||
| */ | ||
| interface PartialSocket { | ||
@@ -53,4 +52,4 @@ remoteAddress?: string | null | undefined; | ||
| /** | ||
| * Interface that looks like info. | ||
| */ | ||
| * Interface that looks like info. | ||
| */ | ||
| interface PartialInfo { | ||
@@ -63,4 +62,4 @@ remoteAddress?: string | null | undefined; | ||
| /** | ||
| * Interface that looks like a request context. | ||
| */ | ||
| * Interface that looks like a request context. | ||
| */ | ||
| interface PartialRequestContext { | ||
@@ -70,119 +69,119 @@ identity?: PartialIdentiy | null | undefined; | ||
| /** | ||
| * Interface with `headers`. | ||
| */ | ||
| * Interface with `headers`. | ||
| */ | ||
| type HeaderLike = { | ||
| /** | ||
| * Headers. | ||
| */ | ||
| * Headers. | ||
| */ | ||
| headers: Headers | Record<string, string[] | string | undefined>; | ||
| }; | ||
| /** | ||
| * Interface that looks like a request, | ||
| * of which `headers` is required and several other fields may exist. | ||
| */ | ||
| * Interface that looks like a request, | ||
| * of which `headers` is required and several other fields may exist. | ||
| */ | ||
| type RequestLike = { | ||
| /** | ||
| * Some platforms pass `info`. | ||
| */ | ||
| * Some platforms pass `info`. | ||
| */ | ||
| info?: PartialInfo | null | undefined; | ||
| /** | ||
| * Some platforms such as Cloudflare and Vercel provide `ip` directly on | ||
| * `request`. | ||
| */ | ||
| * Some platforms such as Cloudflare and Vercel provide `ip` directly on | ||
| * `request`. | ||
| */ | ||
| ip?: unknown; | ||
| /** | ||
| * Some platforms pass info in `requestContext`. | ||
| */ | ||
| * Some platforms pass info in `requestContext`. | ||
| */ | ||
| requestContext?: PartialRequestContext | null | undefined; | ||
| /** | ||
| * Some platforms pass a `socket`. | ||
| */ | ||
| * Some platforms pass a `socket`. | ||
| */ | ||
| socket?: PartialSocket | null | undefined; | ||
| } & HeaderLike; | ||
| /** | ||
| * Platform name. | ||
| */ | ||
| * Platform name. | ||
| */ | ||
| type Platform = "cloudflare" | "firebase" | "fly-io" | "render" | "vercel"; | ||
| /** | ||
| * Format of a client IP header set by a proxy service. | ||
| * | ||
| * - `"ip"` — a single IP address (e.g. `CF-Connecting-IP`). | ||
| * - `"ips"` — an `X-Forwarded-For`-style comma separated list, parsed | ||
| * tail-to-head. | ||
| */ | ||
| * Format of a client IP header set by a proxy service. | ||
| * | ||
| * - `"ip"` — a single IP address (e.g. `CF-Connecting-IP`). | ||
| * - `"ips"` — an `X-Forwarded-For`-style comma separated list, parsed | ||
| * tail-to-head. | ||
| */ | ||
| type ClientIpFormat = "ip" | "ips"; | ||
| /** | ||
| * A client IP header set by a proxy service. | ||
| */ | ||
| * A client IP header set by a proxy service. | ||
| */ | ||
| interface ClientIpHeader { | ||
| /** | ||
| * Header name (lower-case). | ||
| */ | ||
| * Header name (lower-case). | ||
| */ | ||
| header: string; | ||
| /** | ||
| * How to parse the header value. | ||
| */ | ||
| * How to parse the header value. | ||
| */ | ||
| format: ClientIpFormat; | ||
| } | ||
| /** | ||
| * A trusted proxy service (such as Cloudflare) sitting in front of the | ||
| * application. | ||
| * | ||
| * Identified by IP range, with the header(s) that carry the real client IP. | ||
| * Create one with a helper such as {@linkcode cloudflare} and include it in the | ||
| * `proxies` array. | ||
| */ | ||
| * A trusted proxy service (such as Cloudflare) sitting in front of the | ||
| * application. | ||
| * | ||
| * Identified by IP range, with the header(s) that carry the real client IP. | ||
| * Create one with a helper such as {@linkcode cloudflare} and include it in the | ||
| * `proxies` array. | ||
| */ | ||
| interface ProxyService { | ||
| /** | ||
| * Discriminant marking this entry as a proxy service. | ||
| */ | ||
| * Discriminant marking this entry as a proxy service. | ||
| */ | ||
| kind: "service"; | ||
| /** | ||
| * Name of the service (such as `"cloudflare"`). | ||
| */ | ||
| * Name of the service (such as `"cloudflare"`). | ||
| */ | ||
| name: string; | ||
| /** | ||
| * IP addresses and CIDR ranges that identify this service. | ||
| */ | ||
| * IP addresses and CIDR ranges that identify this service. | ||
| */ | ||
| ranges: ReadonlyArray<string | Cidr>; | ||
| /** | ||
| * Header(s) this service uses to relay the real client IP, in priority order. | ||
| */ | ||
| * Header(s) this service uses to relay the real client IP, in priority order. | ||
| */ | ||
| clientIp: ReadonlyArray<ClientIpHeader>; | ||
| } | ||
| /** | ||
| * Configuration. | ||
| */ | ||
| * Configuration. | ||
| */ | ||
| interface Options { | ||
| /** | ||
| * Platform the code is running on; | ||
| * used to allow only known more trustworthy headers. | ||
| */ | ||
| * Platform the code is running on; | ||
| * used to allow only known more trustworthy headers. | ||
| */ | ||
| platform?: Platform | null | undefined; | ||
| /** | ||
| * Trusted proxies. | ||
| * | ||
| * IP addresses and CIDR ranges are treated as trusted load balancers or | ||
| * proxies and skipped when finding the client IP. Proxy services created with | ||
| * a helper such as {@linkcode cloudflare} additionally declare which header | ||
| * carries the real client IP. | ||
| */ | ||
| * Trusted proxies. | ||
| * | ||
| * IP addresses and CIDR ranges are treated as trusted load balancers or | ||
| * proxies and skipped when finding the client IP. Proxy services created with | ||
| * a helper such as {@linkcode cloudflare} additionally declare which header | ||
| * carries the real client IP. | ||
| */ | ||
| proxies?: ReadonlyArray<string | Cidr | ProxyService> | null | undefined; | ||
| } | ||
| /** | ||
| * Find a client IP address on a request-like object. | ||
| * | ||
| * @param request | ||
| * Request-like object. | ||
| * @param [options] | ||
| * Configuration (optional). | ||
| * @returns | ||
| * Found IP address; empty string if not found. | ||
| */ | ||
| * Find a client IP address on a request-like object. | ||
| * | ||
| * @param request | ||
| * Request-like object. | ||
| * @param [options] | ||
| * Configuration (optional). | ||
| * @returns | ||
| * Found IP address; empty string if not found. | ||
| */ | ||
| declare function findIp(request: RequestLike, options?: Options | null | undefined): string; | ||
| /** | ||
| * One of the CIDR ranges. | ||
| */ | ||
| * One of the CIDR ranges. | ||
| */ | ||
| type Cidr = Ipv4Cidr | Ipv6Cidr; | ||
| //#endregion | ||
| export { Cidr, ClientIpFormat, ClientIpHeader, type CloudflareOptions, HeaderLike, Options, Platform, ProxyService, RequestLike, cloudflare, findIp as default, findIp, parseProxies, parseProxy }; |
+5
-5
| { | ||
| "name": "@arcjet/ip", | ||
| "version": "1.9.1", | ||
| "version": "1.10.0-rc.0", | ||
| "description": "Arcjet utilities for finding the originating IP of a request", | ||
@@ -53,3 +53,3 @@ "keywords": [ | ||
| "build": "tsdown", | ||
| "typecheck": "tsgo --noEmit", | ||
| "typecheck": "tsc --noEmit", | ||
| "generate": "npm run build && node scripts/verify-ranges.ts --write", | ||
@@ -63,5 +63,5 @@ "test-api": "node --test -- test/*.test.ts", | ||
| "devDependencies": { | ||
| "@types/node": "22.19.21", | ||
| "tsdown": "0.22.3", | ||
| "typescript": "6.0.3" | ||
| "@types/node": "22.20.1", | ||
| "tsdown": "0.22.7", | ||
| "typescript": "7.0.2" | ||
| }, | ||
@@ -68,0 +68,0 @@ "engines": { |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
46107
0.27%1
Infinity%