@kya-os/checkpoint-nextjs 1.2.0 → 1.7.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 +159 -0
- package/EDGE_RUNTIME_WASM_SETUP.md +1 -1
- package/bin/setup-edge-wasm.js +1 -1
- package/dist/api-middleware.d.mts +9 -1
- package/dist/api-middleware.d.ts +9 -1
- package/dist/api-middleware.js +14 -4
- package/dist/api-middleware.mjs +15 -5
- package/dist/composed-policy.d.mts +115 -0
- package/dist/composed-policy.d.ts +115 -0
- package/dist/composed-policy.js +102 -0
- package/dist/composed-policy.mjs +96 -0
- package/dist/config-DAwIA4DB.d.mts +214 -0
- package/dist/config-DyU4l5er.d.ts +214 -0
- package/dist/create-middleware.js +0 -2
- package/dist/create-middleware.mjs +0 -2
- package/dist/edge-runtime-loader.js +3 -1
- package/dist/edge-runtime-loader.mjs +3 -1
- package/dist/edge-wasm-middleware.d.mts +6 -6
- package/dist/edge-wasm-middleware.d.ts +6 -6
- package/dist/index.d.mts +6 -14
- package/dist/index.d.ts +6 -14
- package/dist/index.js +191 -13
- package/dist/index.mjs +192 -14
- package/dist/middleware-edge.d.mts +7 -3
- package/dist/middleware-edge.d.ts +7 -3
- package/dist/middleware-edge.js +174 -4
- package/dist/middleware-edge.mjs +171 -4
- package/dist/middleware-node.d.mts +39 -116
- package/dist/middleware-node.d.ts +39 -116
- package/dist/middleware-node.js +181 -4
- package/dist/middleware-node.mjs +178 -5
- package/dist/middleware.d.mts +10 -1
- package/dist/middleware.d.ts +10 -1
- package/dist/middleware.js +6 -0
- package/dist/middleware.mjs +6 -1
- package/dist/nodejs-wasm-loader.d.mts +3 -4
- package/dist/nodejs-wasm-loader.d.ts +3 -4
- package/dist/nodejs-wasm-loader.js +1 -1
- package/dist/nodejs-wasm-loader.mjs +1 -1
- package/dist/wasm-setup.js +1 -1
- package/dist/wasm-setup.mjs +1 -1
- package/package.json +4 -9
- package/dist/.tsbuildinfo +0 -1
- package/dist/signature-verifier.d.mts +0 -33
- package/dist/signature-verifier.d.ts +0 -33
- package/dist/signature-verifier.js +0 -384
- package/dist/signature-verifier.mjs +0 -360
- package/dist/wasm-middleware.d.mts +0 -98
- package/dist/wasm-middleware.d.ts +0 -98
- package/dist/wasm-middleware.js +0 -125
- package/dist/wasm-middleware.mjs +0 -121
- package/templates/middleware-wasm-100.ts +0 -161
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ed25519 Signature Verification for HTTP Message Signatures
|
|
3
|
-
* Implements proper cryptographic verification for ChatGPT and other agents
|
|
4
|
-
*
|
|
5
|
-
* Based on RFC 9421 (HTTP Message Signatures) and ChatGPT's implementation
|
|
6
|
-
* Reference: https://help.openai.com/en/articles/9785974-chatgpt-user-allowlisting
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Signature verification result
|
|
10
|
-
*/
|
|
11
|
-
interface SignatureVerificationResult {
|
|
12
|
-
isValid: boolean;
|
|
13
|
-
agent?: string;
|
|
14
|
-
keyid?: string;
|
|
15
|
-
confidence: number;
|
|
16
|
-
reason?: string;
|
|
17
|
-
verificationMethod: 'signature' | 'none';
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Verify HTTP Message Signature for AI agents
|
|
21
|
-
*/
|
|
22
|
-
declare function verifyAgentSignature(method: string, path: string, headers: Record<string, string>): Promise<SignatureVerificationResult>;
|
|
23
|
-
/**
|
|
24
|
-
* Quick check if signature headers are present (for performance)
|
|
25
|
-
*/
|
|
26
|
-
declare function hasSignatureHeaders(headers: Record<string, string>): boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Check if this is a ChatGPT signature based on headers
|
|
29
|
-
* Uses secure URL parsing to prevent spoofing attacks
|
|
30
|
-
*/
|
|
31
|
-
declare function isChatGPTSignature(headers: Record<string, string>): boolean;
|
|
32
|
-
|
|
33
|
-
export { type SignatureVerificationResult, hasSignatureHeaders, isChatGPTSignature, verifyAgentSignature };
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var ed25519 = require('@noble/ed25519');
|
|
4
|
-
var sha2_js = require('@noble/hashes/sha2.js');
|
|
5
|
-
|
|
6
|
-
function _interopNamespace(e) {
|
|
7
|
-
if (e && e.__esModule) return e;
|
|
8
|
-
var n = Object.create(null);
|
|
9
|
-
if (e) {
|
|
10
|
-
Object.keys(e).forEach(function (k) {
|
|
11
|
-
if (k !== 'default') {
|
|
12
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return e[k]; }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
n.default = e;
|
|
21
|
-
return Object.freeze(n);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var ed25519__namespace = /*#__PURE__*/_interopNamespace(ed25519);
|
|
25
|
-
|
|
26
|
-
// src/signature-verifier.ts
|
|
27
|
-
ed25519__namespace.etc.sha512Sync = (...m) => sha2_js.sha512(ed25519__namespace.etc.concatBytes(...m));
|
|
28
|
-
var KNOWN_KEYS = {
|
|
29
|
-
chatgpt: [
|
|
30
|
-
{
|
|
31
|
-
kid: "otMqcjr17mGyruktGvJU8oojQTSMHlVm7uO-lrcqbdg",
|
|
32
|
-
// ChatGPT's current Ed25519 public key (base64)
|
|
33
|
-
// Source: https://chatgpt.com/.well-known/http-message-signatures-directory
|
|
34
|
-
publicKey: "7F_3jDlxaquwh291MiACkcS3Opq88NksyHiakzS-Y1g",
|
|
35
|
-
validFrom: 1735689600,
|
|
36
|
-
// Jan 1, 2025 (nbf from OpenAI)
|
|
37
|
-
validUntil: 1769029093
|
|
38
|
-
// Jan 21, 2026 (exp from OpenAI)
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
};
|
|
42
|
-
var keyCache = /* @__PURE__ */ new Map();
|
|
43
|
-
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
44
|
-
var CACHE_MAX_SIZE = 100;
|
|
45
|
-
function getApiBaseUrl() {
|
|
46
|
-
if (typeof window !== "undefined") {
|
|
47
|
-
return "/api/internal";
|
|
48
|
-
}
|
|
49
|
-
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || process.env.NEXT_PUBLIC_API_URL || process.env.API_URL || (process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : null);
|
|
50
|
-
if (baseUrl) {
|
|
51
|
-
return baseUrl.replace(/\/$/, "") + "/api/internal";
|
|
52
|
-
}
|
|
53
|
-
if (process.env.NODE_ENV !== "production") {
|
|
54
|
-
console.warn(
|
|
55
|
-
"[Signature] No base URL configured for server-side fetch. Using localhost fallback."
|
|
56
|
-
);
|
|
57
|
-
return "http://localhost:3000/api/internal";
|
|
58
|
-
}
|
|
59
|
-
console.error(
|
|
60
|
-
"[Signature] CRITICAL: No base URL configured for server-side fetch in production!"
|
|
61
|
-
);
|
|
62
|
-
return "/api/internal";
|
|
63
|
-
}
|
|
64
|
-
function cleanupExpiredCache() {
|
|
65
|
-
const now = Date.now();
|
|
66
|
-
const entriesToDelete = [];
|
|
67
|
-
for (const [agent, cached] of keyCache.entries()) {
|
|
68
|
-
if (now - cached.cachedAt > CACHE_TTL_MS) {
|
|
69
|
-
entriesToDelete.push(agent);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
for (const agent of entriesToDelete) {
|
|
73
|
-
keyCache.delete(agent);
|
|
74
|
-
}
|
|
75
|
-
if (keyCache.size > CACHE_MAX_SIZE) {
|
|
76
|
-
const entries = Array.from(keyCache.entries()).map(([agent, cached]) => ({
|
|
77
|
-
agent,
|
|
78
|
-
cachedAt: cached.cachedAt
|
|
79
|
-
}));
|
|
80
|
-
entries.sort((a, b) => a.cachedAt - b.cachedAt);
|
|
81
|
-
const toRemove = entries.slice(0, keyCache.size - CACHE_MAX_SIZE);
|
|
82
|
-
for (const entry of toRemove) {
|
|
83
|
-
keyCache.delete(entry.agent);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
async function fetchKeysFromApi(agent) {
|
|
88
|
-
if (keyCache.size > CACHE_MAX_SIZE) {
|
|
89
|
-
cleanupExpiredCache();
|
|
90
|
-
}
|
|
91
|
-
const cached = keyCache.get(agent);
|
|
92
|
-
if (cached && Date.now() - cached.cachedAt < CACHE_TTL_MS) {
|
|
93
|
-
return cached.keys;
|
|
94
|
-
}
|
|
95
|
-
if (typeof fetch === "undefined") {
|
|
96
|
-
console.warn("[Signature] fetch() not available in this environment");
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
const apiBaseUrl = getApiBaseUrl();
|
|
101
|
-
const url = `${apiBaseUrl}/signature-keys?agent=${encodeURIComponent(agent)}`;
|
|
102
|
-
const response = await fetch(url, {
|
|
103
|
-
method: "GET",
|
|
104
|
-
headers: {
|
|
105
|
-
"Content-Type": "application/json"
|
|
106
|
-
},
|
|
107
|
-
// 5 second timeout
|
|
108
|
-
signal: AbortSignal.timeout(5e3)
|
|
109
|
-
});
|
|
110
|
-
if (!response.ok) {
|
|
111
|
-
console.warn(`[Signature] Failed to fetch keys from API: ${response.status}`);
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
const data = await response.json();
|
|
115
|
-
if (!data.keys || !Array.isArray(data.keys) || data.keys.length === 0) {
|
|
116
|
-
console.warn(`[Signature] No keys returned from API for agent: ${agent}`);
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
keyCache.set(agent, {
|
|
120
|
-
keys: data.keys,
|
|
121
|
-
cachedAt: Date.now()
|
|
122
|
-
});
|
|
123
|
-
return data.keys;
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.warn("[Signature] Error fetching keys from API, using fallback", {
|
|
126
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
127
|
-
agent
|
|
128
|
-
});
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function isValidAgent(agent) {
|
|
133
|
-
return agent in KNOWN_KEYS;
|
|
134
|
-
}
|
|
135
|
-
async function getKeysForAgent(agent) {
|
|
136
|
-
const apiKeys = await fetchKeysFromApi(agent);
|
|
137
|
-
if (apiKeys && apiKeys.length > 0) {
|
|
138
|
-
return apiKeys;
|
|
139
|
-
}
|
|
140
|
-
if (isValidAgent(agent)) {
|
|
141
|
-
return KNOWN_KEYS[agent];
|
|
142
|
-
}
|
|
143
|
-
return [];
|
|
144
|
-
}
|
|
145
|
-
function parseSignatureInput(signatureInput) {
|
|
146
|
-
try {
|
|
147
|
-
const match = signatureInput.match(/sig1=\((.*?)\);(.+)/);
|
|
148
|
-
if (!match) return null;
|
|
149
|
-
const [, headersList, params] = match;
|
|
150
|
-
const signedHeaders = headersList ? headersList.split(" ").map((h) => h.replace(/"/g, "").trim()).filter((h) => h.length > 0) : [];
|
|
151
|
-
const keyidMatch = params ? params.match(/keyid="([^"]+)"/) : null;
|
|
152
|
-
const createdMatch = params ? params.match(/created=(\d+)/) : null;
|
|
153
|
-
const expiresMatch = params ? params.match(/expires=(\d+)/) : null;
|
|
154
|
-
if (!keyidMatch || !keyidMatch[1]) return null;
|
|
155
|
-
return {
|
|
156
|
-
keyid: keyidMatch[1],
|
|
157
|
-
created: createdMatch && createdMatch[1] ? parseInt(createdMatch[1]) : void 0,
|
|
158
|
-
expires: expiresMatch && expiresMatch[1] ? parseInt(expiresMatch[1]) : void 0,
|
|
159
|
-
signedHeaders
|
|
160
|
-
};
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error("[Signature] Failed to parse Signature-Input:", error);
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
function buildSignatureBase(method, path, headers, signedHeaders) {
|
|
167
|
-
const components = [];
|
|
168
|
-
for (const headerName of signedHeaders) {
|
|
169
|
-
let value;
|
|
170
|
-
switch (headerName) {
|
|
171
|
-
case "@method":
|
|
172
|
-
value = method.toUpperCase();
|
|
173
|
-
break;
|
|
174
|
-
case "@path":
|
|
175
|
-
value = path;
|
|
176
|
-
break;
|
|
177
|
-
case "@authority":
|
|
178
|
-
value = headers["host"] || headers["Host"] || "";
|
|
179
|
-
break;
|
|
180
|
-
default: {
|
|
181
|
-
const key = Object.keys(headers).find((k) => k.toLowerCase() === headerName.toLowerCase());
|
|
182
|
-
value = key ? headers[key] || "" : "";
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
components.push(`"${headerName}": ${value}`);
|
|
187
|
-
}
|
|
188
|
-
return components.join("\n");
|
|
189
|
-
}
|
|
190
|
-
function base64ToBytes(base64) {
|
|
191
|
-
let standardBase64 = base64.replace(/-/g, "+").replace(/_/g, "/");
|
|
192
|
-
const padding = standardBase64.length % 4;
|
|
193
|
-
if (padding) {
|
|
194
|
-
standardBase64 += "=".repeat(4 - padding);
|
|
195
|
-
}
|
|
196
|
-
const binaryString = atob(standardBase64);
|
|
197
|
-
return Uint8Array.from(binaryString, (c) => c.charCodeAt(0));
|
|
198
|
-
}
|
|
199
|
-
async function verifyEd25519Signature(publicKeyBase64, signatureBase64, message) {
|
|
200
|
-
try {
|
|
201
|
-
const publicKeyBytes = base64ToBytes(publicKeyBase64);
|
|
202
|
-
const signatureBytes = base64ToBytes(signatureBase64);
|
|
203
|
-
const messageBytes = new TextEncoder().encode(message);
|
|
204
|
-
if (publicKeyBytes.length !== 32) {
|
|
205
|
-
console.error("[Signature] Invalid public key length:", publicKeyBytes.length);
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
if (signatureBytes.length !== 64) {
|
|
209
|
-
console.error("[Signature] Invalid signature length:", signatureBytes.length);
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
return ed25519__namespace.verify(signatureBytes, messageBytes, publicKeyBytes);
|
|
213
|
-
} catch (nobleError) {
|
|
214
|
-
console.warn("[Signature] @noble/ed25519 failed, trying Web Crypto fallback:", nobleError);
|
|
215
|
-
try {
|
|
216
|
-
const publicKeyBytes = base64ToBytes(publicKeyBase64);
|
|
217
|
-
const signatureBytes = base64ToBytes(signatureBase64);
|
|
218
|
-
const messageBytes = new TextEncoder().encode(message);
|
|
219
|
-
const publicKey = await crypto.subtle.importKey(
|
|
220
|
-
"raw",
|
|
221
|
-
publicKeyBytes.buffer,
|
|
222
|
-
{
|
|
223
|
-
name: "Ed25519",
|
|
224
|
-
namedCurve: "Ed25519"
|
|
225
|
-
},
|
|
226
|
-
false,
|
|
227
|
-
["verify"]
|
|
228
|
-
);
|
|
229
|
-
return await crypto.subtle.verify(
|
|
230
|
-
"Ed25519",
|
|
231
|
-
publicKey,
|
|
232
|
-
signatureBytes.buffer,
|
|
233
|
-
messageBytes
|
|
234
|
-
);
|
|
235
|
-
} catch (cryptoError) {
|
|
236
|
-
console.error("[Signature] Both @noble/ed25519 and Web Crypto failed:", {
|
|
237
|
-
nobleError: nobleError instanceof Error ? nobleError.message : "Unknown",
|
|
238
|
-
cryptoError: cryptoError instanceof Error ? cryptoError.message : "Unknown"
|
|
239
|
-
});
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
async function verifyAgentSignature(method, path, headers) {
|
|
245
|
-
const signature = headers["signature"] || headers["Signature"];
|
|
246
|
-
const signatureInput = headers["signature-input"] || headers["Signature-Input"];
|
|
247
|
-
const signatureAgent = headers["signature-agent"] || headers["Signature-Agent"];
|
|
248
|
-
if (!signature || !signatureInput) {
|
|
249
|
-
return {
|
|
250
|
-
isValid: false,
|
|
251
|
-
confidence: 0,
|
|
252
|
-
reason: "No signature headers present",
|
|
253
|
-
verificationMethod: "none"
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
const parsed = parseSignatureInput(signatureInput);
|
|
257
|
-
if (!parsed) {
|
|
258
|
-
return {
|
|
259
|
-
isValid: false,
|
|
260
|
-
confidence: 0,
|
|
261
|
-
reason: "Invalid Signature-Input header",
|
|
262
|
-
verificationMethod: "none"
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
if (parsed.created) {
|
|
266
|
-
const now2 = Math.floor(Date.now() / 1e3);
|
|
267
|
-
const age = now2 - parsed.created;
|
|
268
|
-
if (age > 300) {
|
|
269
|
-
return {
|
|
270
|
-
isValid: false,
|
|
271
|
-
confidence: 0,
|
|
272
|
-
reason: "Signature expired (older than 5 minutes)",
|
|
273
|
-
verificationMethod: "none"
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
if (age < -30) {
|
|
277
|
-
return {
|
|
278
|
-
isValid: false,
|
|
279
|
-
confidence: 0,
|
|
280
|
-
reason: "Signature timestamp is in the future",
|
|
281
|
-
verificationMethod: "none"
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
let agent;
|
|
286
|
-
let agentKey;
|
|
287
|
-
const isChatGPT = signatureAgent === '"https://chatgpt.com"' || (() => {
|
|
288
|
-
try {
|
|
289
|
-
const url = new URL(signatureAgent?.replace(/^"|"$/g, "") || "");
|
|
290
|
-
return url.hostname === "chatgpt.com" || url.hostname.endsWith(".chatgpt.com");
|
|
291
|
-
} catch {
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
294
|
-
})();
|
|
295
|
-
if (isChatGPT) {
|
|
296
|
-
agent = "ChatGPT";
|
|
297
|
-
agentKey = "chatgpt";
|
|
298
|
-
}
|
|
299
|
-
if (!agent || !agentKey) {
|
|
300
|
-
return {
|
|
301
|
-
isValid: false,
|
|
302
|
-
confidence: 0,
|
|
303
|
-
reason: "Unknown signature agent",
|
|
304
|
-
verificationMethod: "none"
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
const knownKeys = await getKeysForAgent(agentKey);
|
|
308
|
-
if (knownKeys.length === 0) {
|
|
309
|
-
return {
|
|
310
|
-
isValid: false,
|
|
311
|
-
confidence: 0,
|
|
312
|
-
reason: "No keys available for agent",
|
|
313
|
-
verificationMethod: "none"
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
const key = knownKeys.find((k) => k.kid === parsed.keyid);
|
|
317
|
-
if (!key) {
|
|
318
|
-
return {
|
|
319
|
-
isValid: false,
|
|
320
|
-
confidence: 0,
|
|
321
|
-
reason: `Unknown key ID: ${parsed.keyid}`,
|
|
322
|
-
verificationMethod: "none"
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
326
|
-
if (now < key.validFrom || now > key.validUntil) {
|
|
327
|
-
return {
|
|
328
|
-
isValid: false,
|
|
329
|
-
confidence: 0,
|
|
330
|
-
reason: "Key is not valid at current time",
|
|
331
|
-
verificationMethod: "none"
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
const signatureBase = buildSignatureBase(method, path, headers, parsed.signedHeaders);
|
|
335
|
-
let signatureValue = signature;
|
|
336
|
-
if (signatureValue.startsWith("sig1=:")) {
|
|
337
|
-
signatureValue = signatureValue.substring(6);
|
|
338
|
-
}
|
|
339
|
-
if (signatureValue.endsWith(":")) {
|
|
340
|
-
signatureValue = signatureValue.slice(0, -1);
|
|
341
|
-
}
|
|
342
|
-
const isValid = await verifyEd25519Signature(key.publicKey, signatureValue, signatureBase);
|
|
343
|
-
if (isValid) {
|
|
344
|
-
return {
|
|
345
|
-
isValid: true,
|
|
346
|
-
agent,
|
|
347
|
-
keyid: parsed.keyid,
|
|
348
|
-
confidence: 1,
|
|
349
|
-
// 100% confidence for valid signature
|
|
350
|
-
verificationMethod: "signature"
|
|
351
|
-
};
|
|
352
|
-
} else {
|
|
353
|
-
return {
|
|
354
|
-
isValid: false,
|
|
355
|
-
confidence: 0,
|
|
356
|
-
reason: "Signature verification failed",
|
|
357
|
-
verificationMethod: "none"
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
function hasSignatureHeaders(headers) {
|
|
362
|
-
return !!((headers["signature"] || headers["Signature"]) && (headers["signature-input"] || headers["Signature-Input"]));
|
|
363
|
-
}
|
|
364
|
-
function isChatGPTSignature(headers) {
|
|
365
|
-
const signatureAgent = headers["signature-agent"] || headers["Signature-Agent"];
|
|
366
|
-
if (!signatureAgent) {
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
const agentUrlStr = signatureAgent.replace(/^"+|"+$/g, "");
|
|
370
|
-
if (agentUrlStr === "https://chatgpt.com") {
|
|
371
|
-
return true;
|
|
372
|
-
}
|
|
373
|
-
try {
|
|
374
|
-
const agentUrl = new URL(agentUrlStr);
|
|
375
|
-
const allowedHosts = ["chatgpt.com", "www.chatgpt.com"];
|
|
376
|
-
return allowedHosts.includes(agentUrl.host);
|
|
377
|
-
} catch {
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
exports.hasSignatureHeaders = hasSignatureHeaders;
|
|
383
|
-
exports.isChatGPTSignature = isChatGPTSignature;
|
|
384
|
-
exports.verifyAgentSignature = verifyAgentSignature;
|