z-zero-mcp-server 1.10.3 → 1.11.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 +9 -9
- package/dist/base_backend.d.ts +2 -0
- package/dist/base_backend.js +23 -4
- package/dist/failure_taxonomy.d.ts +13 -6
- package/dist/failure_taxonomy.js +76 -6
- package/dist/index.js +365 -245
- package/dist/lib/api-base.d.ts +4 -1
- package/dist/lib/api-base.js +50 -17
- package/dist/lib/domain-lock.d.ts +16 -0
- package/dist/lib/domain-lock.js +142 -0
- package/dist/lib/extract-total-price.d.ts +23 -17
- package/dist/lib/extract-total-price.js +146 -139
- package/dist/lib/key-store.d.ts +25 -2
- package/dist/lib/key-store.js +175 -25
- package/dist/lib/url-guard.d.ts +10 -0
- package/dist/lib/url-guard.js +83 -1
- package/dist/playwright_bridge.d.ts +9 -1
- package/dist/playwright_bridge.js +379 -138
- package/dist/types.d.ts +3 -1
- package/dist/ucp_bridge.d.ts +1 -10
- package/dist/ucp_bridge.js +16 -66
- package/package.json +5 -3
- package/dist/lib/web3-detector.d.ts +0 -19
- package/dist/lib/web3-detector.js +0 -157
package/dist/lib/key-store.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Persist the key
|
|
3
|
-
* Returns true on success. Failure is
|
|
2
|
+
* Persist the key with owner-only permissions, noting which config key (if any)
|
|
3
|
+
* was in place when it was written. Returns true on success. Failure is
|
|
4
|
+
* non-fatal (key still lives in memory).
|
|
4
5
|
*/
|
|
5
6
|
export declare function persistPassportKey(key: string): boolean;
|
|
7
|
+
type KeySource = "file" | "env" | "set_api_key" | "none";
|
|
6
8
|
/** Read the current active Passport Key. */
|
|
7
9
|
export declare function getPassportKey(): string;
|
|
10
|
+
/** Where the active key came from, and whether it still has to be rotated. */
|
|
11
|
+
export declare function keyStatus(): {
|
|
12
|
+
source: KeySource;
|
|
13
|
+
rotation_pending: boolean;
|
|
14
|
+
};
|
|
8
15
|
/**
|
|
9
16
|
* Replace the active Passport Key in memory (no restart needed).
|
|
10
17
|
* @param newKey - must start with "zk_live_" or "zk_test_"
|
|
@@ -16,3 +23,19 @@ export declare function setPassportKey(newKey: string): {
|
|
|
16
23
|
};
|
|
17
24
|
/** Check if a key is currently configured. */
|
|
18
25
|
export declare function hasPassportKey(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Make sure a key that came in through the config has been traded for a fresh
|
|
28
|
+
* one. Called at server start and before every authenticated request; does
|
|
29
|
+
* nothing once done. A network failure leaves it pending and the next request
|
|
30
|
+
* tries again (the config key keeps working meanwhile — it is only dead once
|
|
31
|
+
* the server has swapped it).
|
|
32
|
+
*/
|
|
33
|
+
export declare function ensureKeyReady(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* The stored key was just rejected (401). If the config holds a different key
|
|
36
|
+
* that has not been tried, switch to it (and rotate it). Returns true when the
|
|
37
|
+
* caller should retry once. Handles credentials files written before 1.11,
|
|
38
|
+
* which do not record which config key they replaced (audit T14 F3).
|
|
39
|
+
*/
|
|
40
|
+
export declare function recoverFromRejectedKey(): Promise<boolean>;
|
|
41
|
+
export {};
|
package/dist/lib/key-store.js
CHANGED
|
@@ -1,62 +1,118 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// key-store.ts
|
|
3
|
-
// Shared, mutable in-memory store for the Passport Key
|
|
3
|
+
// Shared, mutable in-memory store for the Passport Key.
|
|
4
4
|
// All API backends import getPassportKey() from here
|
|
5
5
|
// so a single set_api_key MCP tool updates the key for ALL backends at once.
|
|
6
6
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
7
|
+
// Rotate-on-connect, for EVERY way a key arrives (audit T14 F1, M.4):
|
|
8
|
+
// the key a person copies from the dashboard is a one-time ticket. Pasted into
|
|
9
|
+
// a chat (set_api_key) or written into the MCP config as Z_ZERO_API_KEY by the
|
|
10
|
+
// agent, it has been through an LLM conversation. So the first time this server
|
|
11
|
+
// uses it, it trades it for a fresh key (POST /api/keys/rotate) and keeps the
|
|
12
|
+
// fresh one in a local file, chmod 600. The copy in the chat or the config is
|
|
13
|
+
// dead from then on. Before 1.11 only set_api_key did this; a key that came in
|
|
14
|
+
// through the config file — the path most install tabs use — never rotated.
|
|
15
|
+
//
|
|
16
|
+
// The credentials file remembers WHICH config key it replaced (a SHA-256 of it,
|
|
17
|
+
// never the key). A different Z_ZERO_API_KEY in the config later means the user
|
|
18
|
+
// put a new key there on purpose: that one wins and is rotated in turn. Before,
|
|
19
|
+
// an old file silently beat any new key in the config (audit T14 F3).
|
|
20
|
+
//
|
|
21
|
+
// One file per API host (lib/api-base.ts): the z-zero.xyz key is never read
|
|
22
|
+
// when requests go to a custom server (audit T14 F2, M.5).
|
|
12
23
|
//
|
|
13
24
|
// Thread-safety: Node.js is single-threaded. Module-level `let` is safe.
|
|
14
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
26
|
exports.persistPassportKey = persistPassportKey;
|
|
16
27
|
exports.getPassportKey = getPassportKey;
|
|
28
|
+
exports.keyStatus = keyStatus;
|
|
17
29
|
exports.setPassportKey = setPassportKey;
|
|
18
30
|
exports.hasPassportKey = hasPassportKey;
|
|
31
|
+
exports.ensureKeyReady = ensureKeyReady;
|
|
32
|
+
exports.recoverFromRejectedKey = recoverFromRejectedKey;
|
|
19
33
|
const fs_1 = require("fs");
|
|
20
34
|
const path_1 = require("path");
|
|
21
35
|
const os_1 = require("os");
|
|
36
|
+
const crypto_1 = require("crypto");
|
|
37
|
+
const api_base_js_1 = require("./api-base.js");
|
|
38
|
+
const version_js_1 = require("../version.js");
|
|
22
39
|
const CRED_DIR = (0, path_1.join)((0, os_1.homedir)(), ".z-zero");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
/** ~/.z-zero/credentials for z-zero.xyz; credentials-<host_port> for anything else. */
|
|
41
|
+
function credFile() {
|
|
42
|
+
const base = (0, api_base_js_1.resolveApiBaseUrl)();
|
|
43
|
+
if (base === api_base_js_1.CANONICAL_API)
|
|
44
|
+
return (0, path_1.join)(CRED_DIR, "credentials");
|
|
45
|
+
const u = new URL(base);
|
|
46
|
+
return (0, path_1.join)(CRED_DIR, `credentials-${(u.host).replace(/[^a-zA-Z0-9.-]/g, "_")}`);
|
|
47
|
+
}
|
|
48
|
+
const looksLikeKey = (k) => k.startsWith("zk_live_") || k.startsWith("zk_test_");
|
|
49
|
+
const sha256 = (s) => (0, crypto_1.createHash)("sha256").update(s).digest("hex");
|
|
50
|
+
function readCred() {
|
|
26
51
|
try {
|
|
27
|
-
const
|
|
28
|
-
const parsed = JSON.parse(raw);
|
|
52
|
+
const parsed = JSON.parse((0, fs_1.readFileSync)(credFile(), "utf8"));
|
|
29
53
|
const key = typeof parsed?.passport_key === "string" ? parsed.passport_key.trim() : "";
|
|
30
|
-
if (
|
|
31
|
-
return
|
|
32
|
-
|
|
54
|
+
if (!looksLikeKey(key))
|
|
55
|
+
return null;
|
|
56
|
+
const from = typeof parsed?.from_env_sha256 === "string" ? parsed.from_env_sha256
|
|
57
|
+
: ("from_env_sha256" in (parsed ?? {}) ? null : undefined);
|
|
58
|
+
return { passport_key: key, from_env_sha256: from };
|
|
33
59
|
}
|
|
34
60
|
catch {
|
|
35
|
-
return null; // no file yet, or unreadable
|
|
61
|
+
return null; // no file yet, or unreadable
|
|
36
62
|
}
|
|
37
63
|
}
|
|
64
|
+
function envKey() {
|
|
65
|
+
const k = (process.env.Z_ZERO_API_KEY || "").trim();
|
|
66
|
+
return looksLikeKey(k) ? k : "";
|
|
67
|
+
}
|
|
38
68
|
/**
|
|
39
|
-
* Persist the key
|
|
40
|
-
* Returns true on success. Failure is
|
|
69
|
+
* Persist the key with owner-only permissions, noting which config key (if any)
|
|
70
|
+
* was in place when it was written. Returns true on success. Failure is
|
|
71
|
+
* non-fatal (key still lives in memory).
|
|
41
72
|
*/
|
|
42
73
|
function persistPassportKey(key) {
|
|
43
74
|
try {
|
|
44
75
|
(0, fs_1.mkdirSync)(CRED_DIR, { recursive: true, mode: 0o700 });
|
|
45
|
-
|
|
46
|
-
|
|
76
|
+
const env = envKey();
|
|
77
|
+
const body = { passport_key: key, from_env_sha256: env ? sha256(env) : null };
|
|
78
|
+
(0, fs_1.writeFileSync)(credFile(), JSON.stringify(body) + "\n", { mode: 0o600 });
|
|
79
|
+
(0, fs_1.chmodSync)(credFile(), 0o600); // enforce even if file pre-existed with looser mode
|
|
47
80
|
return true;
|
|
48
81
|
}
|
|
49
82
|
catch (err) {
|
|
50
|
-
console.error(`[KEY-STORE] ⚠️ Could not persist key to ${
|
|
83
|
+
console.error(`[KEY-STORE] ⚠️ Could not persist key to ${credFile()}: ${err?.message || err}`);
|
|
51
84
|
return false;
|
|
52
85
|
}
|
|
53
86
|
}
|
|
54
|
-
|
|
55
|
-
let
|
|
87
|
+
let _passportKey = "";
|
|
88
|
+
let _source = "none";
|
|
89
|
+
/** The active key came from the config and has not been traded for a fresh one yet. */
|
|
90
|
+
let _envRotationPending = false;
|
|
91
|
+
/** A dead file key may fall back to the config key once. */
|
|
92
|
+
let _envFallbackTried = false;
|
|
93
|
+
(function loadInitialKey() {
|
|
94
|
+
const cred = readCred();
|
|
95
|
+
const env = envKey();
|
|
96
|
+
const envIsNew = !!env && env !== cred?.passport_key &&
|
|
97
|
+
(!cred || (cred.from_env_sha256 !== undefined && cred.from_env_sha256 !== sha256(env)));
|
|
98
|
+
if (envIsNew) {
|
|
99
|
+
_passportKey = env;
|
|
100
|
+
_source = "env";
|
|
101
|
+
_envRotationPending = true;
|
|
102
|
+
}
|
|
103
|
+
else if (cred) {
|
|
104
|
+
_passportKey = cred.passport_key;
|
|
105
|
+
_source = "file";
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
56
108
|
/** Read the current active Passport Key. */
|
|
57
109
|
function getPassportKey() {
|
|
58
110
|
return _passportKey;
|
|
59
111
|
}
|
|
112
|
+
/** Where the active key came from, and whether it still has to be rotated. */
|
|
113
|
+
function keyStatus() {
|
|
114
|
+
return { source: _source, rotation_pending: _envRotationPending };
|
|
115
|
+
}
|
|
60
116
|
/**
|
|
61
117
|
* Replace the active Passport Key in memory (no restart needed).
|
|
62
118
|
* @param newKey - must start with "zk_live_" or "zk_test_"
|
|
@@ -67,15 +123,109 @@ function setPassportKey(newKey) {
|
|
|
67
123
|
if (!trimmed) {
|
|
68
124
|
return { ok: false, message: "Key cannot be empty." };
|
|
69
125
|
}
|
|
70
|
-
if (!
|
|
71
|
-
return { ok: false, message: `Invalid key format — must start with "zk_live_" or "zk_test_"
|
|
126
|
+
if (!looksLikeKey(trimmed)) {
|
|
127
|
+
return { ok: false, message: `Invalid key format — must start with "zk_live_" or "zk_test_".` };
|
|
72
128
|
}
|
|
73
129
|
_passportKey = trimmed;
|
|
130
|
+
_source = "set_api_key";
|
|
131
|
+
_envRotationPending = false;
|
|
74
132
|
// ✅ FIX 11: Don't log partial key — even 10 chars helps brute-force
|
|
75
133
|
console.error(`[KEY-STORE] ✅ Passport Key updated successfully.`);
|
|
76
|
-
return { ok: true, message:
|
|
134
|
+
return { ok: true, message: "Passport Key updated successfully." };
|
|
77
135
|
}
|
|
78
136
|
/** Check if a key is currently configured. */
|
|
79
137
|
function hasPassportKey() {
|
|
80
138
|
return _passportKey.length > 0;
|
|
81
139
|
}
|
|
140
|
+
let _rotating = null;
|
|
141
|
+
/**
|
|
142
|
+
* Make sure a key that came in through the config has been traded for a fresh
|
|
143
|
+
* one. Called at server start and before every authenticated request; does
|
|
144
|
+
* nothing once done. A network failure leaves it pending and the next request
|
|
145
|
+
* tries again (the config key keeps working meanwhile — it is only dead once
|
|
146
|
+
* the server has swapped it).
|
|
147
|
+
*/
|
|
148
|
+
async function ensureKeyReady() {
|
|
149
|
+
if (!_envRotationPending)
|
|
150
|
+
return;
|
|
151
|
+
if (!_rotating)
|
|
152
|
+
_rotating = rotateConfigKey().finally(() => { _rotating = null; });
|
|
153
|
+
await _rotating;
|
|
154
|
+
}
|
|
155
|
+
async function rotateConfigKey() {
|
|
156
|
+
const configKey = _passportKey;
|
|
157
|
+
let resp;
|
|
158
|
+
try {
|
|
159
|
+
resp = await fetch(`${(0, api_base_js_1.resolveApiBaseUrl)()}/api/keys/rotate`, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: { "Authorization": `Bearer ${configKey}`, "x-mcp-version": version_js_1.CURRENT_MCP_VERSION },
|
|
162
|
+
redirect: "manual",
|
|
163
|
+
signal: AbortSignal.timeout(8000),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
console.error(`[KEY-STORE] ⚠️ Could not rotate the config key yet (${err?.message || "network"}); will retry on the next call.`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (resp.ok) {
|
|
171
|
+
const data = await resp.json().catch(() => null);
|
|
172
|
+
const fresh = typeof data?.new_key === "string" ? data.new_key : "";
|
|
173
|
+
if (!looksLikeKey(fresh))
|
|
174
|
+
return; // malformed answer: stay pending, retry later
|
|
175
|
+
const persisted = persistPassportKey(fresh);
|
|
176
|
+
_passportKey = fresh;
|
|
177
|
+
_source = "file";
|
|
178
|
+
_envRotationPending = false;
|
|
179
|
+
console.error(`[KEY-STORE] ✅ The key from your MCP config was swapped for a fresh one ` +
|
|
180
|
+
(persisted ? `(stored in ${credFile()}). ` : `(NOT stored — could not write ${credFile()}; after a restart, get a new key from the dashboard). `) +
|
|
181
|
+
`The copy in the config and in any chat is now dead.`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (resp.status === 401 || resp.status === 409) {
|
|
185
|
+
// The config key is already dead: another process on this machine rotated
|
|
186
|
+
// it a moment ago (two MCP clients starting together), or it was revoked.
|
|
187
|
+
// Take what is in the credentials file, if anything.
|
|
188
|
+
_envRotationPending = false;
|
|
189
|
+
let cred = readCred();
|
|
190
|
+
if (!cred || cred.passport_key === configKey) {
|
|
191
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
192
|
+
cred = readCred();
|
|
193
|
+
}
|
|
194
|
+
if (cred && cred.passport_key !== configKey) {
|
|
195
|
+
_passportKey = cred.passport_key;
|
|
196
|
+
_source = "file";
|
|
197
|
+
console.error("[KEY-STORE] The config key was already rotated — using the stored key.");
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
console.error("[KEY-STORE] ⚠️ The key in your MCP config was rejected (revoked, or already used on another machine). Get a fresh key from https://z-zero.xyz/dashboard/agents.");
|
|
201
|
+
}
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (resp.status === 404) {
|
|
205
|
+
// A self-hosted server without the rotate endpoint: keep the config key as before.
|
|
206
|
+
_envRotationPending = false;
|
|
207
|
+
console.error("[KEY-STORE] This server has no key-rotation endpoint; the key from your MCP config stays as it is.");
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
// 429 / 5xx: stay pending, retry on the next call.
|
|
211
|
+
console.error(`[KEY-STORE] ⚠️ Key rotation answered ${resp.status}; will retry on the next call.`);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The stored key was just rejected (401). If the config holds a different key
|
|
215
|
+
* that has not been tried, switch to it (and rotate it). Returns true when the
|
|
216
|
+
* caller should retry once. Handles credentials files written before 1.11,
|
|
217
|
+
* which do not record which config key they replaced (audit T14 F3).
|
|
218
|
+
*/
|
|
219
|
+
async function recoverFromRejectedKey() {
|
|
220
|
+
if (_source !== "file" || _envFallbackTried)
|
|
221
|
+
return false;
|
|
222
|
+
const env = envKey();
|
|
223
|
+
if (!env || env === _passportKey)
|
|
224
|
+
return false;
|
|
225
|
+
_envFallbackTried = true;
|
|
226
|
+
_passportKey = env;
|
|
227
|
+
_source = "env";
|
|
228
|
+
_envRotationPending = true;
|
|
229
|
+
await ensureKeyReady();
|
|
230
|
+
return true;
|
|
231
|
+
}
|
package/dist/lib/url-guard.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/** Expand any IPv6 literal (::, zone id, embedded dotted IPv4) to 8 numeric groups; null if malformed. */
|
|
2
|
+
export declare function expandIpv6(ip: string): number[] | null;
|
|
3
|
+
/**
|
|
4
|
+
* RFC1918 / loopback / link-local / CGNAT / multicast / unspecified for IPv4;
|
|
5
|
+
* for IPv6: ::/96 (unspecified, loopback, deprecated IPv4-compatible), IPv4-mapped
|
|
6
|
+
* ::ffff:0:0/96 in ANY spelling (dotted or hex — "::ffff:7f00:1" IS 127.0.0.1),
|
|
7
|
+
* NAT64 64:ff9b::/96, ULA fc00::/7, link-local fe80::/10, site-local fec0::/10,
|
|
8
|
+
* multicast ff00::/8. Unparseable literals are treated as unsafe.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isPrivateIp(ip: string): boolean;
|
|
1
11
|
/**
|
|
2
12
|
* Throws if `rawUrl` is not a safe public checkout URL.
|
|
3
13
|
* - must parse as a URL
|
package/dist/lib/url-guard.js
CHANGED
|
@@ -6,7 +6,72 @@
|
|
|
6
6
|
// real PAN/CVV, so the destination must be a public HTTPS host, never an
|
|
7
7
|
// internal/metadata address.
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.expandIpv6 = expandIpv6;
|
|
10
|
+
exports.isPrivateIp = isPrivateIp;
|
|
9
11
|
exports.assertSafeCheckoutUrl = assertSafeCheckoutUrl;
|
|
12
|
+
const node_net_1 = require("node:net");
|
|
13
|
+
/** Expand any IPv6 literal (::, zone id, embedded dotted IPv4) to 8 numeric groups; null if malformed. */
|
|
14
|
+
function expandIpv6(ip) {
|
|
15
|
+
let str = ip.toLowerCase().split("%")[0];
|
|
16
|
+
const dotted = str.match(/^(.*:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
|
|
17
|
+
if (dotted) {
|
|
18
|
+
const v4 = dotted[2].split(".").map(Number);
|
|
19
|
+
if (v4.some((n) => n > 255))
|
|
20
|
+
return null;
|
|
21
|
+
str = dotted[1] + ((v4[0] << 8) | v4[1]).toString(16) + ":" + ((v4[2] << 8) | v4[3]).toString(16);
|
|
22
|
+
}
|
|
23
|
+
const halves = str.split("::");
|
|
24
|
+
if (halves.length > 2)
|
|
25
|
+
return null;
|
|
26
|
+
const head = halves[0] ? halves[0].split(":") : [];
|
|
27
|
+
const tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
28
|
+
const fill = halves.length === 2 ? 8 - head.length - tail.length : 0;
|
|
29
|
+
if (fill < 0 || (halves.length === 1 && head.length !== 8))
|
|
30
|
+
return null;
|
|
31
|
+
const groups = [...head, ...new Array(fill).fill("0"), ...tail].map((g) => (/^[0-9a-f]{1,4}$/.test(g) ? parseInt(g, 16) : NaN));
|
|
32
|
+
if (groups.length !== 8 || groups.some((n) => Number.isNaN(n)))
|
|
33
|
+
return null;
|
|
34
|
+
return groups;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* RFC1918 / loopback / link-local / CGNAT / multicast / unspecified for IPv4;
|
|
38
|
+
* for IPv6: ::/96 (unspecified, loopback, deprecated IPv4-compatible), IPv4-mapped
|
|
39
|
+
* ::ffff:0:0/96 in ANY spelling (dotted or hex — "::ffff:7f00:1" IS 127.0.0.1),
|
|
40
|
+
* NAT64 64:ff9b::/96, ULA fc00::/7, link-local fe80::/10, site-local fec0::/10,
|
|
41
|
+
* multicast ff00::/8. Unparseable literals are treated as unsafe.
|
|
42
|
+
*/
|
|
43
|
+
function isPrivateIp(ip) {
|
|
44
|
+
const v = (0, node_net_1.isIP)(ip);
|
|
45
|
+
if (v === 4) {
|
|
46
|
+
const [a, b] = ip.split(".").map(Number);
|
|
47
|
+
return a === 0 || a === 10 || a === 127 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31)
|
|
48
|
+
|| (a === 192 && b === 168) || (a === 100 && b >= 64 && b <= 127) || a >= 224;
|
|
49
|
+
}
|
|
50
|
+
if (v === 6) {
|
|
51
|
+
const g = expandIpv6(ip);
|
|
52
|
+
if (!g)
|
|
53
|
+
return true;
|
|
54
|
+
const v4 = (hi, lo) => `${hi >> 8}.${hi & 255}.${lo >> 8}.${lo & 255}`;
|
|
55
|
+
const zero5 = g[0] === 0 && g[1] === 0 && g[2] === 0 && g[3] === 0 && g[4] === 0;
|
|
56
|
+
if (zero5 && g[5] === 0xffff)
|
|
57
|
+
return isPrivateIp(v4(g[6], g[7])); // IPv4-mapped, any spelling
|
|
58
|
+
if (zero5 && g[5] === 0)
|
|
59
|
+
return true; // ::, ::1, ::a.b.c.d
|
|
60
|
+
if (g[0] === 0x64 && g[1] === 0xff9b && g[2] === 0 && g[3] === 0 && g[4] === 0 && g[5] === 0) {
|
|
61
|
+
return isPrivateIp(v4(g[6], g[7])); // NAT64
|
|
62
|
+
}
|
|
63
|
+
if ((g[0] & 0xfe00) === 0xfc00)
|
|
64
|
+
return true; // ULA fc00::/7
|
|
65
|
+
if ((g[0] & 0xffc0) === 0xfe80)
|
|
66
|
+
return true; // link-local
|
|
67
|
+
if ((g[0] & 0xffc0) === 0xfec0)
|
|
68
|
+
return true; // site-local (deprecated)
|
|
69
|
+
if ((g[0] & 0xff00) === 0xff00)
|
|
70
|
+
return true; // multicast
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true; // not an IP literal at all → caller must not treat as safe
|
|
74
|
+
}
|
|
10
75
|
const PRIVATE_HOST_PATTERNS = [
|
|
11
76
|
/^localhost$/i,
|
|
12
77
|
/^127\./,
|
|
@@ -31,7 +96,7 @@ function assertSafeCheckoutUrl(rawUrl) {
|
|
|
31
96
|
catch {
|
|
32
97
|
throw new Error(`Invalid checkout_url: ${rawUrl}`);
|
|
33
98
|
}
|
|
34
|
-
const hostname = url.hostname;
|
|
99
|
+
const hostname = url.hostname.toLowerCase();
|
|
35
100
|
// Loopback checkout targets are an EXPLICIT opt-in, never a side effect of
|
|
36
101
|
// NODE_ENV. This server runs on the end user's machine, where NODE_ENV is
|
|
37
102
|
// essentially never "production" — so keying the bypass off that flag left it
|
|
@@ -52,7 +117,24 @@ function assertSafeCheckoutUrl(rawUrl) {
|
|
|
52
117
|
if (url.protocol !== "https:") {
|
|
53
118
|
throw new Error("checkout_url must use HTTPS.");
|
|
54
119
|
}
|
|
120
|
+
// A store's checkout is on the default port. Another port on the same host is
|
|
121
|
+
// another program, not the store (audit T11 F6).
|
|
122
|
+
if (url.port !== "") {
|
|
123
|
+
throw new Error(`checkout_url must use the default HTTPS port (got :${url.port}).`);
|
|
124
|
+
}
|
|
125
|
+
// Chromium sends every *.localhost name (and "localhost.") to this machine
|
|
126
|
+
// itself, whatever DNS says (audit T11 F3 / T19).
|
|
127
|
+
const bareName = hostname.replace(/\.$/, "");
|
|
128
|
+
if (bareName === "localhost" || bareName.endsWith(".localhost")) {
|
|
129
|
+
throw new Error(`SSRF blocked host: ${hostname}`);
|
|
130
|
+
}
|
|
55
131
|
if (PRIVATE_HOST_PATTERNS.some((p) => p.test(hostname))) {
|
|
56
132
|
throw new Error(`SSRF blocked host: ${hostname}`);
|
|
57
133
|
}
|
|
134
|
+
// IP literals in any spelling: IPv6 private ranges, IPv4-mapped "::ffff:7f00:1",
|
|
135
|
+
// CGNAT, 0.0.0.0/8 … (same judge the UCP lane uses; audit MCP-04).
|
|
136
|
+
const bare = hostname.replace(/^\[|\]$/g, "");
|
|
137
|
+
if ((0, node_net_1.isIP)(bare) && isPrivateIp(bare)) {
|
|
138
|
+
throw new Error(`SSRF blocked host: ${hostname}`);
|
|
139
|
+
}
|
|
58
140
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type { CardData, PaymentResult, CheckoutHints } from "./types.js";
|
|
2
|
+
type Page = import("playwright").Page;
|
|
2
3
|
/**
|
|
3
4
|
* Detects and fills credit card form fields on a checkout page.
|
|
4
5
|
* Card data exists ONLY in RAM and is wiped after injection.
|
|
5
6
|
* Hard timeout of 60s prevents merchant page from hanging indefinitely.
|
|
7
|
+
*
|
|
8
|
+
* Nothing this function returns may carry the card (audit T12 F3, M.1): a
|
|
9
|
+
* Playwright error quotes the value it was filling (`fill("4242…")`), and a page
|
|
10
|
+
* can echo the number back as its "order number". Every string leaving here goes
|
|
11
|
+
* through finish(), which strips this card's own number and CVV, then every
|
|
12
|
+
* other card-shaped number.
|
|
6
13
|
*/
|
|
7
|
-
export declare function fillCheckoutForm(checkoutUrl: string, cardData: CardData, existingPage?:
|
|
14
|
+
export declare function fillCheckoutForm(checkoutUrl: string, cardData: CardData, existingPage?: Page, hints?: CheckoutHints): Promise<PaymentResult>;
|
|
15
|
+
export {};
|