@curless/hotel-storefront 0.68.3 → 0.69.0
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 +23 -0
- package/dist/cidr.d.ts +46 -0
- package/dist/cidr.d.ts.map +1 -0
- package/dist/cidr.js +143 -0
- package/dist/cidr.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/legal.d.ts +7 -1
- package/dist/legal.d.ts.map +1 -1
- package/dist/legal.js +10 -3
- package/dist/legal.js.map +1 -1
- package/dist/lib.d.ts +6 -0
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +5 -0
- package/dist/lib.js.map +1 -1
- package/dist/ranges-check-cli.d.ts +3 -0
- package/dist/ranges-check-cli.d.ts.map +1 -0
- package/dist/ranges-check-cli.js +10 -0
- package/dist/ranges-check-cli.js.map +1 -0
- package/dist/ranges-check.d.ts +39 -0
- package/dist/ranges-check.d.ts.map +1 -0
- package/dist/ranges-check.js +137 -0
- package/dist/ranges-check.js.map +1 -0
- package/dist/server.d.ts +4 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +41 -2
- package/dist/server.js.map +1 -1
- package/dist/source-allowlist.d.ts +95 -0
- package/dist/source-allowlist.d.ts.map +1 -0
- package/dist/source-allowlist.js +250 -0
- package/dist/source-allowlist.js.map +1 -0
- package/dist/source-ranges.d.ts +30 -0
- package/dist/source-ranges.d.ts.map +1 -0
- package/dist/source-ranges.js +376 -0
- package/dist/source-ranges.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type PlatformId, type PlatformRanges } from './source-ranges.js';
|
|
2
|
+
export type SourceMode = 'off' | 'shadow' | 'enforce';
|
|
3
|
+
export declare const SOURCE_MODES: readonly SourceMode[];
|
|
4
|
+
/** `sourceAllowlist` in a deployment's config. */
|
|
5
|
+
export type SourceAllowlistConfig = {
|
|
6
|
+
mode: SourceMode;
|
|
7
|
+
/** Platforms whose published ranges are let in - ids of `PLATFORM_RANGES`. */
|
|
8
|
+
platforms?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Ranges of our own, let in beside the platforms: the host's own addresses
|
|
11
|
+
* its checks run from. ⚠️ Never a person's home or office address.
|
|
12
|
+
*/
|
|
13
|
+
extraCidrs?: string[];
|
|
14
|
+
};
|
|
15
|
+
/** The environment variable that overrides the config's `mode` - a rollback that needs no commit. */
|
|
16
|
+
export declare const SOURCE_MODE_ENV = "HOTEL_SOURCE_ALLOWLIST";
|
|
17
|
+
/** What a request's address was judged to be. `platform` is a `PlatformId` or `extra`. */
|
|
18
|
+
export type SourceVerdict = {
|
|
19
|
+
allowed: true;
|
|
20
|
+
platform: PlatformId | 'extra';
|
|
21
|
+
} | {
|
|
22
|
+
allowed: false;
|
|
23
|
+
reason: 'unlisted' | 'no-address';
|
|
24
|
+
};
|
|
25
|
+
/** The one line a 403 says. Short, and true in any client: no card, no platform list. */
|
|
26
|
+
export declare const REFUSED_SAID = "This MCP server accepts connections only from approved AI platforms, and this request did not come from one.";
|
|
27
|
+
/**
|
|
28
|
+
* Distinct (network, client, user-agent) kept for /healthz/detail, for sessions
|
|
29
|
+
* and for refusals apart - past it, the least seen gives way (audit P3-10: the
|
|
30
|
+
* first hundred were kept for good, and a hundred made-up user-agents filled it).
|
|
31
|
+
*/
|
|
32
|
+
export declare const UNLISTED_KEPT = 100;
|
|
33
|
+
/**
|
|
34
|
+
* The widest range `extraCidrs` takes: /24 for IPv4, /48 for IPv6 (audit P2-3).
|
|
35
|
+
* It is for our own hosts' addresses; 0.0.0.0/0 there let everybody in, and
|
|
36
|
+
* said only `extra(1)` at start.
|
|
37
|
+
*/
|
|
38
|
+
export declare const EXTRA_MIN_PREFIX: {
|
|
39
|
+
readonly 4: 24;
|
|
40
|
+
readonly 6: 48;
|
|
41
|
+
};
|
|
42
|
+
/** Refusals logged per network in `REFUSED_LOG_WINDOW_MS`; every one is still counted. */
|
|
43
|
+
export declare const REFUSED_LOGS_PER_NETWORK = 3;
|
|
44
|
+
export declare const REFUSED_LOG_WINDOW_MS: number;
|
|
45
|
+
/**
|
|
46
|
+
* The config's `sourceAllowlist`, checked - or an Error that says what is
|
|
47
|
+
* wrong. Thrown at start (server.ts `loadConfig` and `buildServer`): a mistyped
|
|
48
|
+
* allowlist found out by the first platform turned away is found out too late.
|
|
49
|
+
*/
|
|
50
|
+
export declare const checkSourceAllowlist: (value: unknown, ranges?: readonly PlatformRanges[]) => SourceAllowlistConfig | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The address a request came from, for the allowlist.
|
|
53
|
+
*
|
|
54
|
+
* The last X-Forwarded-For entry (server.ts `clientIp`) is the one our proxy
|
|
55
|
+
* added - when there is a proxy. ⚠️ A REQUEST WHOSE OWN CONNECTION COMES FROM A
|
|
56
|
+
* PUBLIC ADDRESS HAD NONE (audit P3-8): it reached us directly - a port left
|
|
57
|
+
* open - and its header is its own to write. Its connection's address is then
|
|
58
|
+
* the source. A private or loopback connection is our proxy's (or our own
|
|
59
|
+
* host's), and the header is believed.
|
|
60
|
+
*/
|
|
61
|
+
export declare const sourceAddress: (lastForwarded: string | undefined, peer: string | undefined) => string | undefined;
|
|
62
|
+
export type SourceAllowlist = {
|
|
63
|
+
mode: Exclude<SourceMode, 'off'>;
|
|
64
|
+
/** Where the mode came from - the config, or `HOTEL_SOURCE_ALLOWLIST`. */
|
|
65
|
+
modeFrom: 'config' | 'env';
|
|
66
|
+
judge: (ip: string | undefined) => SourceVerdict;
|
|
67
|
+
/** A new session (`initialize`) let through: one log line, one count. */
|
|
68
|
+
noteSession: (ip: string | undefined, verdict: SourceVerdict, said: {
|
|
69
|
+
client?: string;
|
|
70
|
+
ua?: string;
|
|
71
|
+
session?: string;
|
|
72
|
+
}) => void;
|
|
73
|
+
/** A request refused (enforce): counted, and logged a few times a network. */
|
|
74
|
+
noteRefused: (ip: string | undefined, verdict: SourceVerdict, ua: string | undefined) => void;
|
|
75
|
+
/** What /healthz/detail shows. */
|
|
76
|
+
health: () => Record<string, unknown>;
|
|
77
|
+
/** One line for the boot banner. */
|
|
78
|
+
summary: string;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The allowlist a deployment runs with - or undefined when it is off (no
|
|
82
|
+
* `sourceAllowlist`, `mode: "off"`, or `HOTEL_SOURCE_ALLOWLIST=off`).
|
|
83
|
+
*
|
|
84
|
+
* ⚠️ `HOTEL_SOURCE_ALLOWLIST` OVERRIDES THE MODE, NOT THE LISTS: it turns a
|
|
85
|
+
* configured allowlist off, to shadow or to enforce without a commit to the
|
|
86
|
+
* brand's repository - the way back when a platform has moved and its guests
|
|
87
|
+
* are being turned away. Set with no `sourceAllowlist` in the config, it is
|
|
88
|
+
* refused: there would be nothing to let in.
|
|
89
|
+
*/
|
|
90
|
+
export declare const makeSourceAllowlist: (configured: unknown, env?: Record<string, string | undefined>, opts?: {
|
|
91
|
+
ranges?: readonly PlatformRanges[];
|
|
92
|
+
now?: () => number;
|
|
93
|
+
log?: (line: string) => void;
|
|
94
|
+
}) => SourceAllowlist | undefined;
|
|
95
|
+
//# sourceMappingURL=source-allowlist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-allowlist.d.ts","sourceRoot":"","sources":["../src/source-allowlist.ts"],"names":[],"mappings":"AAUA,OAAO,EAAmB,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAsB3F,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AACtD,eAAO,MAAM,YAAY,EAAE,SAAS,UAAU,EAAiC,CAAC;AAEhF,kDAAkD;AAClD,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACr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,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KACrD,IAAI,CAAC;IACV,8EAA8E;IAC9E,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAC9F,kCAAkC;IAClC,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAC9B,YAAY,OAAO,EACnB,MAAK,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAM,EAC5C,OAAM;IACJ,MAAM,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;IACnC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACzB,KACL,eAAe,GAAG,SAkIpB,CAAC"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { formatAddress, inCidr, isPrivateAddress, networkOfAddress, parseAddress, parseCidr, } from './cidr.js';
|
|
2
|
+
import { PLATFORM_RANGES } from './source-ranges.js';
|
|
3
|
+
export const SOURCE_MODES = ['off', 'shadow', 'enforce'];
|
|
4
|
+
/** The environment variable that overrides the config's `mode` - a rollback that needs no commit. */
|
|
5
|
+
export const SOURCE_MODE_ENV = 'HOTEL_SOURCE_ALLOWLIST';
|
|
6
|
+
/** The one line a 403 says. Short, and true in any client: no card, no platform list. */
|
|
7
|
+
export const REFUSED_SAID = 'This MCP server accepts connections only from approved AI platforms, and this request did not come from one.';
|
|
8
|
+
/**
|
|
9
|
+
* Distinct (network, client, user-agent) kept for /healthz/detail, for sessions
|
|
10
|
+
* and for refusals apart - past it, the least seen gives way (audit P3-10: the
|
|
11
|
+
* first hundred were kept for good, and a hundred made-up user-agents filled it).
|
|
12
|
+
*/
|
|
13
|
+
export const UNLISTED_KEPT = 100;
|
|
14
|
+
/**
|
|
15
|
+
* The widest range `extraCidrs` takes: /24 for IPv4, /48 for IPv6 (audit P2-3).
|
|
16
|
+
* It is for our own hosts' addresses; 0.0.0.0/0 there let everybody in, and
|
|
17
|
+
* said only `extra(1)` at start.
|
|
18
|
+
*/
|
|
19
|
+
export const EXTRA_MIN_PREFIX = { 4: 24, 6: 48 };
|
|
20
|
+
/** Refusals logged per network in `REFUSED_LOG_WINDOW_MS`; every one is still counted. */
|
|
21
|
+
export const REFUSED_LOGS_PER_NETWORK = 3;
|
|
22
|
+
export const REFUSED_LOG_WINDOW_MS = 10 * 60_000;
|
|
23
|
+
const KEYS = new Set(['mode', 'platforms', 'extraCidrs']);
|
|
24
|
+
/** A value from a request, safe on one log line: printable ASCII, cut short. */
|
|
25
|
+
const printable = (s, max) => s.replace(/[^\x20-\x7e]/g, '?').slice(0, max);
|
|
26
|
+
/**
|
|
27
|
+
* The config's `sourceAllowlist`, checked - or an Error that says what is
|
|
28
|
+
* wrong. Thrown at start (server.ts `loadConfig` and `buildServer`): a mistyped
|
|
29
|
+
* allowlist found out by the first platform turned away is found out too late.
|
|
30
|
+
*/
|
|
31
|
+
export const checkSourceAllowlist = (value, ranges = PLATFORM_RANGES) => {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
const fail = (what) => {
|
|
35
|
+
throw new Error(`sourceAllowlist: ${what}`);
|
|
36
|
+
};
|
|
37
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
38
|
+
fail('must be an object { mode, platforms, extraCidrs }');
|
|
39
|
+
}
|
|
40
|
+
const v = value;
|
|
41
|
+
for (const k of Object.keys(v)) {
|
|
42
|
+
if (!KEYS.has(k))
|
|
43
|
+
fail(`unknown key "${k}" - the keys are mode, platforms, extraCidrs`);
|
|
44
|
+
}
|
|
45
|
+
if (!SOURCE_MODES.includes(v.mode)) {
|
|
46
|
+
fail(`mode must be one of ${SOURCE_MODES.join(', ')} (it is ${JSON.stringify(v.mode)})`);
|
|
47
|
+
}
|
|
48
|
+
const known = new Set(ranges.map((r) => r.id));
|
|
49
|
+
if (v.platforms !== undefined) {
|
|
50
|
+
if (!Array.isArray(v.platforms))
|
|
51
|
+
fail('platforms must be an array of platform ids');
|
|
52
|
+
for (const p of v.platforms) {
|
|
53
|
+
if (typeof p !== 'string' || !known.has(p)) {
|
|
54
|
+
fail(`unknown platform ${JSON.stringify(p)} - the platforms are ${[...known].join(', ')}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (v.extraCidrs !== undefined) {
|
|
59
|
+
if (!Array.isArray(v.extraCidrs))
|
|
60
|
+
fail('extraCidrs must be an array of ranges');
|
|
61
|
+
for (const c of v.extraCidrs) {
|
|
62
|
+
const cidr = typeof c === 'string' ? parseCidr(c) : undefined;
|
|
63
|
+
if (!cidr) {
|
|
64
|
+
fail(`extraCidrs: ${JSON.stringify(c)} is not a range written exactly (an address, or address/prefix with no bits set past the prefix)`);
|
|
65
|
+
}
|
|
66
|
+
else if (cidr.bits < EXTRA_MIN_PREFIX[cidr.v]) {
|
|
67
|
+
fail(`extraCidrs: ${JSON.stringify(c)} is wider than /${EXTRA_MIN_PREFIX[cidr.v]} - it is for our own hosts' addresses, not a network of strangers`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const platforms = v.platforms ?? [];
|
|
72
|
+
const extra = v.extraCidrs ?? [];
|
|
73
|
+
// ⚠️ BY THE RANGES, NOT THE NAMES (audit P2-2): platforms that publish none
|
|
74
|
+
// (Manus, Muse, Google) let nobody in, and would have turned everyone away.
|
|
75
|
+
if (v.mode !== 'off' && rangesOf(platforms, ranges) + extra.length === 0) {
|
|
76
|
+
fail(`lets nobody in - ${platforms.length ? `${platforms.join(', ')} publish no ranges; ` : ''}name a platform with ranges, or extraCidrs, or set mode "off"`);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
mode: v.mode,
|
|
80
|
+
...(v.platforms !== undefined ? { platforms } : {}),
|
|
81
|
+
...(v.extraCidrs !== undefined ? { extraCidrs: extra } : {}),
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/** How many ranges these platforms publish, together. */
|
|
85
|
+
const rangesOf = (platforms, ranges) => [...new Set(platforms)].reduce((n, id) => n + (ranges.find((r) => r.id === id)?.sources ?? []).reduce((m, s) => m + s.cidrs.length, 0), 0);
|
|
86
|
+
/**
|
|
87
|
+
* The address a request came from, for the allowlist.
|
|
88
|
+
*
|
|
89
|
+
* The last X-Forwarded-For entry (server.ts `clientIp`) is the one our proxy
|
|
90
|
+
* added - when there is a proxy. ⚠️ A REQUEST WHOSE OWN CONNECTION COMES FROM A
|
|
91
|
+
* PUBLIC ADDRESS HAD NONE (audit P3-8): it reached us directly - a port left
|
|
92
|
+
* open - and its header is its own to write. Its connection's address is then
|
|
93
|
+
* the source. A private or loopback connection is our proxy's (or our own
|
|
94
|
+
* host's), and the header is believed.
|
|
95
|
+
*/
|
|
96
|
+
export const sourceAddress = (lastForwarded, peer) => {
|
|
97
|
+
const p = parseAddress(peer);
|
|
98
|
+
return p && !isPrivateAddress(p) ? peer : lastForwarded;
|
|
99
|
+
};
|
|
100
|
+
/** Counts by key, at most `max` keys: past it, the least seen gives way to the new one. */
|
|
101
|
+
const tally = (max) => {
|
|
102
|
+
const m = new Map();
|
|
103
|
+
return {
|
|
104
|
+
add: (network, client, ua) => {
|
|
105
|
+
const key = `${network}\n${client}\n${ua}`;
|
|
106
|
+
const seen = m.get(key);
|
|
107
|
+
if (seen) {
|
|
108
|
+
seen.count += 1;
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (m.size >= max) {
|
|
112
|
+
let least;
|
|
113
|
+
let fewest = Number.POSITIVE_INFINITY;
|
|
114
|
+
for (const [k, v] of m) {
|
|
115
|
+
if (v.count < fewest) {
|
|
116
|
+
fewest = v.count;
|
|
117
|
+
least = k;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (least !== undefined)
|
|
121
|
+
m.delete(least);
|
|
122
|
+
}
|
|
123
|
+
m.set(key, { network, client, ua, count: 1 });
|
|
124
|
+
},
|
|
125
|
+
list: () => [...m.values()].sort((a, b) => b.count - a.count).map((u) => ({ ...u })),
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* The allowlist a deployment runs with - or undefined when it is off (no
|
|
130
|
+
* `sourceAllowlist`, `mode: "off"`, or `HOTEL_SOURCE_ALLOWLIST=off`).
|
|
131
|
+
*
|
|
132
|
+
* ⚠️ `HOTEL_SOURCE_ALLOWLIST` OVERRIDES THE MODE, NOT THE LISTS: it turns a
|
|
133
|
+
* configured allowlist off, to shadow or to enforce without a commit to the
|
|
134
|
+
* brand's repository - the way back when a platform has moved and its guests
|
|
135
|
+
* are being turned away. Set with no `sourceAllowlist` in the config, it is
|
|
136
|
+
* refused: there would be nothing to let in.
|
|
137
|
+
*/
|
|
138
|
+
export const makeSourceAllowlist = (configured, env = {}, opts = {}) => {
|
|
139
|
+
const ranges = opts.ranges ?? PLATFORM_RANGES;
|
|
140
|
+
const now = opts.now ?? (() => Date.now());
|
|
141
|
+
const log = opts.log ?? ((line) => console.log(line));
|
|
142
|
+
const cfg = checkSourceAllowlist(configured, ranges);
|
|
143
|
+
// Any case (audit P3-13): OFF in a hurry must not stop the start.
|
|
144
|
+
const fromEnv = env[SOURCE_MODE_ENV]?.trim().toLowerCase();
|
|
145
|
+
if (fromEnv !== undefined && fromEnv !== '') {
|
|
146
|
+
if (!SOURCE_MODES.includes(fromEnv)) {
|
|
147
|
+
throw new Error(`${SOURCE_MODE_ENV} must be one of ${SOURCE_MODES.join(', ')} (it is ${JSON.stringify(fromEnv)})`);
|
|
148
|
+
}
|
|
149
|
+
if (!cfg && fromEnv !== 'off') {
|
|
150
|
+
throw new Error(`${SOURCE_MODE_ENV}=${fromEnv}, but the config has no sourceAllowlist - there is nothing to let in`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const mode = (fromEnv || cfg?.mode || 'off');
|
|
154
|
+
if (!cfg || mode === 'off')
|
|
155
|
+
return undefined;
|
|
156
|
+
const modeFrom = fromEnv ? 'env' : 'config';
|
|
157
|
+
const entries = [];
|
|
158
|
+
const platformIds = [...new Set(cfg.platforms ?? [])];
|
|
159
|
+
const rangeCount = {};
|
|
160
|
+
for (const id of platformIds) {
|
|
161
|
+
const p = ranges.find((r) => r.id === id);
|
|
162
|
+
const cidrs = (p?.sources ?? []).flatMap((s) => s.cidrs);
|
|
163
|
+
rangeCount[id] = cidrs.length;
|
|
164
|
+
for (const c of cidrs) {
|
|
165
|
+
const cidr = parseCidr(c);
|
|
166
|
+
// The file is checked by its own test; a range it holds that does not
|
|
167
|
+
// read is a release that must not start.
|
|
168
|
+
if (!cidr)
|
|
169
|
+
throw new Error(`source-ranges: ${id} holds ${JSON.stringify(c)}, not a range`);
|
|
170
|
+
entries.push({ cidr, platform: id });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (const c of cfg.extraCidrs ?? []) {
|
|
174
|
+
entries.push({ cidr: parseCidr(c), platform: 'extra' });
|
|
175
|
+
}
|
|
176
|
+
rangeCount.extra = (cfg.extraCidrs ?? []).length;
|
|
177
|
+
// A config written with mode "off" is checked as off; turned on by the
|
|
178
|
+
// environment, it must still let somebody in (audit P2-2).
|
|
179
|
+
if (!entries.length) {
|
|
180
|
+
throw new Error(`sourceAllowlist: ${mode}${modeFrom === 'env' ? ` (${SOURCE_MODE_ENV})` : ''} would let nobody in - no platform named has ranges, and there are no extraCidrs`);
|
|
181
|
+
}
|
|
182
|
+
const match = (a) => entries.find((e) => inCidr(a, e.cidr))?.platform;
|
|
183
|
+
const judge = (ip) => {
|
|
184
|
+
const a = parseAddress(ip);
|
|
185
|
+
if (!a)
|
|
186
|
+
return { allowed: false, reason: 'no-address' };
|
|
187
|
+
const platform = match(a);
|
|
188
|
+
return platform ? { allowed: true, platform } : { allowed: false, reason: 'unlisted' };
|
|
189
|
+
};
|
|
190
|
+
/** How an address is written on a log line: a platform's whole; anybody else's network only. */
|
|
191
|
+
const shown = (ip, verdict) => {
|
|
192
|
+
const a = parseAddress(ip);
|
|
193
|
+
if (!a)
|
|
194
|
+
return '-';
|
|
195
|
+
// As parsed, never as sent: what followed an address stays off the line (audit P3-9).
|
|
196
|
+
return verdict.allowed ? formatAddress(a) : networkOfAddress(a);
|
|
197
|
+
};
|
|
198
|
+
const since = new Date(now()).toISOString();
|
|
199
|
+
const sessions = Object.fromEntries([...platformIds, 'extra', 'unlisted', 'no-address'].map((k) => [k, 0]));
|
|
200
|
+
let refused = 0;
|
|
201
|
+
const unlisted = tally(UNLISTED_KEPT);
|
|
202
|
+
const refusedBy = tally(UNLISTED_KEPT);
|
|
203
|
+
const refusedLogs = new Map();
|
|
204
|
+
const noteSession = (ip, verdict, said) => {
|
|
205
|
+
const key = verdict.allowed ? verdict.platform : verdict.reason;
|
|
206
|
+
sessions[key] = (sessions[key] ?? 0) + 1;
|
|
207
|
+
const client = printable(said.client ?? '-', 60);
|
|
208
|
+
const ua = printable(said.ua ?? '-', 120);
|
|
209
|
+
if (!verdict.allowed)
|
|
210
|
+
unlisted.add(shown(ip, verdict), client, ua);
|
|
211
|
+
log(`[source] ${mode} session ${verdict.allowed ? `allowed platform=${verdict.platform}` : `not-allowed reason=${verdict.reason}`} ip=${shown(ip, verdict)} client=${JSON.stringify(client)} ua=${JSON.stringify(ua)}${said.session ? ` s=${said.session}` : ''}`);
|
|
212
|
+
};
|
|
213
|
+
const noteRefused = (ip, verdict, uaRaw) => {
|
|
214
|
+
refused += 1;
|
|
215
|
+
const network = shown(ip, verdict);
|
|
216
|
+
const ua = printable(uaRaw ?? '-', 120);
|
|
217
|
+
refusedBy.add(network, '-', ua);
|
|
218
|
+
const t = now();
|
|
219
|
+
const seen = refusedLogs.get(network);
|
|
220
|
+
if (!seen || t - seen.at > REFUSED_LOG_WINDOW_MS) {
|
|
221
|
+
if (refusedLogs.size > 10_000)
|
|
222
|
+
refusedLogs.clear();
|
|
223
|
+
refusedLogs.set(network, { at: t, n: 1 });
|
|
224
|
+
}
|
|
225
|
+
else if (seen.n < REFUSED_LOGS_PER_NETWORK) {
|
|
226
|
+
seen.n += 1;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
log(`[source] enforce refused reason=${verdict.allowed ? '-' : verdict.reason} ip=${network} ua=${JSON.stringify(ua)}`);
|
|
232
|
+
};
|
|
233
|
+
const health = () => ({
|
|
234
|
+
mode,
|
|
235
|
+
modeFrom,
|
|
236
|
+
since,
|
|
237
|
+
ranges: { ...rangeCount },
|
|
238
|
+
sessions: { ...sessions },
|
|
239
|
+
unlisted: unlisted.list(),
|
|
240
|
+
...(mode === 'enforce' ? { refused, refusedBy: refusedBy.list() } : {}),
|
|
241
|
+
});
|
|
242
|
+
const empty = platformIds.filter((id) => rangeCount[id] === 0);
|
|
243
|
+
const summary = `${mode}${modeFrom === 'env' ? ` (${SOURCE_MODE_ENV})` : ''}: ${platformIds
|
|
244
|
+
.map((id) => `${id}(${rangeCount[id]})`)
|
|
245
|
+
.join(', ')}${rangeCount.extra ? `${platformIds.length ? ', ' : ''}extra(${rangeCount.extra})` : ''}${empty.length
|
|
246
|
+
? ` - ⚠️ no published ranges for ${empty.join(', ')}: ${mode === 'enforce' ? 'refused' : 'would be refused'} unless extraCidrs name them`
|
|
247
|
+
: ''}`;
|
|
248
|
+
return { mode, modeFrom, judge, noteSession, noteRefused, health, summary };
|
|
249
|
+
};
|
|
250
|
+
//# sourceMappingURL=source-allowlist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-allowlist.js","sourceRoot":"","sources":["../src/source-allowlist.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL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AW,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC9E,CAAC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type PlatformId = 'anthropic' | 'openai' | 'google' | 'manus' | 'muse';
|
|
2
|
+
/** How `ranges-check` reads a source again: the page or file, and its shape. */
|
|
3
|
+
export type RangesFormat = 'anthropic-ip-page' | 'openai-prefixes-json';
|
|
4
|
+
export type RangeSource = {
|
|
5
|
+
/** The official page or file the ranges were read from. */
|
|
6
|
+
url: string;
|
|
7
|
+
/** The day they were read, YYYY-MM-DD. */
|
|
8
|
+
checked: string;
|
|
9
|
+
format: RangesFormat;
|
|
10
|
+
/** The file's own date or version, when it has one (OpenAI's `creationTime`). */
|
|
11
|
+
version?: string;
|
|
12
|
+
/** What the source says the ranges are for, in its own words (short). */
|
|
13
|
+
says: string;
|
|
14
|
+
cidrs: string[];
|
|
15
|
+
};
|
|
16
|
+
export type PlatformRanges = {
|
|
17
|
+
id: PlatformId;
|
|
18
|
+
name: string;
|
|
19
|
+
sources: RangeSource[];
|
|
20
|
+
/** A platform that publishes no ranges: where we looked, and when. */
|
|
21
|
+
unpublished?: {
|
|
22
|
+
checked: string;
|
|
23
|
+
looked: string[];
|
|
24
|
+
note: string;
|
|
25
|
+
};
|
|
26
|
+
/** What else is worth knowing about its ranges. */
|
|
27
|
+
note?: string;
|
|
28
|
+
};
|
|
29
|
+
export declare const PLATFORM_RANGES: readonly PlatformRanges[];
|
|
30
|
+
//# sourceMappingURL=source-ranges.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-ranges.d.ts","sourceRoot":"","sources":["../src/source-ranges.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAE9E,gFAAgF;AAChF,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,sBAAsB,CAAC;AAExE,MAAM,MAAM,WAAW,GAAG;IACxB,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;IACZ,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;IACrB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,UAAU,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,sEAAsE;IACtE,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAClE,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,SAAS,cAAc,EAwWpD,CAAC"}
|