@profullstack/threatcrush 0.13.55 → 0.13.56

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 CHANGED
@@ -182,7 +182,9 @@ threatcrush findings show 3f2a9c1d
182
182
  threatcrush findings ack|fix|fp|ignore|reopen 3f2a9c1d 7b1e… --note "why"
183
183
  ```
184
184
 
185
- `--no-upload` (or `THREATCRUSH_UPLOAD=0`) keeps a run local. A repo is named by
185
+ In CI, set `THREATCRUSH_API_KEY` to a `tc_agent_` key with write and runs
186
+ upload into that key's org with no login (workflow example in
187
+ docs/SCANNING.md). `--no-upload` (or `THREATCRUSH_UPLOAD=0`) keeps a run local. A repo is named by
186
188
  its origin remote (credentials stripped); URL targets lose their query string.
187
189
 
188
190
  ### Usage counts
package/dist/index.js CHANGED
@@ -50251,7 +50251,8 @@ async function uploadResult(result, opts) {
50251
50251
  const say = (line2) => (opts.machineReadable ? process.stderr : process.stdout).write(`${line2}
50252
50252
  `);
50253
50253
  if (uploadDisabled(opts.upload, opts.env)) return { uploaded: false, reason: "disabled" };
50254
- if (!hasSession()) {
50254
+ const apiKey = (opts.env ?? process.env).THREATCRUSH_API_KEY?.trim();
50255
+ if (!apiKey && !hasSession()) {
50255
50256
  if (!opts.machineReadable && process.stdout.isTTY) {
50256
50257
  say(source_default.dim(` Sign in with ${source_default.white("threatcrush login")} to track these findings in the cloud and triage them anywhere.
50257
50258
  `));
@@ -50259,31 +50260,33 @@ async function uploadResult(result, opts) {
50259
50260
  return { uploaded: false, reason: "signed-out" };
50260
50261
  }
50261
50262
  const cfg = readCliConfig();
50262
- if (!cfg.current_org_id) {
50263
+ if (!apiKey && !cfg.current_org_id) {
50263
50264
  say(source_default.yellow(` Not saved to the cloud: no current org. Pick one with ${source_default.white("threatcrush orgs use <slug>")}.
50264
50265
  `));
50265
50266
  return { uploaded: false, reason: "no-org" };
50266
50267
  }
50267
50268
  try {
50268
- const res = await cloudFetch(`/api/orgs/${cfg.current_org_id}/scan-findings/report`, {
50269
- method: "POST",
50270
- timeoutMs: 3e4,
50271
- body: JSON.stringify({
50272
- source: opts.source,
50273
- target: opts.target,
50274
- kind: opts.kind,
50275
- scope: opts.scope ?? "",
50276
- worker_id: workerId(),
50277
- result: {
50278
- // ai-scan and pentest put the target URL in each finding's location:
50279
- // clean it like the target, or a ?key= in the URL reaches the cloud.
50280
- findings: result.findings.map((f) => f.location && /^https?:\/\//i.test(f.location) ? { ...f, location: cleanUrl(f.location) } : f),
50281
- severity_summary: result.severity_summary,
50282
- summary: result.summary,
50283
- error: result.error
50284
- }
50285
- })
50269
+ const body = JSON.stringify({
50270
+ source: opts.source,
50271
+ target: opts.target,
50272
+ kind: opts.kind,
50273
+ scope: opts.scope ?? "",
50274
+ worker_id: workerId(),
50275
+ result: {
50276
+ // ai-scan and pentest put the target URL in each finding's location:
50277
+ // clean it like the target, or a ?key= in the URL reaches the cloud.
50278
+ findings: result.findings.map((f) => f.location && /^https?:\/\//i.test(f.location) ? { ...f, location: cleanUrl(f.location) } : f),
50279
+ severity_summary: result.severity_summary,
50280
+ summary: result.summary,
50281
+ error: result.error
50282
+ }
50286
50283
  });
50284
+ const res = apiKey ? await fetch(`${apiUrl()}/api/v1/findings/report`, {
50285
+ method: "POST",
50286
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
50287
+ body,
50288
+ signal: AbortSignal.timeout(3e4)
50289
+ }) : await cloudFetch(`/api/orgs/${cfg.current_org_id}/scan-findings/report`, { method: "POST", timeoutMs: 3e4, body });
50287
50290
  const data = await res.json().catch(() => ({}));
50288
50291
  if (!res.ok || !data.sync) {
50289
50292
  say(source_default.yellow(` Not saved to the cloud: ${data.error || `HTTP ${res.status}`}.
@@ -50291,10 +50294,15 @@ async function uploadResult(result, opts) {
50291
50294
  return { uploaded: false, reason: "error" };
50292
50295
  }
50293
50296
  const s = data.sync;
50294
- const org = cfg.current_org_slug || "your org";
50295
50297
  const parts = [`${s.new} new`, `${s.seen + s.reopened} still open${s.reopened ? ` (${s.reopened} back after a fix)` : ""}`, `${s.fixed} fixed`];
50296
- say(source_default.cyan(` \u2601 Saved to ${org}: ${parts.join(" \xB7 ")}. Triage with ${source_default.white("threatcrush findings")} or on threatcrush.com/org/${org}/findings
50298
+ if (apiKey) {
50299
+ say(source_default.cyan(` \u2601 Saved to the API key's org: ${parts.join(" \xB7 ")}. Triage on threatcrush.com (Findings).
50297
50300
  `));
50301
+ } else {
50302
+ const org = cfg.current_org_slug || "your org";
50303
+ say(source_default.cyan(` \u2601 Saved to ${org}: ${parts.join(" \xB7 ")}. Triage with ${source_default.white("threatcrush findings")} or on threatcrush.com/org/${org}/findings
50304
+ `));
50305
+ }
50298
50306
  return { uploaded: true, sync: s, propertyName: data.property_name };
50299
50307
  } catch (err) {
50300
50308
  say(source_default.yellow(` Not saved to the cloud: ${err.message}.
@@ -50381,7 +50389,7 @@ async function findingsListCommand(opts) {
50381
50389
  for (const f of data.findings) {
50382
50390
  const sev = (SEV_COLOR[f.severity] ?? source_default.white)(f.severity.toUpperCase().padEnd(8));
50383
50391
  console.log(` ${source_default.gray(short(f.id))} ${sev} ${source_default.dim((STATUS_LABEL[f.status] ?? f.status).padEnd(7))} ${f.message}`);
50384
- console.log(source_default.dim(` ${f.source} \xB7 ${f.properties?.name ?? "?"}${f.location ? ` \xB7 ${f.location}` : ""} \xB7 seen ${f.times_seen}x, last ${day(f.last_seen_at)}`));
50392
+ console.log(source_default.dim(` ${f.source} \xB7 ${f.properties?.name ?? "?"}${f.location && f.location !== f.properties?.target ? ` \xB7 ${f.location}` : ""} \xB7 seen ${f.times_seen}x, last ${day(f.last_seen_at)}`));
50385
50393
  }
50386
50394
  if (data.total > data.findings.length) console.log(source_default.dim(`
50387
50395
  ${data.findings.length} of ${data.total} shown; --limit for more.`));