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.
- package/README.md +2 -2
- package/dist/chunks/{chunk-CGXTVKRB.js → chunk-2N762ZXU.js} +152 -37
- package/dist/chunks/{chunk-W4FDH5AD.js → chunk-4RD66ACT.js} +8 -6
- package/dist/chunks/{chunk-PRPLLMXA.js → chunk-GOT54CF4.js} +39 -34
- package/dist/chunks/{chunk-CUIFGML3.js → chunk-RTCPK4MF.js} +82 -36
- package/dist/cjs/fastify.cjs +234 -85
- package/dist/cjs/fetch.cjs +189 -73
- package/dist/cjs/index.cjs +233 -76
- package/dist/cjs/next.cjs +210 -91
- package/dist/cjs/testing.cjs +0 -104
- package/dist/fastify.js +4 -12
- package/dist/fetch.js +3 -3
- package/dist/index.js +3 -3
- package/dist/next.js +24 -22
- package/dist/testing.js +1 -1
- package/dist/types/node/src/fastify.d.ts +15 -7
- package/dist/types/node/src/fetch.d.ts +6 -2
- package/dist/types/node/src/next.d.ts +38 -17
- package/dist/types/shared/src/address.d.ts +25 -6
- package/dist/types/shared/src/collect.d.ts +7 -1
- package/dist/types/shared/src/index.d.ts +5 -0
- package/dist/types/shared/src/paths.d.ts +6 -2
- package/dist/types/shared/src/tools.d.ts +10 -0
- package/dist/types-cjs/node/src/fastify.d.cts +15 -7
- package/dist/types-cjs/node/src/fetch.d.cts +6 -2
- package/dist/types-cjs/node/src/next.d.cts +38 -17
- package/dist/types-cjs/shared/src/address.d.cts +25 -6
- package/dist/types-cjs/shared/src/collect.d.cts +7 -1
- package/dist/types-cjs/shared/src/index.d.cts +5 -0
- package/dist/types-cjs/shared/src/paths.d.cts +6 -2
- package/dist/types-cjs/shared/src/tools.d.cts +10 -0
- package/package.json +3 -2
|
@@ -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.
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
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.
|
|
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"
|