@agenticcli/shipguard 0.7.1 → 0.8.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 +2 -6
- package/dist/checksum-manifest.json +5 -5
- package/dist/{chunk-MPQ42F54.js → chunk-KGIK7XNK.js} +4 -18
- package/dist/{chunk-3NSULPWH.js → chunk-MVYY4QWT.js} +3 -3
- package/dist/{chunk-A63X4LUJ.js → chunk-VJBU6FNW.js} +264 -103
- package/dist/cli-facts.json +5 -5
- package/dist/cli.js +293 -93
- package/dist/{config-generator-2BVUZGEU.js → config-generator-4MK6PGY5.js} +2 -2
- package/dist/{dist-3SW45O4F.js → dist-YSE6YNXH.js} +1 -3
- package/dist/{pro-scanner-QDOFUEXZ.js → pro-scanner-5GYWJ7AS.js} +2 -2
- package/docs/llms.txt +2 -2
- package/package.json +5 -4
- package/rules/free-bundle.json +9 -9
|
@@ -2,14 +2,13 @@ import {
|
|
|
2
2
|
EXEC_RULE_FIELDS,
|
|
3
3
|
RE2JS_V1_RUNTIME_ID,
|
|
4
4
|
canonicalJson,
|
|
5
|
-
compileCached,
|
|
6
5
|
computeExecutableHash,
|
|
7
6
|
parseFlags,
|
|
8
7
|
parseStrictNoDup,
|
|
9
8
|
re2jsV1Executor,
|
|
10
9
|
selectExpected,
|
|
11
10
|
verifyExactSet
|
|
12
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KGIK7XNK.js";
|
|
13
12
|
|
|
14
13
|
// src/core/pro-scanner.ts
|
|
15
14
|
import * as path2 from "path";
|
|
@@ -57,6 +56,12 @@ function assertTrustedApiUrl(url) {
|
|
|
57
56
|
);
|
|
58
57
|
}
|
|
59
58
|
|
|
59
|
+
// src/core/links.ts
|
|
60
|
+
var GO_BASE = "https://agenticcli.dev/go/";
|
|
61
|
+
function goLink(slot) {
|
|
62
|
+
return `${GO_BASE}${slot}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
60
65
|
// src/utils/secure-fs.ts
|
|
61
66
|
import { chmodSync, mkdirSync, statSync, writeFileSync } from "fs";
|
|
62
67
|
var SECURE_DIR_MODE = 448;
|
|
@@ -71,6 +76,29 @@ function writeSecureFileSync(file, data) {
|
|
|
71
76
|
if (isPosix) chmodSync(file, SECURE_FILE_MODE);
|
|
72
77
|
}
|
|
73
78
|
|
|
79
|
+
// src/core/platform-status.ts
|
|
80
|
+
var PLATFORM_UNAVAILABLE_CODE = "PLATFORM_UNAVAILABLE";
|
|
81
|
+
var PlatformUnavailableError = class extends Error {
|
|
82
|
+
code = PLATFORM_UNAVAILABLE_CODE;
|
|
83
|
+
retryAfterSeconds;
|
|
84
|
+
constructor(message, retryAfterSeconds) {
|
|
85
|
+
super(message);
|
|
86
|
+
this.name = "PlatformUnavailableError";
|
|
87
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function parseRetryAfterSeconds(headers) {
|
|
91
|
+
const raw = typeof headers?.get === "function" ? headers.get("Retry-After") : null;
|
|
92
|
+
if (raw === null || raw.trim() === "") return void 0;
|
|
93
|
+
const seconds = Number(raw.trim());
|
|
94
|
+
return Number.isFinite(seconds) && seconds >= 0 ? Math.floor(seconds) : void 0;
|
|
95
|
+
}
|
|
96
|
+
function isPlatformUnavailable(res, body) {
|
|
97
|
+
const header = typeof res.headers?.get === "function" ? res.headers.get("X-Platform-Status") : null;
|
|
98
|
+
return body?.code === PLATFORM_UNAVAILABLE_CODE || res.status === 503 && header === "unavailable";
|
|
99
|
+
}
|
|
100
|
+
var PLATFORM_UNAVAILABLE_DEFAULT_MESSAGE = "Service temporarily unavailable. Please try again later.";
|
|
101
|
+
|
|
74
102
|
// src/core/auth.ts
|
|
75
103
|
var FILE_MODE = 384;
|
|
76
104
|
var UNSAFE_PERM_MASK = 63;
|
|
@@ -138,22 +166,29 @@ async function exchangeApiKeyForToken(apiKey, apiUrl) {
|
|
|
138
166
|
if (res.status === 401) {
|
|
139
167
|
console.error("[shipguard] SHIPGUARD_API_KEY exchange rejected \u2014 invalid or revoked key");
|
|
140
168
|
throw new Error(
|
|
141
|
-
|
|
169
|
+
`SHIPGUARD_API_KEY is invalid or has been revoked. Check the key value or generate a new one at ${goLink("dashboard")}.`
|
|
142
170
|
);
|
|
143
171
|
}
|
|
144
172
|
if (res.status === 402) {
|
|
145
173
|
console.error("[shipguard] SHIPGUARD_API_KEY exchange rejected \u2014 monthly budget exhausted");
|
|
146
174
|
throw new Error(
|
|
147
|
-
|
|
175
|
+
`SHIPGUARD_API_KEY has exhausted its monthly credit budget. Buy more at ${goLink("billing")}`
|
|
148
176
|
);
|
|
149
177
|
}
|
|
150
178
|
if (!res.ok) {
|
|
151
179
|
let detail = res.statusText;
|
|
180
|
+
let body2 = null;
|
|
152
181
|
try {
|
|
153
|
-
|
|
182
|
+
body2 = await res.json();
|
|
154
183
|
detail = body2?.error_description ?? body2?.error ?? detail;
|
|
155
184
|
} catch {
|
|
156
185
|
}
|
|
186
|
+
if (isPlatformUnavailable(res, body2)) {
|
|
187
|
+
throw new PlatformUnavailableError(
|
|
188
|
+
typeof body2?.error === "string" ? body2.error : PLATFORM_UNAVAILABLE_DEFAULT_MESSAGE,
|
|
189
|
+
parseRetryAfterSeconds(res.headers)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
157
192
|
console.error(`[shipguard] SHIPGUARD_API_KEY exchange failed (${res.status}): ${detail}`);
|
|
158
193
|
throw new Error(`SHIPGUARD_API_KEY exchange failed (${res.status}): ${detail}`);
|
|
159
194
|
}
|
|
@@ -202,10 +237,24 @@ async function getAuthToken(apiUrl) {
|
|
|
202
237
|
});
|
|
203
238
|
return access_token;
|
|
204
239
|
}
|
|
240
|
+
let refusedBody = null;
|
|
241
|
+
try {
|
|
242
|
+
const probe = typeof res.clone === "function" ? res.clone() : res;
|
|
243
|
+
refusedBody = await probe.json();
|
|
244
|
+
} catch {
|
|
245
|
+
refusedBody = null;
|
|
246
|
+
}
|
|
247
|
+
if (isPlatformUnavailable(res, refusedBody)) {
|
|
248
|
+
throw new PlatformUnavailableError(
|
|
249
|
+
typeof refusedBody?.error === "string" ? refusedBody.error : PLATFORM_UNAVAILABLE_DEFAULT_MESSAGE,
|
|
250
|
+
parseRetryAfterSeconds(res.headers)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
205
253
|
console.error(
|
|
206
254
|
`[shipguard] Token refresh refused by ${creds.apiUrl} (HTTP ${res.status} ${res.statusText}) \u2014 you will be asked to log in again.`
|
|
207
255
|
);
|
|
208
256
|
} catch (err) {
|
|
257
|
+
if (err instanceof PlatformUnavailableError) throw err;
|
|
209
258
|
const detail = err instanceof Error ? err.message : String(err);
|
|
210
259
|
console.error(
|
|
211
260
|
`[shipguard] Token refresh failed \u2014 you will be asked to log in again. Reason: ${detail}`
|
|
@@ -221,62 +270,91 @@ import * as path from "path";
|
|
|
221
270
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
222
271
|
|
|
223
272
|
// src/core/crypto.ts
|
|
224
|
-
|
|
273
|
+
import { createHash } from "crypto";
|
|
274
|
+
|
|
275
|
+
// src/core/keyring-ceremony-output.ts
|
|
276
|
+
var CEREMONY_OUTPUT = {
|
|
277
|
+
ra: {
|
|
278
|
+
kid: "ra-k2-2026",
|
|
279
|
+
fingerprint: "a3c0751a14d6933c2e0dbfca69f50a0189ed749153d62b1b76727fc714bf043c",
|
|
280
|
+
publicKey: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAI5sKq3SF+toDqPO3Brz1FkWOl7INL/O9K3BBtPS3zTo=\n-----END PUBLIC KEY-----"
|
|
281
|
+
},
|
|
282
|
+
cf: {
|
|
283
|
+
kid: "cf-k2-2026",
|
|
284
|
+
fingerprint: "3535a1f5bdd798af75e893aaa93346df6b7e421632ca8bc0105ff866a89c0cee",
|
|
285
|
+
publicKey: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAjyVy38g4NcfXqD3WmZP7ygit8m4aoywK0KsA0jYiEv4=\n-----END PUBLIC KEY-----"
|
|
286
|
+
},
|
|
287
|
+
bundle: {
|
|
288
|
+
kid: "k3-2026",
|
|
289
|
+
fingerprint: "3cbd12f5c1ef05c33527899f0d074585cb26bacdfe6f13a63cbea243d5c8e57e",
|
|
290
|
+
publicKey: "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEA4seZCqwlRq+QzOsIA6+RJUHXHWe4lb1ok6hwL0Bvqzs=\n-----END PUBLIC KEY-----"
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/core/crypto.ts
|
|
295
|
+
var PINNED_KEYS = {};
|
|
296
|
+
var DEFAULT_KID = CEREMONY_OUTPUT.bundle.kid;
|
|
297
|
+
var MIN_ACCEPTABLE_EPOCH = 2;
|
|
298
|
+
var REVOKED_FINGERPRINTS = /* @__PURE__ */ new Set([
|
|
299
|
+
"855e81b870c16d377efd8354e9761fadca2d22d16536f291fb77e690f9d65abc",
|
|
300
|
+
// keys no longer trusted
|
|
301
|
+
"003837c9c656f66163a29e7b0d043a084fc83c2febc420a5e27889205a27b878",
|
|
302
|
+
// keys no longer trusted
|
|
303
|
+
"87787b86689151fd9a9b763e3baa2cae884bf897d51dc02a211c70640e2c4f9d",
|
|
304
|
+
// keys no longer trusted
|
|
305
|
+
"57873aac03421fa0740fdd9520729536223010067ea3012135db2b255a2b263c"
|
|
306
|
+
// keys no longer trusted
|
|
307
|
+
]);
|
|
308
|
+
var KEYRING_PLACEHOLDER_MARKER = "SHIPGUARD_KEYRING_PLACEHOLDER";
|
|
309
|
+
function isKeyringPlaceholder(entry) {
|
|
310
|
+
return entry.publicKey.includes(KEYRING_PLACEHOLDER_MARKER) || entry.fingerprint.includes(KEYRING_PLACEHOLDER_MARKER);
|
|
311
|
+
}
|
|
312
|
+
function spkiDerFromPem(pem) {
|
|
313
|
+
const m = /^-----BEGIN PUBLIC KEY-----\s*([A-Za-z0-9+/=\s]+?)\s*-----END PUBLIC KEY-----\s*$/.exec(pem.trim());
|
|
314
|
+
if (!m) throw new Error("not a PEM-encoded SPKI public key");
|
|
315
|
+
const der = Buffer.from(m[1].replace(/\s/g, ""), "base64");
|
|
316
|
+
if (der.length === 0) throw new Error("empty SPKI public key");
|
|
317
|
+
return der;
|
|
318
|
+
}
|
|
225
319
|
var KEYRING = [
|
|
226
|
-
// ----- RELEASE-ATTESTATION (
|
|
227
|
-
// Signs corpus manifest + release attestation objects.
|
|
228
|
-
// Private half lives ONLY in ~/.secrets/prod-deploy.env (mode 600) — never shipped, never repo.
|
|
320
|
+
// ----- RELEASE-ATTESTATION (ra-k2-2026, epoch 2) -----
|
|
321
|
+
// Signs corpus manifest + release attestation objects. The private half is never shipped and never stored in this repository.
|
|
229
322
|
{
|
|
230
|
-
kid:
|
|
323
|
+
kid: CEREMONY_OUTPUT.ra.kid,
|
|
231
324
|
role: "release-attestation",
|
|
232
|
-
epoch:
|
|
233
|
-
expiry:
|
|
234
|
-
// 2027-
|
|
235
|
-
fingerprint:
|
|
236
|
-
publicKey:
|
|
237
|
-
MCowBQYDK2VwAyEANcib9WOOIys1wLQW30T/RvRv+3d/+2DAWKOKwEj5sS0=
|
|
238
|
-
-----END PUBLIC KEY-----`
|
|
325
|
+
epoch: 2,
|
|
326
|
+
expiry: 1822348800,
|
|
327
|
+
// 2027-10-01 00:00:00 UTC
|
|
328
|
+
fingerprint: CEREMONY_OUTPUT.ra.fingerprint,
|
|
329
|
+
publicKey: CEREMONY_OUTPUT.ra.publicKey
|
|
239
330
|
},
|
|
240
|
-
// ----- CI-FRESHNESS (
|
|
241
|
-
// Signs short-TTL freshness tokens.
|
|
242
|
-
// Private half lives ONLY in ~/.secrets/prod-deploy.env (mode 600) — never shipped, never repo.
|
|
331
|
+
// ----- CI-FRESHNESS (cf-k2-2026, epoch 2) -----
|
|
332
|
+
// Signs short-TTL freshness tokens. The private half is never stored in this repository.
|
|
243
333
|
{
|
|
244
|
-
kid:
|
|
334
|
+
kid: CEREMONY_OUTPUT.cf.kid,
|
|
245
335
|
role: "ci-freshness",
|
|
246
|
-
epoch:
|
|
247
|
-
expiry:
|
|
248
|
-
// 2027-
|
|
249
|
-
fingerprint:
|
|
250
|
-
publicKey:
|
|
251
|
-
MCowBQYDK2VwAyEAaQ49ermPqqsENKA7fFi8K0zIEyxYEje56a34Pus6UhM=
|
|
252
|
-
-----END PUBLIC KEY-----`
|
|
253
|
-
},
|
|
254
|
-
// ----- BUNDLE keys (existing k1-2026 and k2-2026) -----
|
|
255
|
-
// Convex-held; signs per-request bundle envelopes. PINNED_KEYS stays in sync.
|
|
256
|
-
{
|
|
257
|
-
kid: "k1-2026",
|
|
258
|
-
role: "bundle",
|
|
259
|
-
epoch: 1,
|
|
260
|
-
expiry: 1798761600,
|
|
261
|
-
fingerprint: "855e81b870c16d377efd8354e9761fadca2d22d16536f291fb77e690f9d65abc",
|
|
262
|
-
publicKey: `-----BEGIN PUBLIC KEY-----
|
|
263
|
-
MCowBQYDK2VwAyEAkpeX0A3zIOttGn8t+jagJHLRTv5Q809vqIZU37lE6xQ=
|
|
264
|
-
-----END PUBLIC KEY-----`
|
|
336
|
+
epoch: 2,
|
|
337
|
+
expiry: 1822348800,
|
|
338
|
+
// 2027-10-01 00:00:00 UTC
|
|
339
|
+
fingerprint: CEREMONY_OUTPUT.cf.fingerprint,
|
|
340
|
+
publicKey: CEREMONY_OUTPUT.cf.publicKey
|
|
265
341
|
},
|
|
342
|
+
// ----- BUNDLE key (k3-2026, epoch 3; Convex-held; signs per-request bundle envelopes) -----
|
|
266
343
|
{
|
|
267
|
-
kid:
|
|
344
|
+
kid: CEREMONY_OUTPUT.bundle.kid,
|
|
268
345
|
role: "bundle",
|
|
269
|
-
epoch:
|
|
270
|
-
expiry:
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
-----END PUBLIC KEY-----`
|
|
346
|
+
epoch: 3,
|
|
347
|
+
expiry: 1822348800,
|
|
348
|
+
// 2027-10-01 00:00:00 UTC
|
|
349
|
+
fingerprint: CEREMONY_OUTPUT.bundle.fingerprint,
|
|
350
|
+
publicKey: CEREMONY_OUTPUT.bundle.publicKey
|
|
275
351
|
}
|
|
276
352
|
// AUTH key: managed separately via JWKS endpoint; the CLI does NOT pin auth keys for
|
|
277
|
-
// release trust
|
|
278
|
-
// If you need to add auth-k1-2026 here, obtain the public PEM from the auth service JWKS.
|
|
353
|
+
// release trust.
|
|
279
354
|
];
|
|
355
|
+
PINNED_KEYS = Object.fromEntries(
|
|
356
|
+
KEYRING.filter((e) => e.role === "bundle" && !isKeyringPlaceholder(e)).map((e) => [e.kid, e.publicKey])
|
|
357
|
+
);
|
|
280
358
|
function validateKeyringEntry(entry) {
|
|
281
359
|
if (entry.epoch < MIN_ACCEPTABLE_EPOCH) {
|
|
282
360
|
throw new Error(
|
|
@@ -289,11 +367,6 @@ function validateKeyringEntry(entry) {
|
|
|
289
367
|
);
|
|
290
368
|
}
|
|
291
369
|
}
|
|
292
|
-
function pemToArrayBuffer(pem) {
|
|
293
|
-
const b64 = pem.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, "");
|
|
294
|
-
const binary = Buffer.from(b64, "base64");
|
|
295
|
-
return binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength);
|
|
296
|
-
}
|
|
297
370
|
async function resolveAndImportKey(kid, expectedRole) {
|
|
298
371
|
const entry = KEYRING.find((e) => e.kid === kid);
|
|
299
372
|
if (!entry) {
|
|
@@ -301,15 +374,38 @@ async function resolveAndImportKey(kid, expectedRole) {
|
|
|
301
374
|
`Unknown key "${kid}" \u2014 not found in KEYRING. Upgrade shipguard to a version that supports this key id.`
|
|
302
375
|
);
|
|
303
376
|
}
|
|
377
|
+
if (isKeyringPlaceholder(entry)) {
|
|
378
|
+
throw new Error(
|
|
379
|
+
`Key "${kid}" is an unfilled key-ceremony placeholder \u2014 this build cannot verify it. Upgrade shipguard to a released version.`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
304
382
|
validateKeyringEntry(entry);
|
|
305
383
|
if (entry.role !== expectedRole) {
|
|
306
384
|
throw new Error(
|
|
307
385
|
`key role mismatch: expected ${expectedRole}, got ${entry.role} \u2014 cross-role replay rejected`
|
|
308
386
|
);
|
|
309
387
|
}
|
|
388
|
+
let der;
|
|
389
|
+
try {
|
|
390
|
+
der = spkiDerFromPem(entry.publicKey);
|
|
391
|
+
} catch (err) {
|
|
392
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
393
|
+
throw new Error(`Key "${kid}" has an unreadable public key: ${msg}`);
|
|
394
|
+
}
|
|
395
|
+
const computed = createHash("sha256").update(der).digest("hex");
|
|
396
|
+
if (computed !== entry.fingerprint.toLowerCase()) {
|
|
397
|
+
throw new Error(
|
|
398
|
+
`Key "${kid}" fingerprint mismatch: declared ${entry.fingerprint}, computed ${computed} \u2014 refusing key`
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
if (REVOKED_FINGERPRINTS.has(computed)) {
|
|
402
|
+
throw new Error(
|
|
403
|
+
`Key "${kid}" is revoked (fingerprint ${computed} is on the revoked-key denylist) \u2014 refusing key`
|
|
404
|
+
);
|
|
405
|
+
}
|
|
310
406
|
return globalThis.crypto.subtle.importKey(
|
|
311
407
|
"spki",
|
|
312
|
-
|
|
408
|
+
der.buffer.slice(der.byteOffset, der.byteOffset + der.byteLength),
|
|
313
409
|
{ name: "Ed25519" },
|
|
314
410
|
false,
|
|
315
411
|
["verify"]
|
|
@@ -392,6 +488,31 @@ function acquireFloorLock(lockPath, timeoutMs = 5e3) {
|
|
|
392
488
|
}
|
|
393
489
|
throw new Error(`floor lock timeout after ${timeoutMs}ms \u2014 concurrent CLI writer?`);
|
|
394
490
|
}
|
|
491
|
+
function compareFloorTuples(floor, incoming) {
|
|
492
|
+
if (incoming.keyringEpoch > floor.keyringEpoch) return { decision: "advance" };
|
|
493
|
+
if (incoming.keyringEpoch < floor.keyringEpoch) {
|
|
494
|
+
return {
|
|
495
|
+
decision: "reject",
|
|
496
|
+
reason: `keyring epoch rollback rejected: incoming epoch=${incoming.keyringEpoch}, floor epoch=${floor.keyringEpoch}`
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
if (incoming.sequence < floor.sequence) {
|
|
500
|
+
return {
|
|
501
|
+
decision: "reject",
|
|
502
|
+
reason: `sequence rollback rejected: incoming=${incoming.sequence}, floor=${floor.sequence} (epoch ${floor.keyringEpoch})`
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
if (incoming.sequence === floor.sequence) {
|
|
506
|
+
if (incoming.releaseId === floor.releaseId && incoming.manifestDigest === floor.manifestDigest) {
|
|
507
|
+
return { decision: "idempotent" };
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
decision: "reject",
|
|
511
|
+
reason: `same-sequence/different-tuple rejected: sequence=${incoming.sequence} (epoch ${floor.keyringEpoch})`
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
return { decision: "advance" };
|
|
515
|
+
}
|
|
395
516
|
function atomicAcceptFloor(floorPath, incoming) {
|
|
396
517
|
const lockPath = `${floorPath}.lock`;
|
|
397
518
|
const dir = path.dirname(floorPath);
|
|
@@ -430,22 +551,11 @@ function atomicAcceptFloor(floorPath, incoming) {
|
|
|
430
551
|
}
|
|
431
552
|
}
|
|
432
553
|
if (lockedFloor !== null) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
reason: `sequence rollback rejected (under-lock): incoming=${incoming.sequence}, locked-floor=${lockedFloor.sequence}`
|
|
437
|
-
};
|
|
554
|
+
const decision = compareFloorTuples(lockedFloor, incoming);
|
|
555
|
+
if (decision.decision === "reject") {
|
|
556
|
+
return { accepted: false, reason: `${decision.reason} (under-lock)` };
|
|
438
557
|
}
|
|
439
|
-
if (
|
|
440
|
-
const sameReleaseId = incoming.releaseId === lockedFloor.releaseId;
|
|
441
|
-
const sameManifest = incoming.manifestDigest === lockedFloor.manifestDigest;
|
|
442
|
-
const sameEpoch = incoming.keyringEpoch === lockedFloor.keyringEpoch;
|
|
443
|
-
if (!sameReleaseId || !sameManifest || !sameEpoch) {
|
|
444
|
-
return {
|
|
445
|
-
accepted: false,
|
|
446
|
-
reason: `same-sequence/different-tuple rejected (under-lock): sequence=${incoming.sequence}`
|
|
447
|
-
};
|
|
448
|
-
}
|
|
558
|
+
if (decision.decision === "idempotent") {
|
|
449
559
|
return { accepted: true, wrote: false };
|
|
450
560
|
}
|
|
451
561
|
}
|
|
@@ -960,7 +1070,7 @@ async function verifyBundleResponse(response, request, floorPath) {
|
|
|
960
1070
|
if (freshnessTok["manifestDigest"] !== manifestDigest) {
|
|
961
1071
|
return {
|
|
962
1072
|
ok: false,
|
|
963
|
-
reason: `freshnessTok.manifestDigest mismatch \u2014 token bound to a different manifest
|
|
1073
|
+
reason: `freshnessTok.manifestDigest mismatch \u2014 token bound to a different manifest`,
|
|
964
1074
|
nonSafe: true
|
|
965
1075
|
};
|
|
966
1076
|
}
|
|
@@ -1062,7 +1172,14 @@ async function verifyBundleResponse(response, request, floorPath) {
|
|
|
1062
1172
|
};
|
|
1063
1173
|
}
|
|
1064
1174
|
const attestationEntry = KEYRING.find((e) => e.kid === attestation["kid"]);
|
|
1065
|
-
|
|
1175
|
+
if (!attestationEntry) {
|
|
1176
|
+
return {
|
|
1177
|
+
ok: false,
|
|
1178
|
+
reason: `attestation kid "${String(attestation["kid"])}" vanished from KEYRING after verification`,
|
|
1179
|
+
nonSafe: true
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
const incomingKeyringEpoch = attestationEntry.epoch;
|
|
1066
1183
|
const incomingTuple = {
|
|
1067
1184
|
sequence: incomingSequence,
|
|
1068
1185
|
releaseId: incomingReleaseId,
|
|
@@ -1193,7 +1310,7 @@ function compileDetectorRegex(source, flags = "") {
|
|
|
1193
1310
|
}
|
|
1194
1311
|
|
|
1195
1312
|
// src/core/redact.ts
|
|
1196
|
-
import { createHash } from "crypto";
|
|
1313
|
+
import { createHash as createHash2 } from "crypto";
|
|
1197
1314
|
function redactSecretValue(value) {
|
|
1198
1315
|
if (value.length <= 8) return "***";
|
|
1199
1316
|
return value.slice(0, 8) + "***";
|
|
@@ -1270,7 +1387,7 @@ function redactEvidence(evidence, category) {
|
|
|
1270
1387
|
}
|
|
1271
1388
|
function computeFindingKey(finding) {
|
|
1272
1389
|
const basis = finding.evidence && finding.evidence.length > 0 ? finding.evidence : finding.title;
|
|
1273
|
-
return
|
|
1390
|
+
return createHash2("sha256").update(basis).digest("hex").slice(0, 16);
|
|
1274
1391
|
}
|
|
1275
1392
|
var FINDING_KEY_PROP = "_findingKey";
|
|
1276
1393
|
function getFindingKey(finding) {
|
|
@@ -1442,7 +1559,7 @@ var SECRET_PATTERNS = [
|
|
|
1442
1559
|
recommendation: "Remove from source code. Use process.env.RAZORPAY_KEY_SECRET and store in a gitignored .env file."
|
|
1443
1560
|
},
|
|
1444
1561
|
// JWT secret
|
|
1445
|
-
//
|
|
1562
|
+
// Free-tier secret gaps: the opening quote used to be MANDATORY (`['"]([^'"]{16,})`),
|
|
1446
1563
|
// which only matches source-file assignment style (`const x = "value"`). A .env
|
|
1447
1564
|
// file's `JWT_SECRET=value` line has no quotes at all, so this pattern never
|
|
1448
1565
|
// matched .env content. Quotes are now optional on both sides, and the capture
|
|
@@ -1462,10 +1579,10 @@ var SECRET_PATTERNS = [
|
|
|
1462
1579
|
recommendation: "Remove from source code. Generate a strong random secret, store it in environment variables."
|
|
1463
1580
|
},
|
|
1464
1581
|
// Supabase service-role key — current key format (2025+ rotation: sb_secret_...)
|
|
1465
|
-
//
|
|
1582
|
+
// Free-tier secret gaps: the free tier had no Supabase-specific service-role pattern at
|
|
1466
1583
|
// all — a variable literally named SERVICE_ROLE_KEY matched none of the generic
|
|
1467
1584
|
// secret-name keywords (api_key/secret/token/password/auth_key/access_key) below,
|
|
1468
|
-
// per
|
|
1585
|
+
// per a miss seen on a real project.
|
|
1469
1586
|
// This prefix match covers the current opaque key format; the legacy JWT format
|
|
1470
1587
|
// (pre-2025 projects) is handled separately by checkSupabaseServiceRoleJwt below,
|
|
1471
1588
|
// which decodes the payload rather than pattern-matching the shape.
|
|
@@ -1495,10 +1612,9 @@ var SECRET_PATTERNS = [
|
|
|
1495
1612
|
// D.4 REWRITE: Removed native negative-lookahead (?!\s*\+|\.) — not supported by re2js.
|
|
1496
1613
|
// Equivalent behavior is achieved via postExcludeFollowedBy() which checks the
|
|
1497
1614
|
// character immediately after the closing quote. See DIFFERENTIAL NOTE above.
|
|
1498
|
-
//
|
|
1615
|
+
// Free-tier secret gaps: both quotes used to be MANDATORY (`['"](...)['"]`), which only
|
|
1499
1616
|
// matches source-file assignment style (`const x = "value"`) and never a .env file's
|
|
1500
|
-
// unquoted `TOKEN=value` line — confirmed by
|
|
1501
|
-
// apps/web/content/blog/github-secret-scanner-vs-cli-tools.md (INTERNAL_DEPLOY_TOKEN
|
|
1617
|
+
// unquoted `TOKEN=value` line — confirmed by a miss seen on a real project (INTERNAL_DEPLOY_TOKEN
|
|
1502
1618
|
// caught when moved into config.ts, not when left in .env). Quotes are now optional;
|
|
1503
1619
|
// the capture class already excludes whitespace and quote characters, so an unquoted
|
|
1504
1620
|
// .env value still terminates correctly instead of over-capturing.
|
|
@@ -2203,11 +2319,10 @@ var MIGRATION_PATTERNS = [
|
|
|
2203
2319
|
/^migrations\/.+\.sql$/i,
|
|
2204
2320
|
/^db\/.+\.sql$/i,
|
|
2205
2321
|
// Supabase CLI default layout (`supabase init` / `supabase migration new`) —
|
|
2206
|
-
//
|
|
2322
|
+
// free-tier secret gaps: this was missing entirely, so every DEFAULT Supabase project's
|
|
2207
2323
|
// migrations silently skipped the destructive-migration checks below (DROP TABLE,
|
|
2208
|
-
// TRUNCATE, DELETE FROM without WHERE, etc.).
|
|
2209
|
-
//
|
|
2210
|
-
// `supabase/migrations/0001_create_orders.sql` went unclassified and unscanned.
|
|
2324
|
+
// TRUNCATE, DELETE FROM without WHERE, etc.). A
|
|
2325
|
+
// real-world repro: `supabase/migrations/0001_create_orders.sql` went unclassified and unscanned.
|
|
2211
2326
|
/^supabase\/migrations\/.+\.sql$/i,
|
|
2212
2327
|
/^[^/]+\.sql$/i
|
|
2213
2328
|
// root-level .sql files
|
|
@@ -3235,8 +3350,34 @@ function applySuppressions(findings, files) {
|
|
|
3235
3350
|
return findings;
|
|
3236
3351
|
}
|
|
3237
3352
|
|
|
3238
|
-
// src/core/
|
|
3353
|
+
// src/core/re2js-compile-cache.ts
|
|
3239
3354
|
import { RE2JS as RE2JS2 } from "re2js";
|
|
3355
|
+
var COMPILE_CACHE_MAX = 2e4;
|
|
3356
|
+
var cache = /* @__PURE__ */ new Map();
|
|
3357
|
+
var INSTALLED = /* @__PURE__ */ Symbol.for("agenticcli.re2js.compileCache");
|
|
3358
|
+
function installRe2jsCompileCache() {
|
|
3359
|
+
const target = RE2JS2;
|
|
3360
|
+
if (target[INSTALLED]) return;
|
|
3361
|
+
const original = target.compile.bind(RE2JS2);
|
|
3362
|
+
target.compile = (pattern, flags = 0) => {
|
|
3363
|
+
const key = `${flags}\0${pattern}`;
|
|
3364
|
+
const hit = cache.get(key);
|
|
3365
|
+
if (hit !== void 0) return hit;
|
|
3366
|
+
const compiled = original(pattern, flags);
|
|
3367
|
+
if (cache.size >= COMPILE_CACHE_MAX) cache.clear();
|
|
3368
|
+
cache.set(key, compiled);
|
|
3369
|
+
return compiled;
|
|
3370
|
+
};
|
|
3371
|
+
target[INSTALLED] = true;
|
|
3372
|
+
}
|
|
3373
|
+
function compileCached(pattern, flags) {
|
|
3374
|
+
installRe2jsCompileCache();
|
|
3375
|
+
return RE2JS2.compile(pattern, flags);
|
|
3376
|
+
}
|
|
3377
|
+
|
|
3378
|
+
// src/core/pro-scanner.ts
|
|
3379
|
+
import { RE2JS as RE2JS3 } from "re2js";
|
|
3380
|
+
installRe2jsCompileCache();
|
|
3240
3381
|
var activeExecutor = re2jsV1Executor;
|
|
3241
3382
|
var DEFAULT_FLOOR_PATH = path2.join(os.homedir(), ".shipguard", "release-floor.json");
|
|
3242
3383
|
var NoRulesAppliedError = class extends Error {
|
|
@@ -3248,7 +3389,7 @@ var NoRulesAppliedError = class extends Error {
|
|
|
3248
3389
|
};
|
|
3249
3390
|
var ProFetchError = class extends Error {
|
|
3250
3391
|
code;
|
|
3251
|
-
/** Only populated for RATE_LIMITED, when the server sends a `Retry-After` header. */
|
|
3392
|
+
/** Only populated for RATE_LIMITED and PLATFORM_UNAVAILABLE, when the server sends a usable `Retry-After` header. */
|
|
3252
3393
|
retryAfterSeconds;
|
|
3253
3394
|
constructor(code, message, opts) {
|
|
3254
3395
|
super(message);
|
|
@@ -3257,9 +3398,23 @@ var ProFetchError = class extends Error {
|
|
|
3257
3398
|
this.retryAfterSeconds = opts?.retryAfterSeconds;
|
|
3258
3399
|
}
|
|
3259
3400
|
};
|
|
3401
|
+
function parseCreditsRemaining(headers) {
|
|
3402
|
+
const raw = headers.get("X-Credits-Remaining");
|
|
3403
|
+
if (raw === null || raw.trim() === "") return void 0;
|
|
3404
|
+
const credits = Number(raw.trim());
|
|
3405
|
+
return Number.isFinite(credits) ? credits : void 0;
|
|
3406
|
+
}
|
|
3260
3407
|
async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath) {
|
|
3261
3408
|
assertTrustedApiUrl(apiUrl);
|
|
3262
|
-
|
|
3409
|
+
let token;
|
|
3410
|
+
try {
|
|
3411
|
+
token = await getAuthToken(apiUrl);
|
|
3412
|
+
} catch (err) {
|
|
3413
|
+
if (err instanceof PlatformUnavailableError) {
|
|
3414
|
+
throw new ProFetchError("PLATFORM_UNAVAILABLE", err.message, { retryAfterSeconds: err.retryAfterSeconds });
|
|
3415
|
+
}
|
|
3416
|
+
throw err;
|
|
3417
|
+
}
|
|
3263
3418
|
if (!token) throw new ProFetchError("AUTH_FAILED", "Not authenticated. Run `shipguard login` first.");
|
|
3264
3419
|
let res;
|
|
3265
3420
|
try {
|
|
@@ -3292,15 +3447,20 @@ async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath)
|
|
|
3292
3447
|
errorBody.error ?? "No rule release has ever been activated on the server \u2014 Pro rules genuinely cannot be served right now (a server-side activation gap, not a transient outage)."
|
|
3293
3448
|
);
|
|
3294
3449
|
}
|
|
3450
|
+
if (isPlatformUnavailable(res, errorBody)) {
|
|
3451
|
+
throw new ProFetchError(
|
|
3452
|
+
"PLATFORM_UNAVAILABLE",
|
|
3453
|
+
errorBody?.error ?? PLATFORM_UNAVAILABLE_DEFAULT_MESSAGE,
|
|
3454
|
+
{ retryAfterSeconds: parseRetryAfterSeconds(res.headers) }
|
|
3455
|
+
);
|
|
3456
|
+
}
|
|
3295
3457
|
if (res.status === 401) throw new ProFetchError("AUTH_FAILED", "Auth expired. Run `shipguard login` again.");
|
|
3296
|
-
if (res.status === 402) throw new ProFetchError("INSUFFICIENT_CREDITS",
|
|
3458
|
+
if (res.status === 402) throw new ProFetchError("INSUFFICIENT_CREDITS", `No credits. Buy at ${goLink("billing")}`);
|
|
3297
3459
|
if (res.status === 429) {
|
|
3298
|
-
const retryAfterHeader = res.headers.get("Retry-After");
|
|
3299
|
-
const retryAfterSeconds = retryAfterHeader ? parseInt(retryAfterHeader, 10) : void 0;
|
|
3300
3460
|
throw new ProFetchError(
|
|
3301
3461
|
"RATE_LIMITED",
|
|
3302
3462
|
`Rate limited (429): too many pro rule fetches.`,
|
|
3303
|
-
{ retryAfterSeconds:
|
|
3463
|
+
{ retryAfterSeconds: parseRetryAfterSeconds(res.headers) }
|
|
3304
3464
|
);
|
|
3305
3465
|
}
|
|
3306
3466
|
if (res.status === 409) throw new ProFetchError("SERVER_ERROR", `Rule fetch conflict (409): ${res.statusText}`);
|
|
@@ -3316,12 +3476,12 @@ async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath)
|
|
|
3316
3476
|
if (res.status >= 500) throw new ProFetchError("SERVER_ERROR", `Rule fetch failed (${res.status}): ${res.statusText}`);
|
|
3317
3477
|
throw new ProFetchError("SERVER_ERROR", `Rule fetch failed: ${res.statusText}`);
|
|
3318
3478
|
}
|
|
3319
|
-
const credits =
|
|
3479
|
+
const credits = parseCreditsRemaining(res.headers);
|
|
3320
3480
|
const rulesVersion = res.headers.get("X-Rules-Version") ?? void 0;
|
|
3321
3481
|
const rawText = await res.text();
|
|
3322
3482
|
let responseJson;
|
|
3323
3483
|
try {
|
|
3324
|
-
const { parseStrictNoDup: parseStrict } = await import("./dist-
|
|
3484
|
+
const { parseStrictNoDup: parseStrict } = await import("./dist-YSE6YNXH.js");
|
|
3325
3485
|
responseJson = parseStrict(rawText);
|
|
3326
3486
|
} catch (parseErr) {
|
|
3327
3487
|
const msg = parseErr instanceof Error ? parseErr.message : String(parseErr);
|
|
@@ -3361,10 +3521,10 @@ async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath)
|
|
|
3361
3521
|
explanation: r.title,
|
|
3362
3522
|
recommendation: "",
|
|
3363
3523
|
action,
|
|
3364
|
-
//
|
|
3524
|
+
// Per-rule confidence (hardcoded-confidence fix): carry the rule's REAL signed confidence.
|
|
3365
3525
|
// verifyBundleResponse has already fail-closed if any rule lacks confidence, so
|
|
3366
3526
|
// r.confidence is guaranteed present here — never a silent HIGH default. Corpus
|
|
3367
|
-
// governance
|
|
3527
|
+
// governance calibrates action to this value, and
|
|
3368
3528
|
// deriveBlocking() + CLI output/JSON depend on it being the author's signed intent.
|
|
3369
3529
|
confidence: r.confidence,
|
|
3370
3530
|
matcher: {
|
|
@@ -3374,7 +3534,7 @@ async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath)
|
|
|
3374
3534
|
patterns: r.pattern ? [r.pattern] : [],
|
|
3375
3535
|
antiPatterns: r.antiPattern ? [r.antiPattern] : [],
|
|
3376
3536
|
flags: r.flags,
|
|
3377
|
-
//
|
|
3537
|
+
// antiPatternScope and boundary are now part of the 20-field
|
|
3378
3538
|
// hash preimage (contract 0.5.0) and ARE delivered on the wire ExecutableRule.
|
|
3379
3539
|
// They were missing from this mapping, causing runProRules to always default to
|
|
3380
3540
|
// antiPatternScope:'statement' / boundary:'none' — ignoring the corpus values.
|
|
@@ -3402,14 +3562,14 @@ async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath)
|
|
|
3402
3562
|
}
|
|
3403
3563
|
throw new ProFetchError(
|
|
3404
3564
|
"BUNDLE_INVALID",
|
|
3405
|
-
"legacy-bundle-rejected: attestation required \u2014 server response lacks fullManifest. The server must deliver a BundleResponse with fullManifest + corpusAttestation (attested-release protocol
|
|
3565
|
+
"legacy-bundle-rejected: attestation required \u2014 server response lacks fullManifest. The server must deliver a BundleResponse with fullManifest + corpusAttestation (attested-release protocol). Exit non-safe."
|
|
3406
3566
|
);
|
|
3407
3567
|
}
|
|
3408
3568
|
function toRe2jsFlags2(flags) {
|
|
3409
3569
|
let bits = 0;
|
|
3410
|
-
if (flags.has("i")) bits |=
|
|
3411
|
-
if (flags.has("m")) bits |=
|
|
3412
|
-
if (flags.has("s")) bits |=
|
|
3570
|
+
if (flags.has("i")) bits |= RE2JS3.CASE_INSENSITIVE;
|
|
3571
|
+
if (flags.has("m")) bits |= RE2JS3.MULTILINE;
|
|
3572
|
+
if (flags.has("s")) bits |= RE2JS3.DOTALL;
|
|
3413
3573
|
return bits;
|
|
3414
3574
|
}
|
|
3415
3575
|
function validateBundleCompile(rules) {
|
|
@@ -3441,7 +3601,7 @@ function validateBundleCompile(rules) {
|
|
|
3441
3601
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3442
3602
|
return {
|
|
3443
3603
|
ok: false,
|
|
3444
|
-
reason: `Rule ${rule.id}: anti-pattern "${ap}" fails re2js compilation \u2014 ${msg}. The entire bundle is degraded rather than running the rule without its anti-pattern guard (atomic compile,
|
|
3604
|
+
reason: `Rule ${rule.id}: anti-pattern "${ap}" fails re2js compilation \u2014 ${msg}. The entire bundle is degraded rather than running the rule without its anti-pattern guard (atomic compile, fail-closed).`
|
|
3445
3605
|
};
|
|
3446
3606
|
}
|
|
3447
3607
|
}
|
|
@@ -3496,7 +3656,7 @@ function runProRules(rules, files, _policy) {
|
|
|
3496
3656
|
patterns: rule.matcher.patterns,
|
|
3497
3657
|
antiPatterns: rule.matcher.antiPatterns,
|
|
3498
3658
|
flags: rule.matcher.flags ?? "",
|
|
3499
|
-
//
|
|
3659
|
+
// pass through delivered values; executor defaults to 'none'/'statement'.
|
|
3500
3660
|
...boundary !== void 0 && { boundary },
|
|
3501
3661
|
...antiPatternScope !== void 0 && { antiPatternScope }
|
|
3502
3662
|
};
|
|
@@ -3565,7 +3725,7 @@ function runProRules(rules, files, _policy) {
|
|
|
3565
3725
|
recommendation: rule.recommendation,
|
|
3566
3726
|
blocking: isSuppressed ? false : deriveBlocking(rule),
|
|
3567
3727
|
suppressed: isSuppressed,
|
|
3568
|
-
// New fields from contract integration
|
|
3728
|
+
// New fields from contract integration
|
|
3569
3729
|
suppressionState: isSuppressed ? "suppressed" : "active",
|
|
3570
3730
|
matcherType: cf.matcherType,
|
|
3571
3731
|
// releaseId: 'pre-attestation' — not set on Finding until Phase C wires
|
|
@@ -3622,6 +3782,7 @@ function runProRulesWithDispatch(rules, files, policy, cliVersion, table, manife
|
|
|
3622
3782
|
}
|
|
3623
3783
|
|
|
3624
3784
|
export {
|
|
3785
|
+
goLink,
|
|
3625
3786
|
logger,
|
|
3626
3787
|
getFindingKey,
|
|
3627
3788
|
redactFindingsEvidence,
|
package/dist/cli-facts.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.8.0",
|
|
3
3
|
"packageName": "@agenticcli/shipguard",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"licenseDisplay": "ELv2",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"postgresql.auth.trust-auth-method"
|
|
84
84
|
],
|
|
85
85
|
"bundledCorpusRuleCount": 30,
|
|
86
|
-
"corpusVersion":
|
|
87
|
-
"bundleContentHash": "sha256:
|
|
86
|
+
"corpusVersion": 19,
|
|
87
|
+
"bundleContentHash": "sha256:1e274f5f8176c4ad8566703a67b110d038b528942c26c25c2b7299367bc8ffa8",
|
|
88
88
|
"offlineRuleCount": 60,
|
|
89
89
|
"jsonSchemaFields": [
|
|
90
90
|
"findings",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"coverageChanged",
|
|
112
112
|
"scanIdReused"
|
|
113
113
|
],
|
|
114
|
-
"schemaVersion": "0.
|
|
114
|
+
"schemaVersion": "0.8",
|
|
115
115
|
"degradeCodes": [
|
|
116
116
|
"FILE_TOO_LARGE",
|
|
117
117
|
"OUTPUT_TRUNCATED",
|
|
@@ -142,5 +142,5 @@
|
|
|
142
142
|
],
|
|
143
143
|
"installSnippet": "npx @agenticcli/shipguard scan --changed --strict --json",
|
|
144
144
|
"re2Engine": true,
|
|
145
|
-
"generatedAt": "2026-10-
|
|
145
|
+
"generatedAt": "2026-10-21T08:40:16.734Z"
|
|
146
146
|
}
|