@authhero/proxy 0.10.4 → 0.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Parse a textual IP address into its bytes: 4 for IPv4, 16 for IPv6.
3
+ * IPv4-mapped IPv6 (`::ffff:1.2.3.4`) collapses to the 4-byte form so it is
4
+ * matched against the IPv4 ranges. Returns null for anything unparseable.
5
+ */
6
+ export declare function parseIpAddress(input: string): number[] | null;
7
+ /**
8
+ * True when `ip` falls inside a Cloudflare-published range. Unparseable input
9
+ * returns false — callers treat "not recognizably Cloudflare" as a client IP.
10
+ */
11
+ export declare function isCloudflareIp(ip: string): boolean;
@@ -3,6 +3,33 @@ import type { MiddlewareHandler } from "hono";
3
3
  import type { ProxyRoute } from "../types";
4
4
  import { HandlerRegistry } from "./registry";
5
5
  import { type ProxyHostContext } from "./handlers/util";
6
+ export declare const FORWARDED_HEADERS_HANDLER_TYPE = "forwarded_headers";
7
+ /**
8
+ * Minimal shape shared by stored route handlers (`HandlerConfig`) and the
9
+ * catch-all specs passed to the data plane (`ProxyRouteHandlerSpec`).
10
+ */
11
+ export interface HandlerSpecLike {
12
+ type: string;
13
+ options?: unknown;
14
+ }
15
+ /**
16
+ * Guarantee a `forwarded_headers` handler at the head of a chain. Stored route
17
+ * tables (KV / control plane) predate the handler and routinely omit it, which
18
+ * silently drops the visitor IP: nothing else in the chain stamps
19
+ * X-Forwarded-For / X-Real-IP, so upstreams see only the proxy hop's own
20
+ * source address. Chains that already declare it — anywhere in the list — are
21
+ * returned untouched so their configured options win and nothing is stamped
22
+ * twice. Prefer `withForwardedHeadersFor`, which also checks that the registry
23
+ * knows the handler.
24
+ */
25
+ export declare function withForwardedHeaders(handlers: readonly HandlerSpecLike[]): HandlerSpecLike[];
26
+ /**
27
+ * `withForwardedHeaders`, but a no-op unless `registry` knows the handler — a
28
+ * consumer with a bespoke registry that never registered it would otherwise
29
+ * get a build-time throw on every route. Every chain the data plane compiles
30
+ * (per-host routes and the `defaultHandlers` catch-all) goes through here.
31
+ */
32
+ export declare function withForwardedHeadersFor(registry: HandlerRegistry, handlers: readonly HandlerSpecLike[]): HandlerSpecLike[];
6
33
  /**
7
34
  * Build a Hono app whose route table mirrors the configured proxy routes for
8
35
  * a single host. Compiled once per host (and cached alongside the resolved
@@ -12,8 +39,13 @@ import { type ProxyHostContext } from "./handlers/util";
12
39
  * `handlers/util.ts`). Handlers that template against those values
13
40
  * (`dispatch_namespace`) depend on this wiring.
14
41
  *
42
+ * Every route's handler chain is normalized through
43
+ * `withForwardedHeadersFor`, so a stored route table that omits
44
+ * `forwarded_headers` still forwards the visitor IP.
45
+ *
15
46
  * `defaultHandlers` is a prebuilt middleware chain installed as the catch-all
16
47
  * when no per-host route matches. Pass `undefined` to keep the legacy 404
17
- * "No matching route" behavior.
48
+ * "No matching route" behavior. It is built by the caller (`router.ts`), which
49
+ * applies `withForwardedHeadersFor` to it as well.
18
50
  */
19
51
  export declare function compileHostApp(routes: ProxyRoute[], registry: HandlerRegistry, hostContext?: ProxyHostContext, defaultHandlers?: MiddlewareHandler[]): Hono;
@@ -2,4 +2,5 @@ export declare const forwardedHeadersHandler: import("../registry").HandlerDefin
2
2
  client_ip_header: string;
3
3
  set_x_real_ip: boolean;
4
4
  set_x_original_url: boolean;
5
+ skip_cloudflare_client_ip: boolean;
5
6
  }>;
@@ -13,7 +13,9 @@ export type { CacheAdapterHostCacheOptions } from "./data-plane/cache-adapter-ca
13
13
  export { HandlerRegistry, defineHandler } from "./data-plane/registry";
14
14
  export type { HandlerDefinition, HandlerBuildContext, } from "./data-plane/registry";
15
15
  export { registerBuiltinHandlers, corsHandler, basicAuthHandler, headersHandler, cacheHandler, forwardedHeadersHandler, rewriteCookiesHandler, rewriteLocationHandler, httpHandler, serviceBindingHandler, dispatchNamespaceHandler, redirectHandler, staticHandler, } from "./data-plane/handlers";
16
- export { compileHostApp } from "./data-plane/compile";
16
+ export { compileHostApp, withForwardedHeaders, withForwardedHeadersFor, FORWARDED_HEADERS_HANDLER_TYPE, } from "./data-plane/compile";
17
+ export type { HandlerSpecLike } from "./data-plane/compile";
18
+ export { isCloudflareIp } from "./data-plane/cloudflare-ips";
17
19
  export { sortRoutes, matchesHost, matchesAnyHost, buildMatchFilter, } from "./data-plane/matcher";
18
20
  export { createStaticProxyAdapter, httpRoute } from "./static";
19
21
  export type { StaticProxyAdapterOptions, StaticHostConfig, StaticRouteInput, } from "./static";
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/markusahlstrand/authhero"
13
13
  },
14
- "version": "0.10.4",
14
+ "version": "0.10.6",
15
15
  "files": [
16
16
  "dist"
17
17
  ],
@@ -40,7 +40,7 @@
40
40
  "hono": "^4.6.8"
41
41
  },
42
42
  "dependencies": {
43
- "@authhero/adapter-interfaces": "4.7.0"
43
+ "@authhero/adapter-interfaces": "4.8.0"
44
44
  },
45
45
  "license": "AGPL-3.0-only",
46
46
  "scripts": {