reguard 0.9.0 → 0.10.1

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.
@@ -10,12 +10,15 @@
10
10
  * `trust proxy`, Fastify with `trustProxy`);
11
11
  * 2. the host's own client header when the host is known from the environment (Fly, Vercel,
12
12
  * Railway, Netlify, App Engine, Cloudflare Workers);
13
- * 3. `cf-connecting-ip` when the connection comes from Cloudflare's published ranges;
14
- * 4. the X-Forwarded-For chain read right to left from the connecting peer, skipping private,
15
- * loopback and shared-network addresses (load balancers and proxies inside your network): the
16
- * first public address is the visitor.
17
- * When no public address appears at all, the request came from your own network (server-side
18
- * rendering, health checks, internal services): it is marked internal and never paced.
13
+ * 3. the chain [...X-Forwarded-For, connecting peer] read right to left. Each hop is skipped when it
14
+ * is one of yours (private, loopback, shared-network: load balancers, proxies, the cluster) or
15
+ * CloudFront's (its origin-facing ranges; CloudFront appends the address it saw, so the next entry
16
+ * left is that). A Cloudflare address ends the walk at `cf-connecting-ip`, which Cloudflare sets
17
+ * itself. The first other address is the visitor.
18
+ * Without a connecting peer (Next.js middleware, fetch runtimes) the walk starts at the right end of
19
+ * X-Forwarded-For, which the nearest proxy wrote. When no public address appears at all, the request
20
+ * came from your own network (server-side rendering, health checks, internal services): it is marked
21
+ * internal and never paced.
19
22
  */
20
23
  export type ClientIpMode = "auto" | "socket" | {
21
24
  header: string;
@@ -47,6 +50,16 @@ export interface ResolvedAddress {
47
50
  }
48
51
  /** Cloudflare's published ranges (cloudflare.com/ips-v4, /ips-v6; checked 2026-12-03). */
49
52
  export declare const CLOUDFLARE_RANGES: readonly string[];
53
+ /**
54
+ * CloudFront's origin-facing ranges (AWS's published ip-ranges.json, service CLOUDFRONT_ORIGIN_FACING;
55
+ * checked 2026-12-04): the addresses CloudFront connects to origins from. Only CloudFront uses them.
56
+ */
57
+ export declare const CLOUDFRONT_RANGES: readonly string[];
58
+ /**
59
+ * Headers whose value is always "address:port", so the last ":port" is cut even from an IPv6 address
60
+ * written without brackets (CloudFront-Viewer-Address: "2001:db8::1:443" is 2001:db8::1, port 443).
61
+ */
62
+ export declare const PORT_SUFFIXED_HEADERS: readonly string[];
50
63
  /** Addresses that are never a visitor's: unspecified, private, shared (carrier-grade NAT), loopback, link-local. */
51
64
  export declare const NON_PUBLIC_RANGES: readonly string[];
52
65
  /** At most this many X-Forwarded-For entries are read (from the right). */
@@ -67,6 +80,12 @@ interface Cidr {
67
80
  }
68
81
  /** "a.b.c.d/n", "v6/n" or a bare address; null when malformed. */
69
82
  export declare function parseCidr(text: string): Cidr | null;
83
+ /**
84
+ * What pace, claims and visitor hashes key an address by: an IPv6 address by its /64 (one host or
85
+ * home network's whole block, which its owner can rotate through freely), an IPv4 one as it is.
86
+ * "" for anything that isn't an address.
87
+ */
88
+ export declare function addressKey(address: string | undefined): string;
70
89
  /** Whether an address (any text form) belongs to one of the ranges. */
71
90
  export declare function ipInRanges(address: string, ranges: readonly string[] | readonly Cidr[]): boolean;
72
91
  /** A visitor's address could be this one: not private, shared, loopback, link-local or unspecified. */
@@ -43,8 +43,14 @@ export declare function resolveCollect(input: unknown, warn?: (message: string)
43
43
  /**
44
44
  * A matcher for skip patterns: `*` matches any characters (slashes included), and a pattern ending in
45
45
  * "/*" also matches the path without it ("/account/*" covers "/account"). Query and fragment are ignored.
46
+ * Exemptions (block.allow) match exactly; protections use protectionMatcher.
46
47
  */
47
- export declare function skipMatcher(patterns: readonly string[]): (path: string) => boolean;
48
+ export declare function skipMatcher(patterns: readonly string[], ignoreCase?: boolean): (path: string) => boolean;
49
+ /**
50
+ * A matcher for protections (require, collect.skip, ignore): as skipMatcher, ignoring case, since
51
+ * routers that match paths case-insensitively (Express's default) serve /API/x as /api/x.
52
+ */
53
+ export declare function protectionMatcher(patterns: readonly string[]): (path: string) => boolean;
48
54
  /** The script tag's data-* attributes for the settings that differ from the defaults. */
49
55
  export declare function collectAttributes(c: CollectSettings): Record<string, string>;
50
56
  export declare function collectReport(c: CollectSettings): CollectReport;
@@ -18,6 +18,11 @@ export interface InitRequest {
18
18
  site: string;
19
19
  /** This browser's previous session id (the `_s` cookie), for linking reloads when the cookie can't travel (cross-origin script). */
20
20
  prev?: string;
21
+ /**
22
+ * The session this tab's previous page load started (sessionStorage `_s_tab`, script 0.9.3+): page
23
+ * loads in one tab stay one investigation when the `_s` cookie is cleared or blocked between them.
24
+ */
25
+ tab?: string;
21
26
  /** SDK version (packages/sdk/package.json). */
22
27
  sdk?: string;
23
28
  /** Verification-run id from the `lab_run` query parameter; the hosted collector ignores it. */
@@ -7,7 +7,8 @@
7
7
  * one. A rule checked against only one form can be walked around with the other (`/%61pi/items`
8
8
  * reaches `/api/items`; `/app.js%2Emap` is served as `/app.js.map`). So every rule sees both:
9
9
  * - `raw`: the path as sent, without query or fragment (absolute-form targets cut to their path);
10
- * - `decoded`: percent-decoded once, `//` collapsed and `.`/`..` segments resolved.
10
+ * - `decoded`: percent-decoded once, `\` read as `/` (as URL parsers read it), `//` collapsed and
11
+ * `.`/`..` segments resolved.
11
12
  * Protections apply when either form matches; exemptions only when both do. Summaries keep the raw
12
13
  * path.
13
14
  */
@@ -24,7 +25,10 @@ export declare function decodeOnce(s: string): string;
24
25
  export declare function normalizeSegments(path: string): string;
25
26
  /** Both forms of a request target (`req.url`, a RequestURI, a WSGI path): see the module comment. */
26
27
  export declare function canonicalPath(target: string | undefined): CanonicalPath;
27
- /** A protection (require, source maps, skip, ignore) applies when either form matches. */
28
+ /**
29
+ * A protection (require, source maps, skip, ignore) applies when either form matches; build its
30
+ * matcher with protectionMatcher, which ignores case (routers like Express's match /API as /api).
31
+ */
28
32
  export declare function matchesEither(matcher: (path: string) => boolean, p: CanonicalPath): boolean;
29
33
  /** An exemption (block.allow) applies only when both forms match. */
30
34
  export declare function matchesBoth(matcher: (path: string) => boolean, p: CanonicalPath): boolean;
@@ -52,6 +52,16 @@ export interface BrowserHeaders {
52
52
  * devices stay coherent: only fetch metadata depends on the version, and only for current ones.
53
53
  */
54
54
  export declare function browserIncoherence(h: BrowserHeaders): string[];
55
+ /**
56
+ * Whether a request presents as a person's browser: a browser's user agent (not a tool's), the
57
+ * fetch metadata every current browser sends to a secure origin (Sec-Fetch-Dest), and nothing
58
+ * incoherent (Accept-Language present, client hints matching the user agent). A script that adds
59
+ * one browser header doesn't pass. Such requests get to run the page and earn their own verdict:
60
+ * pace and claims keyed by an address never apply to them.
61
+ */
62
+ export declare function presentsAsBrowser(h: BrowserHeaders & {
63
+ secFetchDest?: string;
64
+ }): boolean;
55
65
  /**
56
66
  * Paths scanners and agents probe and normal browsing never requests. Matched on the path only;
57
67
  * the forced-browsing evidence needs several distinct families in one investigation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reguard",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Reguard for your server: catch AI agents and tools reverse engineering your web app. app.use(reguard()) serves /_s/*, adds the script tag, verifies verdicts, blocks (or dry-runs) flagged visitors and sends request summaries (hashes and shapes only). Next.js helpers in reguard/next, fetch runtimes in reguard/fetch, Fastify in reguard/fastify, test helpers in reguard/testing.",
5
5
  "keywords": [
6
6
  "reguard",
@@ -113,7 +113,8 @@
113
113
  "url": "https://github.com/cadenticai/reguard-js/issues"
114
114
  },
115
115
  "devDependencies": {
116
- "@re-detect/shared": "0.1.0"
116
+ "@re-detect/shared": "0.1.0",
117
+ "fastify": "5.12.8"
117
118
  },
118
119
  "publishConfig": {
119
120
  "access": "public"