@debugbundle/cli 1.19.1 → 1.19.3

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.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/dist/main.cjs +95 -35
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @debugbundle/cli
2
2
 
3
+ ## Cloud cache safety in 1.19.3
4
+
5
+ Upgrade to 1.19.3 for incident-ID validation before cloud requests and cache writes.
6
+ Unsafe IDs return `invalid_incident_id`; UUIDs and existing opaque IDs remain supported.
7
+ Cloud cache reads, writes and retention reject symbolic links; writes use guarded
8
+ atomic replacement. This corrects a path traversal present in earlier clients.
9
+
10
+
11
+ ## Installation guidance in 1.19.2
12
+
13
+ Prefer one project per system across service repositories, reuse existing connections, and keep separate projects for different access or privacy policies. Inspect existing projects before first-time connect; name matching does not infer system membership.
14
+
3
15
  ## Local correlation safety in 1.19.1
4
16
 
5
17
  Trace correlation crosses services only within the same project and environment.
package/dist/main.cjs CHANGED
@@ -18198,7 +18198,7 @@ var require_snapshot_recorder = __commonJS({
18198
18198
  "../../node_modules/.pnpm/undici@8.12.3/node_modules/undici/lib/mock/snapshot-recorder.js"(exports2, module2) {
18199
18199
  "use strict";
18200
18200
  var { writeFile, readFile, mkdir: mkdir5 } = require("node:fs/promises");
18201
- var { dirname: dirname9, resolve: resolve5 } = require("node:path");
18201
+ var { dirname: dirname10, resolve: resolve5 } = require("node:path");
18202
18202
  var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = require("node:timers");
18203
18203
  var { InvalidArgumentError, UndiciError } = require_errors();
18204
18204
  var { setHeader } = require_util();
@@ -18445,7 +18445,7 @@ var require_snapshot_recorder = __commonJS({
18445
18445
  throw new InvalidArgumentError("Snapshot path is required");
18446
18446
  }
18447
18447
  const resolvedPath = resolve5(path);
18448
- await mkdir5(dirname9(resolvedPath), { recursive: true });
18448
+ await mkdir5(dirname10(resolvedPath), { recursive: true });
18449
18449
  const data = Array.from(this.#snapshots.entries()).map(([hash3, snapshot]) => ({
18450
18450
  hash: hash3,
18451
18451
  snapshot
@@ -54914,6 +54914,12 @@ var RetrievalApiError = class extends Error {
54914
54914
  this.code = code;
54915
54915
  }
54916
54916
  };
54917
+ var IncidentIdSchema = external_exports.string().max(255).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/);
54918
+ function parseIncidentId(value) {
54919
+ const parsed = IncidentIdSchema.safeParse(value);
54920
+ if (!parsed.success) throw new RetrievalApiError(400, "invalid_incident_id");
54921
+ return parsed.data;
54922
+ }
54917
54923
  function parseApiError(status, body) {
54918
54924
  const parsed = ApiErrorResponseSchema.safeParse(body);
54919
54925
  if (!parsed.success) {
@@ -55017,7 +55023,7 @@ function createRetrievalApi(client) {
55017
55023
  const parsed = await expectParsed(
55018
55024
  client.request({
55019
55025
  method: "GET",
55020
- path: `/v1/incidents/${input3.incidentId}`,
55026
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}`,
55021
55027
  bearerToken: input3.bearerToken
55022
55028
  }),
55023
55029
  IncidentResponseSchema
@@ -55028,7 +55034,7 @@ function createRetrievalApi(client) {
55028
55034
  const parsed = await expectParsed(
55029
55035
  client.request({
55030
55036
  method: "GET",
55031
- path: `/v1/incidents/${input3.incidentId}/context`,
55037
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/context`,
55032
55038
  bearerToken: input3.bearerToken
55033
55039
  }),
55034
55040
  IncidentContextSchema
@@ -55039,7 +55045,7 @@ function createRetrievalApi(client) {
55039
55045
  const parsed = await expectMutation(
55040
55046
  client.request({
55041
55047
  method: "POST",
55042
- path: `/v1/incidents/${input3.incidentId}/resolve`,
55048
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/resolve`,
55043
55049
  bearerToken: input3.bearerToken
55044
55050
  }),
55045
55051
  IncidentResponseSchema
@@ -55064,7 +55070,7 @@ function createRetrievalApi(client) {
55064
55070
  const parsed = await expectMutation(
55065
55071
  client.request({
55066
55072
  method: "POST",
55067
- path: `/v1/incidents/${input3.incidentId}/reopen`,
55073
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/reopen`,
55068
55074
  bearerToken: input3.bearerToken
55069
55075
  }),
55070
55076
  IncidentResponseSchema
@@ -55089,7 +55095,7 @@ function createRetrievalApi(client) {
55089
55095
  const bundle = await expectParsed(
55090
55096
  client.request({
55091
55097
  method: "GET",
55092
- path: `/v1/incidents/${input3.incidentId}/bundle`,
55098
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/bundle`,
55093
55099
  bearerToken: input3.bearerToken
55094
55100
  }),
55095
55101
  BundleResponseSchema
@@ -55124,7 +55130,7 @@ function createRetrievalApi(client) {
55124
55130
  const reproduction = await expectParsed(
55125
55131
  client.request({
55126
55132
  method: "GET",
55127
- path: `/v1/incidents/${input3.incidentId}/reproduction`,
55133
+ path: `/v1/incidents/${encodeURIComponent(parseIncidentId(input3.incidentId))}/reproduction`,
55128
55134
  bearerToken: input3.bearerToken
55129
55135
  }),
55130
55136
  ReproductionResponseSchema
@@ -58358,7 +58364,7 @@ function buildAgentInterfaceGuidance() {
58358
58364
  "",
58359
58365
  "### Project and service scope",
58360
58366
  "",
58361
- "- A project is the system investigated together; services are its applications/processes, with their repository context and environments. Site, App and API can belong to one project without another grouping layer. Inspect the complete service-definition catalogue before choosing a repository; keep environment-specific service_id distinct from service_definition_id.",
58367
+ "- Prefer one project per system; services are its applications/processes (Site, App, API, Worker), even across repositories. Reuse the system's existing project; preserve an existing connection and SDK input names. Keep separate projects when access or privacy policies require separation. Before first-time connect, inspect existing projects: connect matches the profile name, not system membership. Inspect the complete service-definition catalogue for repository context; distinguish environment-specific service_id from logical service_definition_id.",
58362
58368
  "- For authorised consolidation, use project merge preview, review blockers and suggested_service_mappings, then preview explicit mappings. Apply the checked plan_digest with a stable idempotency_key. After a timeout, get status by that key before retrying; use verify/resume for a committed but unverified result. Access/settings conflicts require ordinary authorised reconciliation; there is no force flag.",
58363
58369
  "- Use the receipt's secret-free adoption manifest and one explicit authorised workspace root. The local adopt preview/apply commands preserve existing SDK tokens and runtime input names; application, relay, CI and deployment edits remain language-aware repository work. Receipt metadata is a snapshot: inspect the current catalogue and run repository checks before declaring local adoption complete. DebugBundle approval does not authorise another product's edits, SDK updates, deployment or canary.",
58364
58370
  "- Report server consolidation, local configuration, repository checks and deployed-runtime verification separately. For retained project links, project list --project-id resolves the original view with current canonical access. Analytics unique counts remain scoped by origin; retain the returned coverage explanation.",
@@ -62431,6 +62437,7 @@ function safeCachedArtifact(value) {
62431
62437
  return result.value;
62432
62438
  }
62433
62439
  async function cacheCloudBundleArtifact(input3, dependencies) {
62440
+ parseIncidentId(input3.incidentId);
62434
62441
  await pruneExpiredCloudArtifacts(dependencies);
62435
62442
  const bundle = safeCachedArtifact(attachSourceToPayload(input3.bundle, "cloud"));
62436
62443
  await persistCloudArtifact(
@@ -62442,6 +62449,7 @@ async function cacheCloudBundleArtifact(input3, dependencies) {
62442
62449
  return bundle;
62443
62450
  }
62444
62451
  async function cacheCloudReproductionArtifact(input3, dependencies) {
62452
+ parseIncidentId(input3.incidentId);
62445
62453
  await pruneExpiredCloudArtifacts(dependencies);
62446
62454
  const reproduction = safeCachedArtifact(attachSourceToPayload(input3.reproduction, "cloud"));
62447
62455
  await persistCloudArtifact(
@@ -62453,15 +62461,24 @@ async function cacheCloudReproductionArtifact(input3, dependencies) {
62453
62461
  return reproduction;
62454
62462
  }
62455
62463
  async function syncCloudIncidentCacheStatus(input3, dependencies) {
62464
+ parseIncidentId(input3.incidentId);
62456
62465
  await pruneExpiredCloudArtifacts(dependencies);
62457
62466
  await Promise.all([
62458
62467
  updateCachedArtifactStatus(
62459
- (0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_BUNDLE_DIRECTORY_PATH, `${input3.incidentId}.bundle.json`),
62468
+ (0, import_node_path11.join)(
62469
+ getWorkspaceRoot2(dependencies),
62470
+ CLOUD_BUNDLE_DIRECTORY_PATH,
62471
+ `${input3.incidentId}.bundle.json`
62472
+ ),
62460
62473
  input3,
62461
62474
  dependencies
62462
62475
  ),
62463
62476
  updateCachedArtifactStatus(
62464
- (0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_REPRODUCTION_DIRECTORY_PATH, `${input3.incidentId}.reproduction.json`),
62477
+ (0, import_node_path11.join)(
62478
+ getWorkspaceRoot2(dependencies),
62479
+ CLOUD_REPRODUCTION_DIRECTORY_PATH,
62480
+ `${input3.incidentId}.reproduction.json`
62481
+ ),
62465
62482
  input3,
62466
62483
  dependencies
62467
62484
  )
@@ -62469,13 +62486,16 @@ async function syncCloudIncidentCacheStatus(input3, dependencies) {
62469
62486
  }
62470
62487
  async function syncCloudIncidentMutationCache(incident, dependencies) {
62471
62488
  try {
62472
- await syncCloudIncidentCacheStatus({
62473
- incidentId: String(incident["incident_id"]),
62474
- incident: {
62475
- ...typeof incident["status"] === "string" ? { status: incident["status"] } : {},
62476
- resolved_at: incident["status"] === "resolved" && typeof incident["resolved_at"] === "string" ? incident["resolved_at"] : null
62477
- }
62478
- }, dependencies);
62489
+ await syncCloudIncidentCacheStatus(
62490
+ {
62491
+ incidentId: String(incident["incident_id"]),
62492
+ incident: {
62493
+ ...typeof incident["status"] === "string" ? { status: incident["status"] } : {},
62494
+ resolved_at: incident["status"] === "resolved" && typeof incident["resolved_at"] === "string" ? incident["resolved_at"] : null
62495
+ }
62496
+ },
62497
+ dependencies
62498
+ );
62479
62499
  } catch {
62480
62500
  incident["cache_warning"] = "cloud_cache_update_unavailable";
62481
62501
  }
@@ -62489,7 +62509,12 @@ async function pruneExpiredCloudArtifacts(dependencies) {
62489
62509
  async function pruneCloudArtifactCache(input3, dependencies) {
62490
62510
  const now = (dependencies?.now ?? (() => /* @__PURE__ */ new Date()))().getTime();
62491
62511
  const [bundleDirectoryCounts, reproductionDirectoryCounts] = await Promise.all([
62492
- pruneExpiredArtifactsInDirectory((0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_BUNDLE_DIRECTORY_PATH), now, input3.olderThanMs, dependencies),
62512
+ pruneExpiredArtifactsInDirectory(
62513
+ (0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_BUNDLE_DIRECTORY_PATH),
62514
+ now,
62515
+ input3.olderThanMs,
62516
+ dependencies
62517
+ ),
62493
62518
  pruneExpiredArtifactsInDirectory(
62494
62519
  (0, import_node_path11.join)(getWorkspaceRoot2(dependencies), CLOUD_REPRODUCTION_DIRECTORY_PATH),
62495
62520
  now,
@@ -62503,9 +62528,10 @@ async function pruneCloudArtifactCache(input3, dependencies) {
62503
62528
  };
62504
62529
  }
62505
62530
  async function pruneExpiredArtifactsInDirectory(directoryPath, now, olderThanMs, dependencies) {
62531
+ await checkedCachePath(directoryPath, dependencies);
62506
62532
  const readdir = dependencies?.readdir ?? import_promises10.readdir;
62507
62533
  const rm = dependencies?.rm ?? import_promises10.rm;
62508
- const stat = dependencies?.stat ?? import_promises10.stat;
62534
+ const stat = dependencies?.stat ?? import_promises10.lstat;
62509
62535
  let fileNames;
62510
62536
  try {
62511
62537
  fileNames = await readdir(directoryPath);
@@ -62520,7 +62546,10 @@ async function pruneExpiredArtifactsInDirectory(directoryPath, now, olderThanMs,
62520
62546
  if (fileName === "reproductions") {
62521
62547
  return { removed: 0, retained: 0 };
62522
62548
  }
62523
- const filePath = (0, import_node_path11.join)(directoryPath, fileName);
62549
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*\.(bundle|reproduction)\.json$/.test(fileName)) {
62550
+ return { removed: 0, retained: 0 };
62551
+ }
62552
+ const filePath = await checkedCachePath((0, import_node_path11.join)(directoryPath, fileName), dependencies);
62524
62553
  let fileStats;
62525
62554
  try {
62526
62555
  fileStats = await stat(filePath);
@@ -62534,6 +62563,7 @@ async function pruneExpiredArtifactsInDirectory(directoryPath, now, olderThanMs,
62534
62563
  if (now - lastAccessedAt <= olderThanMs) {
62535
62564
  return { removed: 0, retained: 1 };
62536
62565
  }
62566
+ await checkedCachePath(filePath, dependencies);
62537
62567
  await rm(filePath, { force: true });
62538
62568
  return { removed: 1, retained: 0 };
62539
62569
  })
@@ -62547,11 +62577,15 @@ async function pruneExpiredArtifactsInDirectory(directoryPath, now, olderThanMs,
62547
62577
  );
62548
62578
  }
62549
62579
  async function updateCachedArtifactStatus(filePath, input3, dependencies) {
62550
- const readFile = dependencies?.readFile ?? import_promises10.readFile;
62551
- const writeFile = dependencies?.writeFile ?? import_promises10.writeFile;
62580
+ await checkedCachePath(filePath, dependencies);
62581
+ let raw;
62552
62582
  let payload;
62553
62583
  try {
62554
- const raw = await readFile(filePath, "utf8");
62584
+ raw = dependencies?.readFile ? await dependencies.readFile(filePath, "utf8") : await readManaged(
62585
+ getWorkspaceRoot2(dependencies),
62586
+ (0, import_node_path11.relative)(getWorkspaceRoot2(dependencies), filePath)
62587
+ );
62588
+ if (raw === void 0) return;
62555
62589
  if (Buffer.byteLength(raw, "utf8") > 512 * 1024) return;
62556
62590
  payload = JSON.parse(raw);
62557
62591
  } catch (error62) {
@@ -62561,8 +62595,13 @@ async function updateCachedArtifactStatus(filePath, input3, dependencies) {
62561
62595
  throw error62;
62562
62596
  }
62563
62597
  const nextPayload = applyIncidentStatusToPayload(payload, input3.incidentId, input3.incident);
62564
- await writeFile(filePath, `${JSON.stringify(safeCachedArtifact(attachSourceToPayload(nextPayload, "cloud")), null, 2)}
62565
- `, "utf8");
62598
+ await writeCachedFile(
62599
+ filePath,
62600
+ `${JSON.stringify(safeCachedArtifact(attachSourceToPayload(nextPayload, "cloud")), null, 2)}
62601
+ `,
62602
+ raw,
62603
+ dependencies
62604
+ );
62566
62605
  }
62567
62606
  function applyIncidentStatusToPayload(payload, incidentId, incident) {
62568
62607
  if (!isRecord2(payload)) {
@@ -62577,16 +62616,37 @@ function applyIncidentStatusToPayload(payload, incidentId, incident) {
62577
62616
  nextPayload["resolved_at"] = incident.resolved_at ?? null;
62578
62617
  }
62579
62618
  if (isRecord2(payload["incident"])) {
62580
- nextPayload["incident"] = applyIncidentStatusToPayload(payload["incident"], incidentId, incident);
62619
+ nextPayload["incident"] = applyIncidentStatusToPayload(
62620
+ payload["incident"],
62621
+ incidentId,
62622
+ incident
62623
+ );
62581
62624
  }
62582
62625
  return nextPayload;
62583
62626
  }
62584
62627
  async function persistCloudArtifact(directoryPath, fileName, payload, dependencies) {
62585
- const mkdir5 = dependencies?.mkdir ?? import_promises10.mkdir;
62586
- const writeFile = dependencies?.writeFile ?? import_promises10.writeFile;
62587
- await mkdir5(directoryPath, { recursive: true });
62588
- await writeFile((0, import_node_path11.join)(directoryPath, fileName), `${JSON.stringify(payload, null, 2)}
62589
- `, "utf8");
62628
+ if ((0, import_node_path11.basename)(fileName) !== fileName || fileName.includes("\\"))
62629
+ throw new Error("Invalid cache filename.");
62630
+ const filePath = await checkedCachePath((0, import_node_path11.join)(directoryPath, fileName), dependencies);
62631
+ const root = getWorkspaceRoot2(dependencies);
62632
+ const previous = await readManaged(root, (0, import_node_path11.relative)(root, filePath));
62633
+ await writeCachedFile(filePath, `${JSON.stringify(payload, null, 2)}
62634
+ `, previous, dependencies);
62635
+ }
62636
+ async function checkedCachePath(filePath, dependencies) {
62637
+ const root = getWorkspaceRoot2(dependencies);
62638
+ return safePath(root, (0, import_node_path11.relative)(root, filePath));
62639
+ }
62640
+ async function writeCachedFile(filePath, contents, expected, dependencies) {
62641
+ await checkedCachePath(filePath, dependencies);
62642
+ if (dependencies?.writeFile) {
62643
+ await dependencies.mkdir?.((0, import_node_path11.dirname)(filePath), { recursive: true });
62644
+ await checkedCachePath(filePath, dependencies);
62645
+ await dependencies.writeFile(filePath, contents, "utf8");
62646
+ return;
62647
+ }
62648
+ const root = getWorkspaceRoot2(dependencies);
62649
+ await writeManaged(root, (0, import_node_path11.relative)(root, filePath), contents, expected);
62590
62650
  }
62591
62651
 
62592
62652
  // src/clean-command.ts
@@ -71381,10 +71441,10 @@ function manifestFor(input3) {
71381
71441
  fail("adoption_manifest_stale");
71382
71442
  return { operation, manifest };
71383
71443
  }
71384
- async function hierarchy(root, relative6) {
71444
+ async function hierarchy(root, relative7) {
71385
71445
  if ((0, import_node_path24.resolve)(root) !== root || await (0, import_promises21.realpath)(root) !== root) fail("adoption_unsafe_path");
71386
71446
  try {
71387
- await safePath(root, relative6);
71447
+ await safePath(root, relative7);
71388
71448
  } catch {
71389
71449
  fail("adoption_unsafe_path");
71390
71450
  }
@@ -82344,7 +82404,7 @@ async function handleCaptureRuleCommand2(parsedArgv, dependencies) {
82344
82404
  // package.json
82345
82405
  var package_default = {
82346
82406
  name: "@debugbundle/cli",
82347
- version: "1.19.1",
82407
+ version: "1.19.3",
82348
82408
  private: false,
82349
82409
  description: "Command-line interface for DebugBundle",
82350
82410
  license: "Apache-2.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@debugbundle/cli",
3
- "version": "1.19.1",
3
+ "version": "1.19.3",
4
4
  "private": false,
5
5
  "description": "Command-line interface for DebugBundle",
6
6
  "license": "Apache-2.0",