@kya-os/checkpoint-shared 1.4.0 → 1.5.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/CHANGELOG.md +41 -0
- package/dist/beacon-types/index.d.mts +448 -432
- package/dist/beacon-types/index.d.mts.map +1 -0
- package/dist/beacon-types/index.d.ts +448 -432
- package/dist/beacon-types/index.d.ts.map +1 -0
- package/dist/beacon-types/index.js +286 -182
- package/dist/beacon-types/index.mjs +284 -180
- package/dist/beacon-types/index.mjs.map +1 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts +5 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.mts.map +1 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts +5 -0
- package/dist/browser-posture-cookie-Dmq9Brf_.d.ts.map +1 -0
- package/dist/browser-posture-cookie.d.mts +2 -0
- package/dist/browser-posture-cookie.d.ts +2 -0
- package/dist/browser-posture-cookie.js +1 -0
- package/dist/browser-posture-cookie.mjs +2 -0
- package/dist/browser-posture-cookie.mjs.map +1 -0
- package/dist/browser-posture-report.d.mts +48 -44
- package/dist/browser-posture-report.d.mts.map +1 -0
- package/dist/browser-posture-report.d.ts +48 -44
- package/dist/browser-posture-report.d.ts.map +1 -0
- package/dist/browser-posture-report.js +1 -1
- package/dist/browser-posture-report.mjs +2 -1
- package/dist/browser-posture-report.mjs.map +1 -0
- package/dist/browser-posture.d.mts +82 -75
- package/dist/browser-posture.d.mts.map +1 -0
- package/dist/browser-posture.d.ts +82 -75
- package/dist/browser-posture.d.ts.map +1 -0
- package/dist/browser-posture.js +167 -18993
- package/dist/browser-posture.mjs +166 -18990
- package/dist/browser-posture.mjs.map +1 -0
- package/dist/browser.d.mts +323 -316
- package/dist/browser.d.mts.map +1 -0
- package/dist/browser.d.ts +323 -316
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +1 -1
- package/dist/browser.mjs +2 -1
- package/dist/browser.mjs.map +1 -0
- package/dist/canonical-signer/index.d.mts +38 -33
- package/dist/canonical-signer/index.d.mts.map +1 -0
- package/dist/canonical-signer/index.d.ts +38 -33
- package/dist/canonical-signer/index.d.ts.map +1 -0
- package/dist/canonical-signer/index.js +411 -181
- package/dist/canonical-signer/index.mjs +383 -175
- package/dist/canonical-signer/index.mjs.map +1 -0
- package/dist/clearance.d.mts +30 -0
- package/dist/clearance.d.mts.map +1 -0
- package/dist/clearance.d.ts +30 -0
- package/dist/clearance.d.ts.map +1 -0
- package/dist/clearance.js +120 -0
- package/dist/clearance.mjs +112 -0
- package/dist/clearance.mjs.map +1 -0
- package/dist/client-ip-1y2iXAYW.js +237 -0
- package/dist/client-ip-HOfe6ucV.mjs +215 -0
- package/dist/client-ip-HOfe6ucV.mjs.map +1 -0
- package/dist/deploy/index.d.mts +339 -339
- package/dist/deploy/index.d.mts.map +1 -0
- package/dist/deploy/index.d.ts +339 -339
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js +505 -413
- package/dist/deploy/index.mjs +504 -410
- package/dist/deploy/index.mjs.map +1 -0
- package/dist/errors/index.d.mts +101 -101
- package/dist/errors/index.d.mts.map +1 -0
- package/dist/errors/index.d.ts +101 -101
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +341 -314
- package/dist/errors/index.mjs +340 -311
- package/dist/errors/index.mjs.map +1 -0
- package/dist/external-jr_S4iSS.d.mts +4187 -0
- package/dist/external-jr_S4iSS.d.mts.map +1 -0
- package/dist/external-jr_S4iSS.d.ts +4187 -0
- package/dist/external-jr_S4iSS.d.ts.map +1 -0
- package/dist/gateway/index.d.mts +138 -132
- package/dist/gateway/index.d.mts.map +1 -0
- package/dist/gateway/index.d.ts +138 -132
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +117 -81
- package/dist/gateway/index.mjs +116 -78
- package/dist/gateway/index.mjs.map +1 -0
- package/dist/gateway-client-ip.d.mts +59 -0
- package/dist/gateway-client-ip.d.mts.map +1 -0
- package/dist/gateway-client-ip.d.ts +59 -0
- package/dist/gateway-client-ip.d.ts.map +1 -0
- package/dist/gateway-client-ip.js +149 -0
- package/dist/gateway-client-ip.mjs +139 -0
- package/dist/gateway-client-ip.mjs.map +1 -0
- package/dist/index.d.mts +14901 -14246
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +14901 -14246
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15180 -31025
- package/dist/index.mjs +15065 -30942
- package/dist/index.mjs.map +1 -0
- package/dist/mcpi/agentshield-api/index.d.mts +45 -44
- package/dist/mcpi/agentshield-api/index.d.mts.map +1 -0
- package/dist/mcpi/agentshield-api/index.d.ts +45 -44
- package/dist/mcpi/agentshield-api/index.d.ts.map +1 -0
- package/dist/mcpi/agentshield-api/index.js +0 -2
- package/dist/mcpi/agentshield-api/index.mjs +1 -1
- package/dist/mcpi/approval-grant/index.d.mts +63 -61
- package/dist/mcpi/approval-grant/index.d.mts.map +1 -0
- package/dist/mcpi/approval-grant/index.d.ts +63 -61
- package/dist/mcpi/approval-grant/index.d.ts.map +1 -0
- package/dist/mcpi/approval-grant/index.js +220 -140
- package/dist/mcpi/approval-grant/index.mjs +219 -137
- package/dist/mcpi/approval-grant/index.mjs.map +1 -0
- package/dist/mcpi/dashboard-config/index.d.mts +2323 -2318
- package/dist/mcpi/dashboard-config/index.d.mts.map +1 -0
- package/dist/mcpi/dashboard-config/index.d.ts +2323 -2318
- package/dist/mcpi/dashboard-config/index.d.ts.map +1 -0
- package/dist/mcpi/dashboard-config/index.js +605 -458
- package/dist/mcpi/dashboard-config/index.mjs +604 -455
- package/dist/mcpi/dashboard-config/index.mjs.map +1 -0
- package/dist/mcpi/multibase-ed25519.d.mts +10 -8
- package/dist/mcpi/multibase-ed25519.d.mts.map +1 -0
- package/dist/mcpi/multibase-ed25519.d.ts +10 -8
- package/dist/mcpi/multibase-ed25519.d.ts.map +1 -0
- package/dist/mcpi/multibase-ed25519.js +182 -106
- package/dist/mcpi/multibase-ed25519.mjs +181 -103
- package/dist/mcpi/multibase-ed25519.mjs.map +1 -0
- package/dist/patterns-CkRVOdtV.js +243 -0
- package/dist/patterns-DzkGy_qk.mjs +173 -0
- package/dist/patterns-DzkGy_qk.mjs.map +1 -0
- package/dist/project-verification-key-C3L5rd8a.js +41 -0
- package/dist/project-verification-key-CgSVX9_m.mjs +37 -0
- package/dist/project-verification-key-CgSVX9_m.mjs.map +1 -0
- package/dist/rolldown-runtime-iY2fYEqi.mjs +19 -0
- package/dist/schemas-BmjNLAE7.js +5677 -0
- package/dist/schemas-DxY-dk9y.mjs +5511 -0
- package/dist/schemas-DxY-dk9y.mjs.map +1 -0
- package/dist/signals/index.d.mts +125 -115
- package/dist/signals/index.d.mts.map +1 -0
- package/dist/signals/index.d.ts +125 -115
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +1693 -1536
- package/dist/signals/index.mjs +1692 -1533
- package/dist/signals/index.mjs.map +1 -0
- package/dist/test-fixtures/index.d.mts +124 -119
- package/dist/test-fixtures/index.d.mts.map +1 -0
- package/dist/test-fixtures/index.d.ts +124 -119
- package/dist/test-fixtures/index.d.ts.map +1 -0
- package/dist/test-fixtures/index.js +460 -228
- package/dist/test-fixtures/index.mjs +459 -225
- package/dist/test-fixtures/index.mjs.map +1 -0
- package/dist/tool-protection/index.d.mts +343 -343
- package/dist/tool-protection/index.d.mts.map +1 -0
- package/dist/tool-protection/index.d.ts +343 -343
- package/dist/tool-protection/index.d.ts.map +1 -0
- package/dist/tool-protection/index.js +366 -285
- package/dist/tool-protection/index.mjs +365 -282
- package/dist/tool-protection/index.mjs.map +1 -0
- package/fixtures/bot-signal-resolution.json +142 -0
- package/fixtures/browser-posture-claims.json +421 -0
- package/fixtures/browser-posture-headers.json +46 -0
- package/fixtures/detection/reason-codes.json +10 -1
- package/fixtures/kya-http/challenge.delegation.fetcher-200.json +9 -3
- package/fixtures/kya-http/challenge.delegation.full.json +9 -3
- package/fixtures/kya-http/challenge.delegation.minimal.json +9 -3
- package/fixtures/kya-http/error-codes.json +7 -2
- package/package.json +20 -6
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
//#region src/utils/client-ip.ts
|
|
2
|
+
const MAX_INPUT_LENGTH = 4096;
|
|
3
|
+
const MAX_TOKEN_LENGTH = 128;
|
|
4
|
+
const MAX_FORWARDED_HOPS = 32;
|
|
5
|
+
function hasControlCharacter(value) {
|
|
6
|
+
for (let i = 0; i < value.length; i++) {
|
|
7
|
+
const code = value.charCodeAt(i);
|
|
8
|
+
if (code <= 31 || code === 127) return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
function parsePort(value) {
|
|
13
|
+
return /^(?:0|[1-9]\d{0,4})$/.test(value) && Number(value) <= 65535;
|
|
14
|
+
}
|
|
15
|
+
function parseIpv4(value) {
|
|
16
|
+
const parts = value.split(".");
|
|
17
|
+
if (parts.length !== 4) return null;
|
|
18
|
+
const octets = [];
|
|
19
|
+
for (const part of parts) {
|
|
20
|
+
if (!/^\d{1,3}$/.test(part)) return null;
|
|
21
|
+
const octet = Number(part);
|
|
22
|
+
if (octet > 255) return null;
|
|
23
|
+
octets.push(octet);
|
|
24
|
+
}
|
|
25
|
+
return octets;
|
|
26
|
+
}
|
|
27
|
+
function parseHexGroup(value) {
|
|
28
|
+
if (!/^[0-9a-fA-F]{1,4}$/.test(value)) return null;
|
|
29
|
+
return Number.parseInt(value, 16);
|
|
30
|
+
}
|
|
31
|
+
/** Parses a bare IPv6 address into its 8 groups (`::` expanded). Exported for reuse by anything that needs to mask/truncate an address (see `anonymize-ip.ts`), not just resolve one. */
|
|
32
|
+
function parseIpv6(value) {
|
|
33
|
+
if (!value || value.includes("%") || hasControlCharacter(value)) return null;
|
|
34
|
+
let address = value;
|
|
35
|
+
if (address.includes(".")) {
|
|
36
|
+
const lastColon = address.lastIndexOf(":");
|
|
37
|
+
if (lastColon < 0) return null;
|
|
38
|
+
const ipv4 = parseIpv4(address.slice(lastColon + 1));
|
|
39
|
+
if (!ipv4) return null;
|
|
40
|
+
const first = ipv4[0] << 8 | ipv4[1];
|
|
41
|
+
const second = ipv4[2] << 8 | ipv4[3];
|
|
42
|
+
address = `${address.slice(0, lastColon + 1)}${first.toString(16)}:${second.toString(16)}`;
|
|
43
|
+
}
|
|
44
|
+
const doubleColon = address.indexOf("::");
|
|
45
|
+
if (doubleColon !== address.lastIndexOf("::")) return null;
|
|
46
|
+
const parseGroups = (part) => {
|
|
47
|
+
if (!part) return [];
|
|
48
|
+
const groups = part.split(":");
|
|
49
|
+
const parsed = [];
|
|
50
|
+
for (const group of groups) {
|
|
51
|
+
const number = parseHexGroup(group);
|
|
52
|
+
if (number === null) return null;
|
|
53
|
+
parsed.push(number);
|
|
54
|
+
}
|
|
55
|
+
return parsed;
|
|
56
|
+
};
|
|
57
|
+
if (doubleColon >= 0) {
|
|
58
|
+
const head = parseGroups(address.slice(0, doubleColon));
|
|
59
|
+
const tail = parseGroups(address.slice(doubleColon + 2));
|
|
60
|
+
if (!head || !tail) return null;
|
|
61
|
+
const missing = 8 - head.length - tail.length;
|
|
62
|
+
if (missing < 1) return null;
|
|
63
|
+
return [
|
|
64
|
+
...head,
|
|
65
|
+
...Array(missing).fill(0),
|
|
66
|
+
...tail
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const groups = parseGroups(address);
|
|
70
|
+
return groups?.length === 8 ? groups : null;
|
|
71
|
+
}
|
|
72
|
+
/** RFC 5952 canonical `::` compression for 8 IPv6 groups. Exported alongside `parseIpv6`. */
|
|
73
|
+
function compressIpv6(groups) {
|
|
74
|
+
const rendered = groups.map((group) => group.toString(16));
|
|
75
|
+
let bestStart = -1;
|
|
76
|
+
let bestLength = 1;
|
|
77
|
+
let runStart = -1;
|
|
78
|
+
for (let index = 0; index <= groups.length; index += 1) {
|
|
79
|
+
if (index < groups.length && groups[index] === 0) {
|
|
80
|
+
if (runStart < 0) runStart = index;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (runStart >= 0) {
|
|
84
|
+
const runLength = index - runStart;
|
|
85
|
+
if (runLength > bestLength) {
|
|
86
|
+
bestStart = runStart;
|
|
87
|
+
bestLength = runLength;
|
|
88
|
+
}
|
|
89
|
+
runStart = -1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (bestStart < 0) return rendered.join(":");
|
|
93
|
+
const before = rendered.slice(0, bestStart).join(":");
|
|
94
|
+
const after = rendered.slice(bestStart + bestLength).join(":");
|
|
95
|
+
if (!before && !after) return "::";
|
|
96
|
+
if (!before) return `::${after}`;
|
|
97
|
+
if (!after) return `${before}::`;
|
|
98
|
+
return `${before}::${after}`;
|
|
99
|
+
}
|
|
100
|
+
function normalizeToken(rawToken) {
|
|
101
|
+
const token = rawToken.trim();
|
|
102
|
+
if (!token || token.length > MAX_TOKEN_LENGTH || hasControlCharacter(token)) return null;
|
|
103
|
+
let address = token;
|
|
104
|
+
if (token.startsWith("[")) {
|
|
105
|
+
const closing = token.indexOf("]");
|
|
106
|
+
if (closing <= 1) return null;
|
|
107
|
+
const suffix = token.slice(closing + 1);
|
|
108
|
+
if (suffix && (!suffix.startsWith(":") || !parsePort(suffix.slice(1)))) return null;
|
|
109
|
+
address = token.slice(1, closing);
|
|
110
|
+
} else if ((token.match(/:/g) ?? []).length === 1 && token.includes(".")) {
|
|
111
|
+
const colon = token.indexOf(":");
|
|
112
|
+
if (!parsePort(token.slice(colon + 1))) return null;
|
|
113
|
+
address = token.slice(0, colon);
|
|
114
|
+
}
|
|
115
|
+
const ipv4 = parseIpv4(address);
|
|
116
|
+
if (ipv4) return ipv4.join(".");
|
|
117
|
+
const ipv6 = parseIpv6(address);
|
|
118
|
+
return ipv6 ? compressIpv6(ipv6) : null;
|
|
119
|
+
}
|
|
120
|
+
function boundedTokens(raw) {
|
|
121
|
+
if (raw == null || !raw || raw.length > MAX_INPUT_LENGTH || hasControlCharacter(raw)) return null;
|
|
122
|
+
const tokens = raw.split(",");
|
|
123
|
+
if (tokens.length > MAX_FORWARDED_HOPS) return null;
|
|
124
|
+
return tokens;
|
|
125
|
+
}
|
|
126
|
+
/** Normalize the first valid address in a bounded header value. */
|
|
127
|
+
function normalizeClientIp(raw) {
|
|
128
|
+
const tokens = boundedTokens(raw);
|
|
129
|
+
if (!tokens) return null;
|
|
130
|
+
for (const token of tokens) {
|
|
131
|
+
const normalized = normalizeToken(token);
|
|
132
|
+
if (normalized) return normalized;
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
function getHeader(headers, name) {
|
|
137
|
+
if ("get" in headers && typeof headers.get === "function") return headers.get(name) ?? void 0;
|
|
138
|
+
const wanted = name.toLowerCase();
|
|
139
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
140
|
+
if (key.toLowerCase() !== wanted || value === void 0) continue;
|
|
141
|
+
return Array.isArray(value) ? value.join(",") : value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function result(ip, source, trusted) {
|
|
145
|
+
return ip ? {
|
|
146
|
+
ip,
|
|
147
|
+
source,
|
|
148
|
+
trusted
|
|
149
|
+
} : null;
|
|
150
|
+
}
|
|
151
|
+
function resolveAddress(raw, source) {
|
|
152
|
+
return result(normalizeClientIp(raw), source, true);
|
|
153
|
+
}
|
|
154
|
+
function resolveExplicit(input) {
|
|
155
|
+
if (input.explicitAddressTrusted !== true) return null;
|
|
156
|
+
return result(normalizeClientIp(input.explicitAddress), "explicit", true);
|
|
157
|
+
}
|
|
158
|
+
function resolveVercel(input) {
|
|
159
|
+
const platform = result(normalizeClientIp(getHeader(input.headers, "x-vercel-forwarded-for")), "x-vercel-forwarded-for", true);
|
|
160
|
+
if (platform) return platform;
|
|
161
|
+
const overwrittenXff = result(normalizeClientIp(getHeader(input.headers, "x-forwarded-for")), "x-forwarded-for", true);
|
|
162
|
+
if (overwrittenXff) return overwrittenXff;
|
|
163
|
+
const realIp = result(normalizeClientIp(getHeader(input.headers, "x-real-ip")), "x-real-ip", false);
|
|
164
|
+
if (realIp) return realIp;
|
|
165
|
+
return resolveAddress(input.frameworkAddress, "framework") ?? resolveAddress(input.directAddress, "socket") ?? {
|
|
166
|
+
ip: null,
|
|
167
|
+
source: "none",
|
|
168
|
+
trusted: false
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function resolveCloudflare(input) {
|
|
172
|
+
const cloudflare = result(normalizeClientIp(getHeader(input.headers, "cf-connecting-ip")), "cf-connecting-ip", true);
|
|
173
|
+
if (cloudflare) return cloudflare;
|
|
174
|
+
return resolveAddress(input.directAddress, "socket") ?? resolveAddress(input.frameworkAddress, "framework") ?? result(normalizeClientIp(getHeader(input.headers, "x-forwarded-for")), "x-forwarded-for", false) ?? result(normalizeClientIp(getHeader(input.headers, "x-real-ip")), "x-real-ip", false) ?? {
|
|
175
|
+
ip: null,
|
|
176
|
+
source: "none",
|
|
177
|
+
trusted: false
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function resolveTrustedProxy(input, trustedHops) {
|
|
181
|
+
const tokens = boundedTokens(getHeader(input.headers, "x-forwarded-for"));
|
|
182
|
+
if (tokens && Number.isInteger(trustedHops) && trustedHops > 0 && tokens.length > trustedHops) {
|
|
183
|
+
const parsed = tokens.map(normalizeToken);
|
|
184
|
+
const selected = parsed[tokens.length - trustedHops - 1];
|
|
185
|
+
if (selected && parsed.every((token) => token !== null)) return {
|
|
186
|
+
ip: selected,
|
|
187
|
+
source: "x-forwarded-for",
|
|
188
|
+
trusted: true
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return resolveAddress(input.frameworkAddress, "framework") ?? resolveAddress(input.directAddress, "socket") ?? result(normalizeClientIp(getHeader(input.headers, "x-real-ip")), "x-real-ip", false) ?? {
|
|
192
|
+
ip: null,
|
|
193
|
+
source: "none",
|
|
194
|
+
trusted: false
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** Resolve a client IP using an explicit deployment trust profile. */
|
|
198
|
+
function resolveClientIp(input) {
|
|
199
|
+
const explicit = resolveExplicit(input);
|
|
200
|
+
if (explicit) return explicit;
|
|
201
|
+
switch (input.policy.platform) {
|
|
202
|
+
case "vercel": return resolveVercel(input);
|
|
203
|
+
case "cloudflare": return resolveCloudflare(input);
|
|
204
|
+
case "trusted-proxy": return resolveTrustedProxy(input, input.policy.trustedHops);
|
|
205
|
+
case "direct": return resolveAddress(input.frameworkAddress, "framework") ?? resolveAddress(input.directAddress, "socket") ?? {
|
|
206
|
+
ip: null,
|
|
207
|
+
source: "none",
|
|
208
|
+
trusted: false
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
//#endregion
|
|
214
|
+
Object.defineProperty(exports, 'compressIpv6', {
|
|
215
|
+
enumerable: true,
|
|
216
|
+
get: function () {
|
|
217
|
+
return compressIpv6;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
Object.defineProperty(exports, 'normalizeClientIp', {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function () {
|
|
223
|
+
return normalizeClientIp;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
Object.defineProperty(exports, 'parseIpv6', {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
get: function () {
|
|
229
|
+
return parseIpv6;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
Object.defineProperty(exports, 'resolveClientIp', {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
get: function () {
|
|
235
|
+
return resolveClientIp;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
//#region src/utils/client-ip.ts
|
|
2
|
+
const MAX_INPUT_LENGTH = 4096;
|
|
3
|
+
const MAX_TOKEN_LENGTH = 128;
|
|
4
|
+
const MAX_FORWARDED_HOPS = 32;
|
|
5
|
+
function hasControlCharacter(value) {
|
|
6
|
+
for (let i = 0; i < value.length; i++) {
|
|
7
|
+
const code = value.charCodeAt(i);
|
|
8
|
+
if (code <= 31 || code === 127) return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
function parsePort(value) {
|
|
13
|
+
return /^(?:0|[1-9]\d{0,4})$/.test(value) && Number(value) <= 65535;
|
|
14
|
+
}
|
|
15
|
+
function parseIpv4(value) {
|
|
16
|
+
const parts = value.split(".");
|
|
17
|
+
if (parts.length !== 4) return null;
|
|
18
|
+
const octets = [];
|
|
19
|
+
for (const part of parts) {
|
|
20
|
+
if (!/^\d{1,3}$/.test(part)) return null;
|
|
21
|
+
const octet = Number(part);
|
|
22
|
+
if (octet > 255) return null;
|
|
23
|
+
octets.push(octet);
|
|
24
|
+
}
|
|
25
|
+
return octets;
|
|
26
|
+
}
|
|
27
|
+
function parseHexGroup(value) {
|
|
28
|
+
if (!/^[0-9a-fA-F]{1,4}$/.test(value)) return null;
|
|
29
|
+
return Number.parseInt(value, 16);
|
|
30
|
+
}
|
|
31
|
+
/** Parses a bare IPv6 address into its 8 groups (`::` expanded). Exported for reuse by anything that needs to mask/truncate an address (see `anonymize-ip.ts`), not just resolve one. */
|
|
32
|
+
function parseIpv6(value) {
|
|
33
|
+
if (!value || value.includes("%") || hasControlCharacter(value)) return null;
|
|
34
|
+
let address = value;
|
|
35
|
+
if (address.includes(".")) {
|
|
36
|
+
const lastColon = address.lastIndexOf(":");
|
|
37
|
+
if (lastColon < 0) return null;
|
|
38
|
+
const ipv4 = parseIpv4(address.slice(lastColon + 1));
|
|
39
|
+
if (!ipv4) return null;
|
|
40
|
+
const first = ipv4[0] << 8 | ipv4[1];
|
|
41
|
+
const second = ipv4[2] << 8 | ipv4[3];
|
|
42
|
+
address = `${address.slice(0, lastColon + 1)}${first.toString(16)}:${second.toString(16)}`;
|
|
43
|
+
}
|
|
44
|
+
const doubleColon = address.indexOf("::");
|
|
45
|
+
if (doubleColon !== address.lastIndexOf("::")) return null;
|
|
46
|
+
const parseGroups = (part) => {
|
|
47
|
+
if (!part) return [];
|
|
48
|
+
const groups = part.split(":");
|
|
49
|
+
const parsed = [];
|
|
50
|
+
for (const group of groups) {
|
|
51
|
+
const number = parseHexGroup(group);
|
|
52
|
+
if (number === null) return null;
|
|
53
|
+
parsed.push(number);
|
|
54
|
+
}
|
|
55
|
+
return parsed;
|
|
56
|
+
};
|
|
57
|
+
if (doubleColon >= 0) {
|
|
58
|
+
const head = parseGroups(address.slice(0, doubleColon));
|
|
59
|
+
const tail = parseGroups(address.slice(doubleColon + 2));
|
|
60
|
+
if (!head || !tail) return null;
|
|
61
|
+
const missing = 8 - head.length - tail.length;
|
|
62
|
+
if (missing < 1) return null;
|
|
63
|
+
return [
|
|
64
|
+
...head,
|
|
65
|
+
...Array(missing).fill(0),
|
|
66
|
+
...tail
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const groups = parseGroups(address);
|
|
70
|
+
return groups?.length === 8 ? groups : null;
|
|
71
|
+
}
|
|
72
|
+
/** RFC 5952 canonical `::` compression for 8 IPv6 groups. Exported alongside `parseIpv6`. */
|
|
73
|
+
function compressIpv6(groups) {
|
|
74
|
+
const rendered = groups.map((group) => group.toString(16));
|
|
75
|
+
let bestStart = -1;
|
|
76
|
+
let bestLength = 1;
|
|
77
|
+
let runStart = -1;
|
|
78
|
+
for (let index = 0; index <= groups.length; index += 1) {
|
|
79
|
+
if (index < groups.length && groups[index] === 0) {
|
|
80
|
+
if (runStart < 0) runStart = index;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (runStart >= 0) {
|
|
84
|
+
const runLength = index - runStart;
|
|
85
|
+
if (runLength > bestLength) {
|
|
86
|
+
bestStart = runStart;
|
|
87
|
+
bestLength = runLength;
|
|
88
|
+
}
|
|
89
|
+
runStart = -1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (bestStart < 0) return rendered.join(":");
|
|
93
|
+
const before = rendered.slice(0, bestStart).join(":");
|
|
94
|
+
const after = rendered.slice(bestStart + bestLength).join(":");
|
|
95
|
+
if (!before && !after) return "::";
|
|
96
|
+
if (!before) return `::${after}`;
|
|
97
|
+
if (!after) return `${before}::`;
|
|
98
|
+
return `${before}::${after}`;
|
|
99
|
+
}
|
|
100
|
+
function normalizeToken(rawToken) {
|
|
101
|
+
const token = rawToken.trim();
|
|
102
|
+
if (!token || token.length > MAX_TOKEN_LENGTH || hasControlCharacter(token)) return null;
|
|
103
|
+
let address = token;
|
|
104
|
+
if (token.startsWith("[")) {
|
|
105
|
+
const closing = token.indexOf("]");
|
|
106
|
+
if (closing <= 1) return null;
|
|
107
|
+
const suffix = token.slice(closing + 1);
|
|
108
|
+
if (suffix && (!suffix.startsWith(":") || !parsePort(suffix.slice(1)))) return null;
|
|
109
|
+
address = token.slice(1, closing);
|
|
110
|
+
} else if ((token.match(/:/g) ?? []).length === 1 && token.includes(".")) {
|
|
111
|
+
const colon = token.indexOf(":");
|
|
112
|
+
if (!parsePort(token.slice(colon + 1))) return null;
|
|
113
|
+
address = token.slice(0, colon);
|
|
114
|
+
}
|
|
115
|
+
const ipv4 = parseIpv4(address);
|
|
116
|
+
if (ipv4) return ipv4.join(".");
|
|
117
|
+
const ipv6 = parseIpv6(address);
|
|
118
|
+
return ipv6 ? compressIpv6(ipv6) : null;
|
|
119
|
+
}
|
|
120
|
+
function boundedTokens(raw) {
|
|
121
|
+
if (raw == null || !raw || raw.length > MAX_INPUT_LENGTH || hasControlCharacter(raw)) return null;
|
|
122
|
+
const tokens = raw.split(",");
|
|
123
|
+
if (tokens.length > MAX_FORWARDED_HOPS) return null;
|
|
124
|
+
return tokens;
|
|
125
|
+
}
|
|
126
|
+
/** Normalize the first valid address in a bounded header value. */
|
|
127
|
+
function normalizeClientIp(raw) {
|
|
128
|
+
const tokens = boundedTokens(raw);
|
|
129
|
+
if (!tokens) return null;
|
|
130
|
+
for (const token of tokens) {
|
|
131
|
+
const normalized = normalizeToken(token);
|
|
132
|
+
if (normalized) return normalized;
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
function getHeader(headers, name) {
|
|
137
|
+
if ("get" in headers && typeof headers.get === "function") return headers.get(name) ?? void 0;
|
|
138
|
+
const wanted = name.toLowerCase();
|
|
139
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
140
|
+
if (key.toLowerCase() !== wanted || value === void 0) continue;
|
|
141
|
+
return Array.isArray(value) ? value.join(",") : value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function result(ip, source, trusted) {
|
|
145
|
+
return ip ? {
|
|
146
|
+
ip,
|
|
147
|
+
source,
|
|
148
|
+
trusted
|
|
149
|
+
} : null;
|
|
150
|
+
}
|
|
151
|
+
function resolveAddress(raw, source) {
|
|
152
|
+
return result(normalizeClientIp(raw), source, true);
|
|
153
|
+
}
|
|
154
|
+
function resolveExplicit(input) {
|
|
155
|
+
if (input.explicitAddressTrusted !== true) return null;
|
|
156
|
+
return result(normalizeClientIp(input.explicitAddress), "explicit", true);
|
|
157
|
+
}
|
|
158
|
+
function resolveVercel(input) {
|
|
159
|
+
const platform = result(normalizeClientIp(getHeader(input.headers, "x-vercel-forwarded-for")), "x-vercel-forwarded-for", true);
|
|
160
|
+
if (platform) return platform;
|
|
161
|
+
const overwrittenXff = result(normalizeClientIp(getHeader(input.headers, "x-forwarded-for")), "x-forwarded-for", true);
|
|
162
|
+
if (overwrittenXff) return overwrittenXff;
|
|
163
|
+
const realIp = result(normalizeClientIp(getHeader(input.headers, "x-real-ip")), "x-real-ip", false);
|
|
164
|
+
if (realIp) return realIp;
|
|
165
|
+
return resolveAddress(input.frameworkAddress, "framework") ?? resolveAddress(input.directAddress, "socket") ?? {
|
|
166
|
+
ip: null,
|
|
167
|
+
source: "none",
|
|
168
|
+
trusted: false
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function resolveCloudflare(input) {
|
|
172
|
+
const cloudflare = result(normalizeClientIp(getHeader(input.headers, "cf-connecting-ip")), "cf-connecting-ip", true);
|
|
173
|
+
if (cloudflare) return cloudflare;
|
|
174
|
+
return resolveAddress(input.directAddress, "socket") ?? resolveAddress(input.frameworkAddress, "framework") ?? result(normalizeClientIp(getHeader(input.headers, "x-forwarded-for")), "x-forwarded-for", false) ?? result(normalizeClientIp(getHeader(input.headers, "x-real-ip")), "x-real-ip", false) ?? {
|
|
175
|
+
ip: null,
|
|
176
|
+
source: "none",
|
|
177
|
+
trusted: false
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function resolveTrustedProxy(input, trustedHops) {
|
|
181
|
+
const tokens = boundedTokens(getHeader(input.headers, "x-forwarded-for"));
|
|
182
|
+
if (tokens && Number.isInteger(trustedHops) && trustedHops > 0 && tokens.length > trustedHops) {
|
|
183
|
+
const parsed = tokens.map(normalizeToken);
|
|
184
|
+
const selected = parsed[tokens.length - trustedHops - 1];
|
|
185
|
+
if (selected && parsed.every((token) => token !== null)) return {
|
|
186
|
+
ip: selected,
|
|
187
|
+
source: "x-forwarded-for",
|
|
188
|
+
trusted: true
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return resolveAddress(input.frameworkAddress, "framework") ?? resolveAddress(input.directAddress, "socket") ?? result(normalizeClientIp(getHeader(input.headers, "x-real-ip")), "x-real-ip", false) ?? {
|
|
192
|
+
ip: null,
|
|
193
|
+
source: "none",
|
|
194
|
+
trusted: false
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** Resolve a client IP using an explicit deployment trust profile. */
|
|
198
|
+
function resolveClientIp(input) {
|
|
199
|
+
const explicit = resolveExplicit(input);
|
|
200
|
+
if (explicit) return explicit;
|
|
201
|
+
switch (input.policy.platform) {
|
|
202
|
+
case "vercel": return resolveVercel(input);
|
|
203
|
+
case "cloudflare": return resolveCloudflare(input);
|
|
204
|
+
case "trusted-proxy": return resolveTrustedProxy(input, input.policy.trustedHops);
|
|
205
|
+
case "direct": return resolveAddress(input.frameworkAddress, "framework") ?? resolveAddress(input.directAddress, "socket") ?? {
|
|
206
|
+
ip: null,
|
|
207
|
+
source: "none",
|
|
208
|
+
trusted: false
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
//#endregion
|
|
214
|
+
export { resolveClientIp as i, normalizeClientIp as n, parseIpv6 as r, compressIpv6 as t };
|
|
215
|
+
//# sourceMappingURL=client-ip-HOfe6ucV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ip-HOfe6ucV.mjs","names":[],"sources":["../src/utils/client-ip.ts"],"sourcesContent":["/**\n * Runtime-agnostic client-IP normalization and trust resolution.\n *\n * Header presence is not proof of provenance. Callers must select the\n * deployment profile that describes which infrastructure has already\n * authenticated a value before using the result for security decisions.\n */\n\nexport type ClientIpSource =\n | 'explicit'\n | 'cf-connecting-ip'\n | 'x-vercel-forwarded-for'\n | 'x-forwarded-for'\n | 'x-real-ip'\n | 'framework'\n | 'socket'\n | 'none';\n\nexport interface ClientIpResolution {\n ip: string | null;\n source: ClientIpSource;\n trusted: boolean;\n}\n\nexport type ClientIpTrustPolicy =\n | { platform: 'vercel' }\n | { platform: 'cloudflare' }\n | { platform: 'trusted-proxy'; trustedHops: number }\n | { platform: 'direct' };\n\nexport type ClientIpHeaderValue = string | readonly string[] | undefined;\nexport type ClientIpHeaders = Headers | Record<string, ClientIpHeaderValue>;\n\nexport interface ResolveClientIpInput {\n headers: ClientIpHeaders;\n directAddress?: string | null;\n frameworkAddress?: string | null;\n explicitAddress?: string | null;\n /** True only after the caller has authenticated the explicit value. */\n explicitAddressTrusted?: boolean;\n policy: ClientIpTrustPolicy;\n}\n\nconst MAX_INPUT_LENGTH = 4096;\nconst MAX_TOKEN_LENGTH = 128;\nconst MAX_FORWARDED_HOPS = 32;\n\nfunction hasControlCharacter(value: string): boolean {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code <= 0x1f || code === 0x7f) return true;\n }\n return false;\n}\n\nfunction parsePort(value: string): boolean {\n return /^(?:0|[1-9]\\d{0,4})$/.test(value) && Number(value) <= 65535;\n}\n\nfunction parseIpv4(value: string): number[] | null {\n const parts = value.split('.');\n if (parts.length !== 4) return null;\n\n const octets: number[] = [];\n for (const part of parts) {\n if (!/^\\d{1,3}$/.test(part)) return null;\n const octet = Number(part);\n if (octet > 255) return null;\n octets.push(octet);\n }\n return octets;\n}\n\nfunction parseHexGroup(value: string): number | null {\n if (!/^[0-9a-fA-F]{1,4}$/.test(value)) return null;\n return Number.parseInt(value, 16);\n}\n\n/** Parses a bare IPv6 address into its 8 groups (`::` expanded). Exported for reuse by anything that needs to mask/truncate an address (see `anonymize-ip.ts`), not just resolve one. */\nexport function parseIpv6(value: string): number[] | null {\n if (!value || value.includes('%') || hasControlCharacter(value)) return null;\n\n let address = value;\n if (address.includes('.')) {\n const lastColon = address.lastIndexOf(':');\n if (lastColon < 0) return null;\n const ipv4 = parseIpv4(address.slice(lastColon + 1));\n if (!ipv4) return null;\n const first = (ipv4[0]! << 8) | ipv4[1]!;\n const second = (ipv4[2]! << 8) | ipv4[3]!;\n address = `${address.slice(0, lastColon + 1)}${first.toString(16)}:${second.toString(16)}`;\n }\n\n const doubleColon = address.indexOf('::');\n if (doubleColon !== address.lastIndexOf('::')) return null;\n\n const parseGroups = (part: string): number[] | null => {\n if (!part) return [];\n const groups = part.split(':');\n const parsed: number[] = [];\n for (const group of groups) {\n const number = parseHexGroup(group);\n if (number === null) return null;\n parsed.push(number);\n }\n return parsed;\n };\n\n if (doubleColon >= 0) {\n const head = parseGroups(address.slice(0, doubleColon));\n const tail = parseGroups(address.slice(doubleColon + 2));\n if (!head || !tail) return null;\n const missing = 8 - head.length - tail.length;\n if (missing < 1) return null;\n return [...head, ...Array<number>(missing).fill(0), ...tail];\n }\n\n const groups = parseGroups(address);\n return groups?.length === 8 ? groups : null;\n}\n\n/** RFC 5952 canonical `::` compression for 8 IPv6 groups. Exported alongside `parseIpv6`. */\nexport function compressIpv6(groups: number[]): string {\n const rendered = groups.map((group) => group.toString(16));\n let bestStart = -1;\n let bestLength = 1;\n let runStart = -1;\n\n for (let index = 0; index <= groups.length; index += 1) {\n if (index < groups.length && groups[index] === 0) {\n if (runStart < 0) runStart = index;\n continue;\n }\n if (runStart >= 0) {\n const runLength = index - runStart;\n if (runLength > bestLength) {\n bestStart = runStart;\n bestLength = runLength;\n }\n runStart = -1;\n }\n }\n\n if (bestStart < 0) return rendered.join(':');\n const before = rendered.slice(0, bestStart).join(':');\n const after = rendered.slice(bestStart + bestLength).join(':');\n if (!before && !after) return '::';\n if (!before) return `::${after}`;\n if (!after) return `${before}::`;\n return `${before}::${after}`;\n}\n\nfunction normalizeToken(rawToken: string): string | null {\n const token = rawToken.trim();\n if (!token || token.length > MAX_TOKEN_LENGTH || hasControlCharacter(token)) return null;\n\n let address = token;\n if (token.startsWith('[')) {\n const closing = token.indexOf(']');\n if (closing <= 1) return null;\n const suffix = token.slice(closing + 1);\n if (suffix && (!suffix.startsWith(':') || !parsePort(suffix.slice(1)))) return null;\n address = token.slice(1, closing);\n } else if ((token.match(/:/g) ?? []).length === 1 && token.includes('.')) {\n const colon = token.indexOf(':');\n if (!parsePort(token.slice(colon + 1))) return null;\n address = token.slice(0, colon);\n }\n\n const ipv4 = parseIpv4(address);\n if (ipv4) return ipv4.join('.');\n\n const ipv6 = parseIpv6(address);\n return ipv6 ? compressIpv6(ipv6) : null;\n}\n\nfunction boundedTokens(raw: string | null | undefined): string[] | null {\n if (raw == null || !raw || raw.length > MAX_INPUT_LENGTH || hasControlCharacter(raw)) return null;\n const tokens = raw.split(',');\n if (tokens.length > MAX_FORWARDED_HOPS) return null;\n return tokens;\n}\n\n/** Normalize the first valid address in a bounded header value. */\nexport function normalizeClientIp(raw: string | null | undefined): string | null {\n const tokens = boundedTokens(raw);\n if (!tokens) return null;\n for (const token of tokens) {\n const normalized = normalizeToken(token);\n if (normalized) return normalized;\n }\n return null;\n}\n\nfunction getHeader(headers: ClientIpHeaders, name: string): string | undefined {\n if ('get' in headers && typeof headers.get === 'function') {\n return headers.get(name) ?? undefined;\n }\n\n const wanted = name.toLowerCase();\n for (const [key, value] of Object.entries(headers)) {\n if (key.toLowerCase() !== wanted || value === undefined) continue;\n return Array.isArray(value) ? value.join(',') : value;\n }\n return undefined;\n}\n\nfunction result(\n ip: string | null,\n source: Exclude<ClientIpSource, 'none'>,\n trusted: boolean\n): ClientIpResolution | null {\n return ip ? { ip, source, trusted } : null;\n}\n\nfunction resolveAddress(\n raw: string | null | undefined,\n source: 'framework' | 'socket'\n): ClientIpResolution | null {\n return result(normalizeClientIp(raw), source, true);\n}\n\nfunction resolveExplicit(input: ResolveClientIpInput): ClientIpResolution | null {\n if (input.explicitAddressTrusted !== true) return null;\n return result(normalizeClientIp(input.explicitAddress), 'explicit', true);\n}\n\nfunction resolveVercel(input: ResolveClientIpInput): ClientIpResolution {\n const platform = result(\n normalizeClientIp(getHeader(input.headers, 'x-vercel-forwarded-for')),\n 'x-vercel-forwarded-for',\n true\n );\n if (platform) return platform;\n\n const overwrittenXff = result(\n normalizeClientIp(getHeader(input.headers, 'x-forwarded-for')),\n 'x-forwarded-for',\n true\n );\n if (overwrittenXff) return overwrittenXff;\n\n const realIp = result(\n normalizeClientIp(getHeader(input.headers, 'x-real-ip')),\n 'x-real-ip',\n false\n );\n if (realIp) return realIp;\n\n return (\n resolveAddress(input.frameworkAddress, 'framework') ??\n resolveAddress(input.directAddress, 'socket') ?? { ip: null, source: 'none', trusted: false }\n );\n}\n\nfunction resolveCloudflare(input: ResolveClientIpInput): ClientIpResolution {\n const cloudflare = result(\n normalizeClientIp(getHeader(input.headers, 'cf-connecting-ip')),\n 'cf-connecting-ip',\n true\n );\n if (cloudflare) return cloudflare;\n\n return (\n resolveAddress(input.directAddress, 'socket') ??\n resolveAddress(input.frameworkAddress, 'framework') ??\n result(\n normalizeClientIp(getHeader(input.headers, 'x-forwarded-for')),\n 'x-forwarded-for',\n false\n ) ??\n result(normalizeClientIp(getHeader(input.headers, 'x-real-ip')), 'x-real-ip', false) ?? {\n ip: null,\n source: 'none',\n trusted: false,\n }\n );\n}\n\nfunction resolveTrustedProxy(input: ResolveClientIpInput, trustedHops: number): ClientIpResolution {\n const raw = getHeader(input.headers, 'x-forwarded-for');\n const tokens = boundedTokens(raw);\n if (tokens && Number.isInteger(trustedHops) && trustedHops > 0 && tokens.length > trustedHops) {\n const parsed = tokens.map(normalizeToken);\n const selectedIndex = tokens.length - trustedHops - 1;\n const selected = parsed[selectedIndex];\n // Parse every token before selecting one. Otherwise an invalid token could\n // silently move the trusted boundary toward an attacker-controlled value.\n if (selected && parsed.every((token) => token !== null)) {\n return { ip: selected, source: 'x-forwarded-for', trusted: true };\n }\n }\n\n return (\n resolveAddress(input.frameworkAddress, 'framework') ??\n resolveAddress(input.directAddress, 'socket') ??\n result(normalizeClientIp(getHeader(input.headers, 'x-real-ip')), 'x-real-ip', false) ?? {\n ip: null,\n source: 'none',\n trusted: false,\n }\n );\n}\n\n/** Resolve a client IP using an explicit deployment trust profile. */\nexport function resolveClientIp(input: ResolveClientIpInput): ClientIpResolution {\n const explicit = resolveExplicit(input);\n if (explicit) return explicit;\n\n switch (input.policy.platform) {\n case 'vercel':\n return resolveVercel(input);\n case 'cloudflare':\n return resolveCloudflare(input);\n case 'trusted-proxy':\n return resolveTrustedProxy(input, input.policy.trustedHops);\n case 'direct':\n return (\n resolveAddress(input.frameworkAddress, 'framework') ??\n resolveAddress(input.directAddress, 'socket') ?? {\n ip: null,\n source: 'none',\n trusted: false,\n }\n );\n }\n}\n"],"mappings":";AA2CA,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AAE3B,SAAS,oBAAoB,OAAwB;CACnD,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,OAAO,MAAM,WAAW,CAAC;EAC/B,IAAI,QAAQ,MAAQ,SAAS,KAAM,OAAO;CAC5C;CACA,OAAO;AACT;AAEA,SAAS,UAAU,OAAwB;CACzC,OAAO,uBAAuB,KAAK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