@agenticcli/shipguard 0.6.0 → 0.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/README.md +9 -1
- package/dist/checksum-manifest.json +5 -5
- package/dist/{chunk-KYVEU6H4.js → chunk-A63X4LUJ.js} +39 -18
- package/dist/cli-facts.json +5 -5
- package/dist/cli.js +486 -148
- package/dist/{config-generator-2AC37XZ2.js → config-generator-2BVUZGEU.js} +1 -0
- package/dist/{pro-scanner-3DY7KU5C.js → pro-scanner-QDOFUEXZ.js} +1 -1
- package/package.json +4 -3
- package/rules/free-bundle.json +30 -10
package/README.md
CHANGED
|
@@ -72,7 +72,15 @@ when you want that truthful verdict to actually stop something.
|
|
|
72
72
|
|
|
73
73
|
## Telemetry
|
|
74
74
|
|
|
75
|
-
ShipGuard
|
|
75
|
+
Published ShipGuard builds send one pseudonymous usage ping after each scan: CLI version, verdict (safe / review / blocked / error), a scan-duration bucket, a CI flag, the build type, and a random install id (a pseudonym stored in `~/.config/shipguard/telemetry.json`; not created or sent in CI, never linked to an account). Never file contents, paths, repo names, branches or commits, or user identity. `shipguard telemetry status` shows what is set, `shipguard telemetry reset` forgets the id (earlier pings can be deleted on request), `SHIPGUARD_TELEMETRY_DEBUG=1` prints the exact payload without sending. Builds from a source checkout never send anything.
|
|
76
|
+
|
|
77
|
+
Before the first ping on a machine, ShipGuard prints a one-line notice to stderr (in every mode, including `--json` and CI, so stdout stays clean). Turn pings off any of these ways:
|
|
78
|
+
|
|
79
|
+
- `SHIPGUARD_TELEMETRY=0` or `DO_NOT_TRACK=1` in the environment (wins over everything)
|
|
80
|
+
- `shipguard telemetry disable` (saved per user; `enable` turns it back on, `status` shows the state and why)
|
|
81
|
+
- `telemetry: { enabled: false }` in `shipguard.policy.yml` or `.shipguard.yml` (per project)
|
|
82
|
+
|
|
83
|
+
To see exactly what would be sent without sending it: `SHIPGUARD_TELEMETRY_DEBUG=1 shipguard scan`.
|
|
76
84
|
|
|
77
85
|
Details: [agenticcli.dev/docs#telemetry](https://agenticcli.dev/docs#telemetry)
|
|
78
86
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"secrets": "
|
|
3
|
-
"auth": "
|
|
4
|
-
"database": "
|
|
5
|
-
"deployment": "
|
|
6
|
-
"payments": "
|
|
2
|
+
"secrets": "8ab3281c5b2454290a3399e482cf8afe0f05794ab60ef26c5c2b9942b4fb1b1b",
|
|
3
|
+
"auth": "8ab3281c5b2454290a3399e482cf8afe0f05794ab60ef26c5c2b9942b4fb1b1b",
|
|
4
|
+
"database": "8ab3281c5b2454290a3399e482cf8afe0f05794ab60ef26c5c2b9942b4fb1b1b",
|
|
5
|
+
"deployment": "8ab3281c5b2454290a3399e482cf8afe0f05794ab60ef26c5c2b9942b4fb1b1b",
|
|
6
|
+
"payments": "8ab3281c5b2454290a3399e482cf8afe0f05794ab60ef26c5c2b9942b4fb1b1b"
|
|
7
7
|
}
|
|
@@ -18,12 +18,10 @@ import * as os from "os";
|
|
|
18
18
|
// src/core/auth.ts
|
|
19
19
|
import {
|
|
20
20
|
readFileSync,
|
|
21
|
-
writeFileSync,
|
|
22
|
-
mkdirSync,
|
|
21
|
+
writeFileSync as writeFileSync2,
|
|
23
22
|
rmSync,
|
|
24
23
|
existsSync,
|
|
25
|
-
statSync
|
|
26
|
-
chmodSync
|
|
24
|
+
statSync as statSync2
|
|
27
25
|
} from "fs";
|
|
28
26
|
import { join, dirname } from "path";
|
|
29
27
|
import { homedir } from "os";
|
|
@@ -59,17 +57,30 @@ function assertTrustedApiUrl(url) {
|
|
|
59
57
|
);
|
|
60
58
|
}
|
|
61
59
|
|
|
60
|
+
// src/utils/secure-fs.ts
|
|
61
|
+
import { chmodSync, mkdirSync, statSync, writeFileSync } from "fs";
|
|
62
|
+
var SECURE_DIR_MODE = 448;
|
|
63
|
+
var SECURE_FILE_MODE = 384;
|
|
64
|
+
var isPosix = process.platform !== "win32";
|
|
65
|
+
function ensureSecureDir(dir) {
|
|
66
|
+
mkdirSync(dir, { recursive: true, mode: SECURE_DIR_MODE });
|
|
67
|
+
if (isPosix && statSync(dir).uid === process.getuid?.()) chmodSync(dir, SECURE_DIR_MODE);
|
|
68
|
+
}
|
|
69
|
+
function writeSecureFileSync(file, data) {
|
|
70
|
+
writeFileSync(file, data, { mode: SECURE_FILE_MODE });
|
|
71
|
+
if (isPosix) chmodSync(file, SECURE_FILE_MODE);
|
|
72
|
+
}
|
|
73
|
+
|
|
62
74
|
// src/core/auth.ts
|
|
63
|
-
var DIR_MODE = 448;
|
|
64
75
|
var FILE_MODE = 384;
|
|
65
76
|
var UNSAFE_PERM_MASK = 63;
|
|
66
|
-
var
|
|
77
|
+
var isPosix2 = process.platform !== "win32";
|
|
67
78
|
function getCredentialsPath() {
|
|
68
79
|
return join(homedir(), ".config", "shipguard", "credentials.json");
|
|
69
80
|
}
|
|
70
81
|
function hasUnsafePermissions(path3) {
|
|
71
|
-
if (!
|
|
72
|
-
const mode =
|
|
82
|
+
if (!isPosix2) return false;
|
|
83
|
+
const mode = statSync2(path3).mode & 511;
|
|
73
84
|
return (mode & UNSAFE_PERM_MASK) !== 0;
|
|
74
85
|
}
|
|
75
86
|
function loadCredentials() {
|
|
@@ -91,17 +102,15 @@ function loadCredentials() {
|
|
|
91
102
|
async function saveCredentials(creds) {
|
|
92
103
|
const p = getCredentialsPath();
|
|
93
104
|
const dir = dirname(p);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
writeFileSync(p, JSON.stringify(creds, null, 2), { mode: FILE_MODE });
|
|
97
|
-
if (isPosix) chmodSync(p, FILE_MODE);
|
|
105
|
+
ensureSecureDir(dir);
|
|
106
|
+
writeSecureFileSync(p, JSON.stringify(creds, null, 2));
|
|
98
107
|
}
|
|
99
108
|
function clearCredentials() {
|
|
100
109
|
const p = getCredentialsPath();
|
|
101
110
|
if (!existsSync(p)) return;
|
|
102
111
|
try {
|
|
103
|
-
const size =
|
|
104
|
-
if (size > 0)
|
|
112
|
+
const size = statSync2(p).size;
|
|
113
|
+
if (size > 0) writeFileSync2(p, Buffer.alloc(size, 0), { mode: FILE_MODE });
|
|
105
114
|
} catch {
|
|
106
115
|
}
|
|
107
116
|
rmSync(p, { force: true });
|
|
@@ -365,7 +374,7 @@ function acquireFloorLock(lockPath, timeoutMs = 5e3) {
|
|
|
365
374
|
const deadline = Date.now() + timeoutMs;
|
|
366
375
|
while (Date.now() < deadline) {
|
|
367
376
|
try {
|
|
368
|
-
const fd = fs.openSync(lockPath, "wx");
|
|
377
|
+
const fd = fs.openSync(lockPath, "wx", SECURE_FILE_MODE);
|
|
369
378
|
fs.closeSync(fd);
|
|
370
379
|
return () => {
|
|
371
380
|
try {
|
|
@@ -387,6 +396,7 @@ function atomicAcceptFloor(floorPath, incoming) {
|
|
|
387
396
|
const lockPath = `${floorPath}.lock`;
|
|
388
397
|
const dir = path.dirname(floorPath);
|
|
389
398
|
const tmpPath = path.join(dir, `.floor-tmp-${process.pid}-${Date.now()}.json`);
|
|
399
|
+
ensureSecureDir(dir);
|
|
390
400
|
const releaseLock = acquireFloorLock(lockPath);
|
|
391
401
|
try {
|
|
392
402
|
let lockedFloor = null;
|
|
@@ -439,7 +449,7 @@ function atomicAcceptFloor(floorPath, incoming) {
|
|
|
439
449
|
return { accepted: true, wrote: false };
|
|
440
450
|
}
|
|
441
451
|
}
|
|
442
|
-
|
|
452
|
+
writeSecureFileSync(tmpPath, JSON.stringify(incoming));
|
|
443
453
|
const tmpFd = fs.openSync(tmpPath, "r+");
|
|
444
454
|
try {
|
|
445
455
|
fs.fsyncSync(tmpFd);
|
|
@@ -2467,6 +2477,15 @@ function findLine(content, pattern) {
|
|
|
2467
2477
|
}
|
|
2468
2478
|
return void 0;
|
|
2469
2479
|
}
|
|
2480
|
+
function findMatchStartLine(content, pattern) {
|
|
2481
|
+
const m = pattern.exec(content);
|
|
2482
|
+
if (!m) return void 0;
|
|
2483
|
+
let line = 1;
|
|
2484
|
+
for (let i = 0; i < m.index; i++) {
|
|
2485
|
+
if (content.charCodeAt(i) === 10) line++;
|
|
2486
|
+
}
|
|
2487
|
+
return line;
|
|
2488
|
+
}
|
|
2470
2489
|
function findLineStr(content, literal) {
|
|
2471
2490
|
const lines = content.split("\n");
|
|
2472
2491
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -2479,7 +2498,7 @@ function checkNextConfig(file) {
|
|
|
2479
2498
|
const { content, relativePath } = file;
|
|
2480
2499
|
if (RE_CORS_NEXT_VALUE.test(content) || RE_CORS_NEXT_HEADER.test(content)) {
|
|
2481
2500
|
const matchedPattern = RE_CORS_NEXT_VALUE.test(content) ? RE_CORS_NEXT_VALUE : RE_CORS_NEXT_HEADER;
|
|
2482
|
-
const line =
|
|
2501
|
+
const line = findMatchStartLine(content, matchedPattern);
|
|
2483
2502
|
findings.push({
|
|
2484
2503
|
id: makeId("cors_wildcard"),
|
|
2485
2504
|
title: "Permissive CORS: Access-Control-Allow-Origin set to wildcard (*)",
|
|
@@ -2786,7 +2805,7 @@ function checkGeneralConfigs(file) {
|
|
|
2786
2805
|
const { content, relativePath } = file;
|
|
2787
2806
|
const corsRe = JSON_FAMILY_EXTENSIONS.has(extname(relativePath).toLowerCase()) ? RE_CONFIG_CORS_WILDCARD_JSON : RE_CONFIG_CORS_WILDCARD;
|
|
2788
2807
|
if (corsRe.test(content)) {
|
|
2789
|
-
const line =
|
|
2808
|
+
const line = findMatchStartLine(content, corsRe);
|
|
2790
2809
|
findings.push({
|
|
2791
2810
|
id: makeId("config_cors_wildcard_origin"),
|
|
2792
2811
|
title: `CORS origin wildcard (*) detected in ${relativePath}`,
|
|
@@ -3612,6 +3631,8 @@ export {
|
|
|
3612
3631
|
payments,
|
|
3613
3632
|
deploymentCheck,
|
|
3614
3633
|
assertTrustedApiUrl,
|
|
3634
|
+
ensureSecureDir,
|
|
3635
|
+
writeSecureFileSync,
|
|
3615
3636
|
loadCredentials,
|
|
3616
3637
|
saveCredentials,
|
|
3617
3638
|
clearCredentials,
|
package/dist/cli-facts.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.7.1",
|
|
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": 18,
|
|
87
|
+
"bundleContentHash": "sha256:fce96295cc50f6345ad4ddee6745710ba1671156b8e04702ef21793427d399cb",
|
|
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.7",
|
|
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-
|
|
145
|
+
"generatedAt": "2026-10-02T06:06:11.087Z"
|
|
146
146
|
}
|
package/dist/cli.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
databaseCheck,
|
|
8
8
|
deploymentCheck,
|
|
9
9
|
deriveBlocking,
|
|
10
|
+
ensureSecureDir,
|
|
10
11
|
getAuthToken,
|
|
11
12
|
getFindingKey,
|
|
12
13
|
isLineSuppressed,
|
|
@@ -20,8 +21,9 @@ import {
|
|
|
20
21
|
runProRulesWithDispatch,
|
|
21
22
|
saveCredentials,
|
|
22
23
|
secretsCheck,
|
|
23
|
-
validateBundleCompile
|
|
24
|
-
|
|
24
|
+
validateBundleCompile,
|
|
25
|
+
writeSecureFileSync
|
|
26
|
+
} from "./chunk-A63X4LUJ.js";
|
|
25
27
|
import {
|
|
26
28
|
DEFAULT_MAX_FILES,
|
|
27
29
|
DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
@@ -37,7 +39,7 @@ import {
|
|
|
37
39
|
} from "./chunk-MPQ42F54.js";
|
|
38
40
|
|
|
39
41
|
// src/cli.ts
|
|
40
|
-
import { Command as
|
|
42
|
+
import { Command as Command11, CommanderError } from "commander";
|
|
41
43
|
|
|
42
44
|
// src/commands/init.ts
|
|
43
45
|
import { Command } from "commander";
|
|
@@ -180,8 +182,8 @@ function initCommand() {
|
|
|
180
182
|
|
|
181
183
|
// src/commands/scan.ts
|
|
182
184
|
import { Command as Command2 } from "commander";
|
|
183
|
-
import { existsSync as
|
|
184
|
-
import { join as
|
|
185
|
+
import { existsSync as existsSync6 } from "fs";
|
|
186
|
+
import { join as join7, resolve as resolve4 } from "path";
|
|
185
187
|
|
|
186
188
|
// src/core/scanner.ts
|
|
187
189
|
import { readFile as readFile2, stat, realpath } from "fs/promises";
|
|
@@ -484,10 +486,10 @@ function getChangedFiles(dir) {
|
|
|
484
486
|
var free_bundle_default = {
|
|
485
487
|
schemaVersion: 1,
|
|
486
488
|
description: "Offline free rule bundle compiled from rule-corpus/*/rule.yaml where bundleEligible=true and enabled=true. Governed by rules.md \xA74/\xA75/\xA79. Generated by scripts/build-free-bundle.ts \u2014 never hand-edited.",
|
|
487
|
-
corpusVersion:
|
|
488
|
-
corpusHash: "sha256:
|
|
489
|
+
corpusVersion: 18,
|
|
490
|
+
corpusHash: "sha256:6762d562afaa997b54e3cfdc7169a749e40b48e7680d1dd7f796358dda735cfe",
|
|
489
491
|
ruleCount: 30,
|
|
490
|
-
contentHash: "sha256:
|
|
492
|
+
contentHash: "sha256:fce96295cc50f6345ad4ddee6745710ba1671156b8e04702ef21793427d399cb",
|
|
491
493
|
rules: [
|
|
492
494
|
{
|
|
493
495
|
id: "generic.auth.jwt-none-algorithm",
|
|
@@ -677,36 +679,56 @@ var free_bundle_default = {
|
|
|
677
679
|
severity: "high",
|
|
678
680
|
confidence: "MEDIUM",
|
|
679
681
|
action: "warn",
|
|
680
|
-
version:
|
|
682
|
+
version: 5,
|
|
681
683
|
status: "experimental",
|
|
682
684
|
cwe: [
|
|
683
|
-
"CWE-942"
|
|
685
|
+
"CWE-942",
|
|
686
|
+
"CWE-346"
|
|
684
687
|
],
|
|
685
688
|
owasp: [
|
|
686
689
|
"A05:2021"
|
|
687
690
|
],
|
|
688
691
|
matcher: {
|
|
689
692
|
type: "pattern",
|
|
690
|
-
fileGlob: "**/*.{ts,js,tsx,jsx,py,go,rb,java,yaml,yml,conf}",
|
|
693
|
+
fileGlob: "**/*.{ts,js,tsx,jsx,py,go,rb,java,yaml,yml,conf,json,jsonc,json5}",
|
|
691
694
|
patterns: [
|
|
692
695
|
`Access-Control-Allow-Origin['",:\\s]+[*]`,
|
|
693
696
|
`(setHeader|header|res\\.set)\\s*\\(\\s*['"]Access-Control-Allow-Origin['"]\\s*,\\s*['"][*]['"]`,
|
|
694
697
|
`cors\\s*\\(\\s*\\{\\s*origin\\s*:\\s*['"][*]['"]`,
|
|
695
|
-
`allow_origins\\s*=\\s*\\[\\s*['"][*]['"]
|
|
698
|
+
`allow_origins\\s*=\\s*\\[\\s*['"][*]['"]`,
|
|
699
|
+
`Access-Control-Allow-Origin['"]\\s{0,40},\\s{0,40}['"]?value['"]?\\s{0,40}:\\s{0,40}['"]\\*['"]`,
|
|
700
|
+
`['"]?value['"]?\\s{0,40}:\\s{0,40}['"]\\*['"]\\s{0,40},\\s{0,40}['"]?key['"]?\\s{0,40}:\\s{0,40}['"]Access-Control-Allow-Origin['"]`,
|
|
701
|
+
`\\b(?:cors|enableCors)\\s{0,10}\\(\\s{0,10}\\{[^{}(]{0,200}\\borigin['"]?\\s{0,10}:\\s{0,10}(?:true\\b|\\[[^\\[\\]]{0,100}['"]\\*['"])`,
|
|
702
|
+
`\\b[cC]ors(?:Options?|Config|Opts?)?['"]?\\s{0,10}[:=]\\s{0,10}\\{[^{}(]{0,120}\\borigin['"]?\\s{0,10}:\\s{0,10}(?:true\\b|\\[[^\\[\\]]{0,100}['"]\\*['"])`,
|
|
703
|
+
`\\bregister\\s{0,10}\\(\\s{0,10}(?:cors|fastifyCors|require\\s{0,10}\\(\\s{0,10}['"]@fastify/cors['"]\\s{0,10}\\))\\s{0,10},\\s{0,10}\\{[^{}(]{0,200}\\borigin['"]?\\s{0,10}:\\s{0,10}(?:true\\b|\\[[^\\[\\]]{0,100}['"]\\*['"])`,
|
|
704
|
+
`\\b(?:[Aa]llow[Oo]rigin|Cors)['"]?\\s{0,10}:\\s{0,10}['"]{1,2}\\*['"]{1,2}`,
|
|
705
|
+
`\\b[Aa]llow[Oo]rigins['"]?\\s{0,20}:\\s{0,20}(?:\\[[^\\[\\]]{0,200}['"]\\*['"]|-\\s{0,10}['"]\\*['"])`
|
|
696
706
|
],
|
|
697
707
|
antiPatterns: [
|
|
698
708
|
"\\btest\\b|\\bspec\\b|__fixtures__|__tests__",
|
|
699
|
-
"static|assets|cdn|fonts|images|public-api|intentional-wildcard"
|
|
709
|
+
"static|assets|cdn|fonts|images|public-api|intentional-wildcard",
|
|
710
|
+
"\\.(?:woff2?|ttf|otf|eot)\\b|font\\.css",
|
|
711
|
+
'[:,\\[]\\s{0,10}"[^"\\n]{0,300}[\\s(](?:Access-Control-Allow-Origin|[cC]ors[({:=]|[Aa]llow[Oo]rigins?:|origin:)',
|
|
712
|
+
':\\s{0,10}"(?:Access-Control-Allow-Origin\\s{0,3}:|[cC]ors\\w{0,20}\\s{0,3}[({])'
|
|
700
713
|
],
|
|
701
714
|
flags: ""
|
|
702
715
|
},
|
|
703
|
-
explanation: "A wildcard CORS origin (Access-Control-Allow-Origin: *) was detected. For API endpoints returning user data, this allows any origin on the internet to read responses. Combined with credentials: 'include', wildcard origins are rejected by browsers \u2014 but without credentials, sensitive data is still exposed to cross-origin requests from attacker-controlled pages.\nv4 (founder ruling 2026-08-08, batch item 11): upgraded MEDIUM -> HIGH. This closes a severity disagreement the CLI's own dedup logic had been surfacing since it shipped (packages/cli/src/core/legacy-corpus-map.ts, `dedupeLegacyAgainstCorpus` doc comment): the legacy hand-written deployment check already rates the same wildcard-CORS defect `high` (packages/cli/src/checks/deployment.ts, `deployment_cors_wildcard` / `deployment_config_cors_wildcard_origin`) and dedup kept both findings because it can never silently soften a report. Canonical ruling: CORS misconfiguration is HIGH severity \u2014 nothing about the detection pattern, confidence, or action (warn) changed, only the severity label.",
|
|
716
|
+
explanation: "A wildcard CORS origin (Access-Control-Allow-Origin: *) was detected. For API endpoints returning user data, this allows any origin on the internet to read responses. Combined with credentials: 'include', wildcard origins are rejected by browsers \u2014 but without credentials, sensitive data is still exposed to cross-origin requests from attacker-controlled pages.\nv4 (founder ruling 2026-08-08, batch item 11): upgraded MEDIUM -> HIGH. This closes a severity disagreement the CLI's own dedup logic had been surfacing since it shipped (packages/cli/src/core/legacy-corpus-map.ts, `dedupeLegacyAgainstCorpus` doc comment): the legacy hand-written deployment check already rates the same wildcard-CORS defect `high` (packages/cli/src/checks/deployment.ts, `deployment_cors_wildcard` / `deployment_config_cors_wildcard_origin`) and dedup kept both findings because it can never silently soften a report. Canonical ruling: CORS misconfiguration is HIGH severity \u2014 nothing about the detection pattern, confidence, or action (warn) changed, only the severity label.\nv5 (2026-09-30): detection widened to setups v4 missed. The rule now also covers JSON/JSONC/JSON5 files and these shapes: a cors middleware or option object whose origin is true (reflects every requesting origin, so credentialed requests from any site succeed) or is a list containing the wildcard; key/value header entries such as the Vercel vercel.json and Firebase Hosting firebase.json headers arrays; and AWS API Gateway (SAM AllowOrigin, HTTP API AllowOrigins, method response header parameters). Severity, confidence, action (warn) and tier are unchanged. False-positive guards: origin true is matched only inside cors()/enableCors()/register(cors) calls or cors option objects, never on a bare origin key; JSON string values that merely describe the header are ignored; font-file rules and the existing test/static markers still suppress.",
|
|
704
717
|
recommendation: "Replace the wildcard with an explicit allowlist of trusted origins. Use environment variables for origin configuration (ALLOWED_ORIGINS) so production and development settings can differ. Audit whether this endpoint requires CORS at all.",
|
|
705
718
|
fix: "Replace `'*'` with `process.env.ALLOWED_ORIGIN` and validate against an allowlist.",
|
|
706
719
|
findingType: "vulnerability",
|
|
707
720
|
aiCodeTarget: true,
|
|
708
721
|
references: [
|
|
709
|
-
"https://cwe.mitre.org/data/definitions/942.html"
|
|
722
|
+
"https://cwe.mitre.org/data/definitions/942.html",
|
|
723
|
+
"https://cwe.mitre.org/data/definitions/346.html",
|
|
724
|
+
"https://github.com/expressjs/cors#configuration-options",
|
|
725
|
+
"https://github.com/fastify/fastify-cors#options",
|
|
726
|
+
"https://vercel.com/docs/project-configuration",
|
|
727
|
+
"https://firebase.google.com/docs/hosting/full-config#headers",
|
|
728
|
+
"https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-api-corsconfiguration.html",
|
|
729
|
+
"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html",
|
|
730
|
+
"https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html",
|
|
731
|
+
"https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin"
|
|
710
732
|
]
|
|
711
733
|
},
|
|
712
734
|
{
|
|
@@ -2485,7 +2507,7 @@ function toSarif(result) {
|
|
|
2485
2507
|
|
|
2486
2508
|
// src/core/render.ts
|
|
2487
2509
|
import chalk from "chalk";
|
|
2488
|
-
import { existsSync as existsSync2
|
|
2510
|
+
import { existsSync as existsSync2 } from "fs";
|
|
2489
2511
|
import { join as join4, basename as basename2 } from "path";
|
|
2490
2512
|
import { homedir } from "os";
|
|
2491
2513
|
var DOCS_URL = "https://agenticcli.dev/docs";
|
|
@@ -2533,8 +2555,9 @@ function quickstartHelp(isTTY) {
|
|
|
2533
2555
|
lines.push(` ${chalk.cyan("status")} Show auth status and credits`);
|
|
2534
2556
|
lines.push(` ${chalk.cyan("hook")} ${chalk.dim("--target")} Install the gate at the merge boundary`);
|
|
2535
2557
|
lines.push(` ${chalk.cyan("schema")} ${chalk.dim("--json")} Print the machine-readable scan contract`);
|
|
2536
|
-
lines.push(` ${chalk.cyan("feedback")}
|
|
2558
|
+
lines.push(` ${chalk.cyan("feedback")} Where to send feedback (GitHub issues)`);
|
|
2537
2559
|
lines.push(` ${chalk.cyan("rate")} ${chalk.dim("<id> up|down")} Rate a rule finding`);
|
|
2560
|
+
lines.push(` ${chalk.cyan("telemetry")} ${chalk.dim("status")} Show or change the pseudonymous usage ping`);
|
|
2538
2561
|
lines.push(` ${chalk.cyan("help")} ${chalk.dim("/ ?")} Show this screen`);
|
|
2539
2562
|
lines.push("");
|
|
2540
2563
|
lines.push(chalk.bold(" Exit codes (verdict-neutral \u2014 read the JSON for the verdict):"));
|
|
@@ -2566,8 +2589,9 @@ function quickstartHelp(isTTY) {
|
|
|
2566
2589
|
lines.push(" status Auth status + credits");
|
|
2567
2590
|
lines.push(" hook --target Install the gate at the merge boundary");
|
|
2568
2591
|
lines.push(" schema --json Machine-readable scan contract");
|
|
2569
|
-
lines.push(" feedback
|
|
2592
|
+
lines.push(" feedback Where to send feedback (GitHub issues)");
|
|
2570
2593
|
lines.push(" rate <id> up|down Rate a finding");
|
|
2594
|
+
lines.push(" telemetry status|enable|disable|reset Pseudonymous usage ping");
|
|
2571
2595
|
lines.push(" help / ? Show this screen");
|
|
2572
2596
|
lines.push("");
|
|
2573
2597
|
lines.push(" Exit codes: 0=completed (verdict in JSON) 1=blocked (--strict only: blocking findings or unfinished scan) 2=config-error 3=runtime-error");
|
|
@@ -2830,8 +2854,8 @@ function welcomeBanner(configDir) {
|
|
|
2830
2854
|
return "";
|
|
2831
2855
|
}
|
|
2832
2856
|
try {
|
|
2833
|
-
|
|
2834
|
-
|
|
2857
|
+
ensureSecureDir(dir);
|
|
2858
|
+
writeSecureFileSync(marker, "1");
|
|
2835
2859
|
} catch {
|
|
2836
2860
|
}
|
|
2837
2861
|
const BANNER_INNER = BOX_WIDTH - 2;
|
|
@@ -2858,8 +2882,8 @@ function welcomeBanner(configDir) {
|
|
|
2858
2882
|
empty,
|
|
2859
2883
|
bannerLine(`Docs: ${chalk.underline(DOCS_URL)}`),
|
|
2860
2884
|
empty,
|
|
2861
|
-
bannerLine(chalk.dim("
|
|
2862
|
-
bannerLine(chalk.dim(`Details: ${chalk.underline("agenticcli.dev/docs#telemetry")}`)),
|
|
2885
|
+
bannerLine(chalk.dim("Pseudonymous usage ping \u2014 opt out: shipguard telemetry disable")),
|
|
2886
|
+
bannerLine(chalk.dim(`or SHIPGUARD_TELEMETRY=0 \xB7 Details: ${chalk.underline("agenticcli.dev/docs#telemetry")}`)),
|
|
2863
2887
|
bottom,
|
|
2864
2888
|
""
|
|
2865
2889
|
].join("\n");
|
|
@@ -3041,7 +3065,7 @@ function resolveHistoryPath(cwd, policy) {
|
|
|
3041
3065
|
// src/core/history/identity.ts
|
|
3042
3066
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
3043
3067
|
import { createHash as createHash2, randomUUID as randomUUID2 } from "crypto";
|
|
3044
|
-
import { existsSync as existsSync3, mkdirSync
|
|
3068
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3045
3069
|
import { dirname as dirname3, join as join5 } from "path";
|
|
3046
3070
|
function tryGit(cwd, args) {
|
|
3047
3071
|
try {
|
|
@@ -3057,7 +3081,7 @@ function ensureGitignored(cwd, entry) {
|
|
|
3057
3081
|
const alreadyPresent = existing.split("\n").map((l) => l.trim()).some((l) => l === entry || l === entry.replace(/\/$/, ""));
|
|
3058
3082
|
if (alreadyPresent) return;
|
|
3059
3083
|
const prefix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
3060
|
-
|
|
3084
|
+
writeFileSync(gitignorePath, `${existing}${prefix}${entry}
|
|
3061
3085
|
`, "utf-8");
|
|
3062
3086
|
} catch (err) {
|
|
3063
3087
|
logger.warn(`Could not update .gitignore for history store: ${err instanceof Error ? err.message : err}`);
|
|
@@ -3081,8 +3105,8 @@ function resolveRepoIdentity(cwd) {
|
|
|
3081
3105
|
}
|
|
3082
3106
|
}
|
|
3083
3107
|
const id = randomUUID2();
|
|
3084
|
-
|
|
3085
|
-
|
|
3108
|
+
mkdirSync(dirname3(fallbackPath), { recursive: true });
|
|
3109
|
+
writeFileSync(fallbackPath, `${id}
|
|
3086
3110
|
`, "utf-8");
|
|
3087
3111
|
ensureGitignored(cwd, ".shipguard/");
|
|
3088
3112
|
return { repoId: id, repoIdKind: "fallback-uuid", remoteLabel };
|
|
@@ -3121,7 +3145,7 @@ function computeScopeFingerprint(input) {
|
|
|
3121
3145
|
|
|
3122
3146
|
// src/core/history/store.ts
|
|
3123
3147
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
3124
|
-
import { existsSync as existsSync4, mkdirSync as
|
|
3148
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2 } from "fs";
|
|
3125
3149
|
import { dirname as dirname4 } from "path";
|
|
3126
3150
|
var sqliteModulePromise;
|
|
3127
3151
|
var warningFilterInstalled = false;
|
|
@@ -3174,7 +3198,7 @@ var HistoryStore = class _HistoryStore {
|
|
|
3174
3198
|
}
|
|
3175
3199
|
const preExisted = existsSync4(dbPath);
|
|
3176
3200
|
try {
|
|
3177
|
-
|
|
3201
|
+
mkdirSync2(dirname4(dbPath), { recursive: true });
|
|
3178
3202
|
} catch (err) {
|
|
3179
3203
|
return {
|
|
3180
3204
|
ok: false,
|
|
@@ -3718,38 +3742,319 @@ async function recordScanHistory(input) {
|
|
|
3718
3742
|
}
|
|
3719
3743
|
|
|
3720
3744
|
// src/core/telemetry.ts
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3745
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
3746
|
+
|
|
3747
|
+
// src/core/telemetry-config.ts
|
|
3748
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
3749
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "fs";
|
|
3750
|
+
import { homedir as homedir2 } from "os";
|
|
3751
|
+
import { join as join6 } from "path";
|
|
3752
|
+
import YAML2 from "yaml";
|
|
3753
|
+
var CONFIG_FILE = "telemetry.json";
|
|
3754
|
+
var NOTICE_MARKER = "telemetry-notice-shown";
|
|
3755
|
+
function getConfigDir() {
|
|
3756
|
+
return join6(homedir2(), ".config", "shipguard");
|
|
3757
|
+
}
|
|
3758
|
+
function configFilePath(dir = getConfigDir()) {
|
|
3759
|
+
return join6(dir, CONFIG_FILE);
|
|
3760
|
+
}
|
|
3761
|
+
function readUserConfig(dir = getConfigDir()) {
|
|
3762
|
+
const file = configFilePath(dir);
|
|
3763
|
+
try {
|
|
3764
|
+
if (!existsSync5(file)) return {};
|
|
3765
|
+
const parsed = JSON.parse(readFileSync2(file, "utf-8"));
|
|
3766
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
3767
|
+
} catch (err) {
|
|
3768
|
+
logger.debug(`telemetry: ignoring unreadable ${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3769
|
+
return {};
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
function userConfigUnreadable(dir = getConfigDir()) {
|
|
3773
|
+
const file = configFilePath(dir);
|
|
3774
|
+
try {
|
|
3775
|
+
if (!existsSync5(file)) return false;
|
|
3776
|
+
const parsed = JSON.parse(readFileSync2(file, "utf-8"));
|
|
3777
|
+
return !(parsed && typeof parsed === "object" && !Array.isArray(parsed));
|
|
3778
|
+
} catch {
|
|
3779
|
+
return true;
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
var UUID_V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
3783
|
+
function writeConfig(dir, next) {
|
|
3784
|
+
const file = configFilePath(dir);
|
|
3785
|
+
ensureSecureDir(dir);
|
|
3786
|
+
writeSecureFileSync(file, JSON.stringify(next, null, 2) + "\n");
|
|
3787
|
+
return file;
|
|
3788
|
+
}
|
|
3789
|
+
function readInstallId(dir = getConfigDir()) {
|
|
3790
|
+
const id = readUserConfig(dir).installId;
|
|
3791
|
+
return typeof id === "string" && UUID_V4.test(id) ? id : void 0;
|
|
3792
|
+
}
|
|
3793
|
+
function getOrCreateInstallId(dir = getConfigDir()) {
|
|
3794
|
+
const existing = readInstallId(dir);
|
|
3795
|
+
if (existing) return existing;
|
|
3796
|
+
try {
|
|
3797
|
+
const installId = randomUUID5();
|
|
3798
|
+
writeConfig(dir, { ...readUserConfig(dir), installId });
|
|
3799
|
+
return installId;
|
|
3800
|
+
} catch (err) {
|
|
3801
|
+
logger.debug(`telemetry: could not persist the install id: ${err instanceof Error ? err.message : String(err)}`);
|
|
3802
|
+
return void 0;
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
function resetInstallId(dir = getConfigDir()) {
|
|
3806
|
+
const cfg = readUserConfig(dir);
|
|
3807
|
+
const hadId = "installId" in cfg;
|
|
3808
|
+
const oldId = readInstallId(dir);
|
|
3809
|
+
if (hadId) {
|
|
3810
|
+
delete cfg.installId;
|
|
3811
|
+
writeConfig(dir, cfg);
|
|
3812
|
+
}
|
|
3813
|
+
return { hadId, oldId };
|
|
3814
|
+
}
|
|
3815
|
+
function writeUserEnabled(dir, enabled) {
|
|
3816
|
+
return writeConfig(dir, { ...readUserConfig(dir), enabled });
|
|
3817
|
+
}
|
|
3818
|
+
function noticeShown(dir = getConfigDir()) {
|
|
3819
|
+
return existsSync5(join6(dir, NOTICE_MARKER));
|
|
3820
|
+
}
|
|
3821
|
+
function markNoticeShown(dir = getConfigDir()) {
|
|
3822
|
+
try {
|
|
3823
|
+
ensureSecureDir(dir);
|
|
3824
|
+
writeSecureFileSync(join6(dir, NOTICE_MARKER), "1\n");
|
|
3825
|
+
} catch (err) {
|
|
3826
|
+
logger.debug(`telemetry: could not persist the notice marker: ${err instanceof Error ? err.message : String(err)}`);
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
var FALSE_LIKE = /* @__PURE__ */ new Set(["false", "off", "no", "0"]);
|
|
3830
|
+
var GENERATED_CONFIG_FILE = ".shipguard.yml";
|
|
3831
|
+
function policyTelemetryEnabled(policy) {
|
|
3832
|
+
if (!policy || typeof policy !== "object") return void 0;
|
|
3833
|
+
const t = policy.telemetry;
|
|
3834
|
+
if (!t || typeof t !== "object") return void 0;
|
|
3835
|
+
const v = t.enabled;
|
|
3836
|
+
if (v === false || v === 0) return false;
|
|
3837
|
+
if (typeof v === "string" && FALSE_LIKE.has(v.trim().toLowerCase())) return false;
|
|
3838
|
+
if (v === true) return true;
|
|
3839
|
+
return void 0;
|
|
3840
|
+
}
|
|
3841
|
+
function readYamlToggle(file) {
|
|
3842
|
+
try {
|
|
3843
|
+
if (!existsSync5(file)) return void 0;
|
|
3844
|
+
return policyTelemetryEnabled(YAML2.parse(readFileSync2(file, "utf-8")));
|
|
3845
|
+
} catch (err) {
|
|
3846
|
+
logger.debug(`telemetry: ignoring unreadable ${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3847
|
+
return void 0;
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
function projectTelemetryEnabled(input) {
|
|
3851
|
+
const values = [policyTelemetryEnabled(input.policy)];
|
|
3852
|
+
if (input.projectDir) {
|
|
3853
|
+
if (input.policy === void 0) values.push(readYamlToggle(join6(input.projectDir, DEFAULT_POLICY_PATH)));
|
|
3854
|
+
values.push(readYamlToggle(join6(input.projectDir, GENERATED_CONFIG_FILE)));
|
|
3855
|
+
}
|
|
3856
|
+
if (values.includes(false)) return false;
|
|
3857
|
+
if (values.includes(true)) return true;
|
|
3858
|
+
return void 0;
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3861
|
+
// src/core/telemetry.ts
|
|
3862
|
+
var IS_PUBLISHED_BUILD = true;
|
|
3863
|
+
function getProvenance(published = IS_PUBLISHED_BUILD) {
|
|
3864
|
+
return published ? "published" : "dev";
|
|
3865
|
+
}
|
|
3866
|
+
var PROD_TELEMETRY_ENDPOINT = "https://cheery-toucan-348.convex.site/cli-telemetry";
|
|
3867
|
+
function isLoopbackUrl(raw2) {
|
|
3868
|
+
if (!raw2) return false;
|
|
3869
|
+
try {
|
|
3870
|
+
const host = new URL(raw2).hostname;
|
|
3871
|
+
return host === "127.0.0.1" || host === "localhost" || host === "[::1]" || host === "::1";
|
|
3872
|
+
} catch {
|
|
3873
|
+
return false;
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
function resolveEndpoint(published = IS_PUBLISHED_BUILD, env = process.env) {
|
|
3877
|
+
const override = env.SHIPGUARD_TELEMETRY_URL;
|
|
3878
|
+
if (published) return override || PROD_TELEMETRY_ENDPOINT;
|
|
3879
|
+
return isLoopbackUrl(override) ? override : null;
|
|
3880
|
+
}
|
|
3881
|
+
var ALLOWED_KEYS = [
|
|
3882
|
+
"schema",
|
|
3883
|
+
"eventId",
|
|
3884
|
+
"installId",
|
|
3885
|
+
"cliVersion",
|
|
3886
|
+
"provenance",
|
|
3887
|
+
"verdict",
|
|
3888
|
+
"durationBucket",
|
|
3889
|
+
"ci"
|
|
3890
|
+
];
|
|
3891
|
+
var VERSION_RE = /^(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})\.(0|[1-9]\d{0,2})(-[0-9A-Za-z.-]{1,24})?$/;
|
|
3892
|
+
var DURATION_BUCKETS = ["lt1s", "1to5s", "5to30s", "gt30s"];
|
|
3893
|
+
function durationBucket(ms) {
|
|
3894
|
+
if (!(ms >= 1e3)) return "lt1s";
|
|
3895
|
+
if (ms < 5e3) return "1to5s";
|
|
3896
|
+
if (ms < 3e4) return "5to30s";
|
|
3897
|
+
return "gt30s";
|
|
3898
|
+
}
|
|
3899
|
+
var CI_PROVIDER_VARS = [
|
|
3900
|
+
"GITHUB_ACTIONS",
|
|
3901
|
+
"GITLAB_CI",
|
|
3902
|
+
"CIRCLECI",
|
|
3903
|
+
"TRAVIS",
|
|
3904
|
+
"BUILDKITE",
|
|
3905
|
+
"JENKINS_URL",
|
|
3906
|
+
"TF_BUILD",
|
|
3907
|
+
"TEAMCITY_VERSION",
|
|
3908
|
+
"BITBUCKET_BUILD_NUMBER",
|
|
3909
|
+
"APPVEYOR",
|
|
3910
|
+
"DRONE",
|
|
3911
|
+
"CODEBUILD_BUILD_ID",
|
|
3912
|
+
"SEMAPHORE",
|
|
3913
|
+
"BUILD_BUILDID",
|
|
3914
|
+
"CF_BUILD_ID",
|
|
3915
|
+
"NETLIFY",
|
|
3916
|
+
"VERCEL",
|
|
3917
|
+
"WOODPECKER",
|
|
3918
|
+
"BUDDY",
|
|
3919
|
+
"HUDSON_URL"
|
|
3920
|
+
];
|
|
3921
|
+
function detectCi(env = process.env) {
|
|
3922
|
+
const ci = env.CI;
|
|
3923
|
+
if (ci !== void 0 && !["", "0", "false"].includes(ci.trim().toLowerCase())) return true;
|
|
3924
|
+
return CI_PROVIDER_VARS.some((k) => env[k] !== void 0);
|
|
3925
|
+
}
|
|
3926
|
+
function isTruthyOff(v, offValues) {
|
|
3927
|
+
return v !== void 0 && offValues.includes(v.trim().toLowerCase());
|
|
3928
|
+
}
|
|
3929
|
+
function envOptOut(env) {
|
|
3930
|
+
if (isTruthyOff(env.SHIPGUARD_TELEMETRY, ["0", "false"])) return "env:SHIPGUARD_TELEMETRY";
|
|
3931
|
+
if (isTruthyOff(env.DO_NOT_TRACK, ["1", "true"])) return "env:DO_NOT_TRACK";
|
|
3932
|
+
return null;
|
|
3725
3933
|
}
|
|
3726
3934
|
function buildPayload(input) {
|
|
3727
|
-
const { cliVersion, verdict,
|
|
3728
|
-
return { cliVersion, verdict,
|
|
3729
|
-
}
|
|
3730
|
-
function
|
|
3731
|
-
if (
|
|
3732
|
-
const
|
|
3733
|
-
const
|
|
3734
|
-
|
|
3735
|
-
const
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
}
|
|
3742
|
-
|
|
3743
|
-
|
|
3935
|
+
const { schema, eventId, installId, cliVersion, provenance, verdict, durationBucket: durationBucket2, ci } = input;
|
|
3936
|
+
return { schema, eventId, installId, cliVersion, provenance, verdict, durationBucket: durationBucket2, ci };
|
|
3937
|
+
}
|
|
3938
|
+
function validatePayload(payload) {
|
|
3939
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return false;
|
|
3940
|
+
const obj = payload;
|
|
3941
|
+
const keys = Object.keys(obj);
|
|
3942
|
+
if (keys.length !== ALLOWED_KEYS.length) return false;
|
|
3943
|
+
for (const k of ALLOWED_KEYS) if (!(k in obj)) return false;
|
|
3944
|
+
if (obj.schema !== 2) return false;
|
|
3945
|
+
if (typeof obj.eventId !== "string" || !UUID_V4.test(obj.eventId)) return false;
|
|
3946
|
+
if (typeof obj.ci !== "boolean") return false;
|
|
3947
|
+
if (obj.ci) {
|
|
3948
|
+
if (obj.installId !== null) return false;
|
|
3949
|
+
} else if (typeof obj.installId !== "string" || !UUID_V4.test(obj.installId)) {
|
|
3950
|
+
return false;
|
|
3951
|
+
}
|
|
3952
|
+
if (typeof obj.cliVersion !== "string" || obj.cliVersion.length > 40 || !VERSION_RE.test(obj.cliVersion)) return false;
|
|
3953
|
+
if (obj.provenance !== "published" && obj.provenance !== "dev") return false;
|
|
3954
|
+
if (!["safe", "review", "blocked", "error"].includes(obj.verdict)) return false;
|
|
3955
|
+
if (!DURATION_BUCKETS.includes(obj.durationBucket)) return false;
|
|
3956
|
+
return true;
|
|
3957
|
+
}
|
|
3958
|
+
function decideTelemetry(input = {}) {
|
|
3959
|
+
const env = input.env ?? process.env;
|
|
3960
|
+
const envOff = envOptOut(env);
|
|
3961
|
+
if (envOff) return { enabled: false, source: envOff };
|
|
3962
|
+
const dir = input.configDir ?? getConfigDir();
|
|
3963
|
+
if (userConfigUnreadable(dir) || readUserConfig(dir).enabled === false) {
|
|
3964
|
+
return { enabled: false, source: "user-config" };
|
|
3965
|
+
}
|
|
3966
|
+
if (projectTelemetryEnabled({ policy: input.policy, projectDir: input.projectDir }) === false) return { enabled: false, source: "project-policy" };
|
|
3967
|
+
return { enabled: true, source: "default" };
|
|
3968
|
+
}
|
|
3969
|
+
var NOTICE_TEXT = "shipguard: sends a pseudonymous usage ping after each scan (version, verdict, duration bucket, a random install id outside CI; never code, paths or your account). Turn it off: SHIPGUARD_TELEMETRY=0, DO_NOT_TRACK=1, or `shipguard telemetry disable`. https://agenticcli.dev/docs#telemetry";
|
|
3970
|
+
var PING_WAIT_MS = 1500;
|
|
3971
|
+
var FETCH_TIMEOUT_MS = 1e3;
|
|
3972
|
+
function debugEnabled(env) {
|
|
3973
|
+
const v = env.SHIPGUARD_TELEMETRY_DEBUG;
|
|
3974
|
+
return Boolean(v) && v !== "0";
|
|
3975
|
+
}
|
|
3976
|
+
function sendTelemetry(input, opts = {}) {
|
|
3977
|
+
try {
|
|
3978
|
+
const env = opts.env ?? process.env;
|
|
3979
|
+
const configDir = opts.configDir ?? getConfigDir();
|
|
3980
|
+
const published = opts.published ?? IS_PUBLISHED_BUILD;
|
|
3981
|
+
const debug = debugEnabled(env);
|
|
3982
|
+
const decision = decideTelemetry({ env, configDir, policy: opts.policy, projectDir: opts.projectDir });
|
|
3983
|
+
if (!decision.enabled) {
|
|
3984
|
+
if (debug) process.stderr.write(`[shipguard:telemetry] disabled (${decision.source}); nothing would be sent
|
|
3985
|
+
`);
|
|
3986
|
+
return Promise.resolve();
|
|
3744
3987
|
}
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3988
|
+
const endpoint = resolveEndpoint(published, env);
|
|
3989
|
+
const ci = detectCi(env);
|
|
3990
|
+
const base = {
|
|
3991
|
+
schema: 2,
|
|
3992
|
+
eventId: randomUUID6(),
|
|
3993
|
+
cliVersion: input.cliVersion,
|
|
3994
|
+
provenance: getProvenance(published),
|
|
3995
|
+
verdict: input.verdict,
|
|
3996
|
+
durationBucket: durationBucket(input.durationMs),
|
|
3997
|
+
ci
|
|
3998
|
+
};
|
|
3999
|
+
if (debug) {
|
|
4000
|
+
const stored = ci ? null : readInstallId(configDir);
|
|
4001
|
+
const installId2 = ci ? null : stored ?? randomUUID6();
|
|
4002
|
+
const note = !ci && !stored ? " (installId is a preview: none saved yet, one is created on the first real ping)" : "";
|
|
4003
|
+
process.stderr.write(
|
|
4004
|
+
`[shipguard:telemetry] SHIPGUARD_TELEMETRY_DEBUG=1: not sending. provenance=${base.provenance} endpoint=${endpoint ?? "(none: dev build without a loopback SHIPGUARD_TELEMETRY_URL)"} payload=${JSON.stringify(buildPayload({ ...base, installId: installId2 }))}${note}
|
|
4005
|
+
`
|
|
4006
|
+
);
|
|
4007
|
+
return Promise.resolve();
|
|
4008
|
+
}
|
|
4009
|
+
if (endpoint === null) {
|
|
4010
|
+
logger.debug("telemetry: dev build, not sending (set a loopback SHIPGUARD_TELEMETRY_URL to capture)");
|
|
4011
|
+
return Promise.resolve();
|
|
4012
|
+
}
|
|
4013
|
+
if (!noticeShown(configDir)) {
|
|
4014
|
+
process.stderr.write(NOTICE_TEXT + "\n");
|
|
4015
|
+
markNoticeShown(configDir);
|
|
4016
|
+
}
|
|
4017
|
+
const installId = ci ? null : getOrCreateInstallId(configDir) ?? void 0;
|
|
4018
|
+
if (installId === void 0) {
|
|
4019
|
+
logger.debug("telemetry: no install id could be saved; not sending");
|
|
4020
|
+
return Promise.resolve();
|
|
4021
|
+
}
|
|
4022
|
+
const payload = buildPayload({ ...base, installId });
|
|
4023
|
+
if (!validatePayload(payload)) {
|
|
4024
|
+
logger.debug("telemetry: payload failed validation; not sending");
|
|
4025
|
+
return Promise.resolve();
|
|
4026
|
+
}
|
|
4027
|
+
const body = JSON.stringify(payload);
|
|
4028
|
+
const controller = new AbortController();
|
|
4029
|
+
const abortTimer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
4030
|
+
const request = fetch(endpoint, {
|
|
4031
|
+
method: "POST",
|
|
4032
|
+
headers: { "Content-Type": "application/json" },
|
|
4033
|
+
body,
|
|
4034
|
+
signal: controller.signal
|
|
4035
|
+
}).then(
|
|
4036
|
+
() => void 0,
|
|
4037
|
+
(err) => {
|
|
4038
|
+
logger.debug(`telemetry: ping failed (ignored): ${err instanceof Error ? err.message : String(err)}`);
|
|
4039
|
+
}
|
|
4040
|
+
).finally(() => clearTimeout(abortTimer));
|
|
4041
|
+
return new Promise((resolve7) => {
|
|
4042
|
+
const cap = setTimeout(resolve7, PING_WAIT_MS);
|
|
4043
|
+
cap.unref();
|
|
4044
|
+
void request.then(() => {
|
|
4045
|
+
clearTimeout(cap);
|
|
4046
|
+
resolve7();
|
|
4047
|
+
});
|
|
4048
|
+
});
|
|
4049
|
+
} catch (err) {
|
|
4050
|
+
logger.debug(`telemetry: skipped after error (ignored): ${err instanceof Error ? err.message : String(err)}`);
|
|
4051
|
+
return Promise.resolve();
|
|
4052
|
+
}
|
|
3748
4053
|
}
|
|
3749
4054
|
|
|
3750
4055
|
// src/commands/scan.ts
|
|
3751
4056
|
var LEARN_MORE = "Docs https://agenticcli.dev/docs \xB7 Site https://agenticcli.dev \xB7 Pricing https://agenticcli.dev/pricing \xB7 Issues https://github.com/agenticcli/shipguard/issues";
|
|
3752
|
-
var CLI_VERSION = true ? "0.
|
|
4057
|
+
var CLI_VERSION = true ? "0.7.1" : process.env.npm_package_version ?? "0.0.0-dev";
|
|
3753
4058
|
function resolveExitCode(opts) {
|
|
3754
4059
|
if (opts.strict && (opts.blockingCount > 0 || opts.degraded === true || opts.recommendation === "DO_NOT_SHIP")) {
|
|
3755
4060
|
return EXIT_CODES.BLOCKED;
|
|
@@ -3775,7 +4080,7 @@ function proFetchActionHint(code, retryAfterSeconds) {
|
|
|
3775
4080
|
}
|
|
3776
4081
|
}
|
|
3777
4082
|
function isProjectRoot(dir) {
|
|
3778
|
-
return
|
|
4083
|
+
return existsSync6(join7(dir, "package.json")) || existsSync6(join7(dir, ".git"));
|
|
3779
4084
|
}
|
|
3780
4085
|
function scanCommand() {
|
|
3781
4086
|
return new Command2("scan").description("Scan your project for high-risk issues (verbose by default; use --quiet for one-line verdict)").argument("[path]", "Path to project root to scan (defaults to current directory)").option("--changed", "Only scan changed files from git diff").option("--report", "Generate a detailed Markdown report").option("--strict", "Opt-in hard gate: exit 1 if blocking findings exist, the scan did not finish, OR the verdict is DO_NOT_SHIP (default exit is 0 \u2014 verdict is informational, read the JSON `recommendation`)").option("--json", "Output results as JSON (machine-readable; suppresses all decoration)").option("--sarif", "Output results as SARIF 2.1.0 (for GitHub Code Scanning)").option("-q, --quiet", "One-line verdict only (suppresses progress, panel, and tips)").option("--pro", "Include pro quality gate rules (requires authentication)").option("--api-url <url>", "API server URL", "https://agenticcli.dev").option("--category <categories>", "Comma-separated category filter for pro rules").option("--beta", "Include beta-stage rules").option("--all", "Scan any directory, even without package.json or .git").option("--allow-degraded", "With --pro: fall back to local-only rules if the pro rule fetch fails, instead of failing loud (opt-in; restores the pre-2026-07-14 fallback behavior \u2014 see exit code 3 below)").option("--check-regressions", "Opt-in hard gate: exit 1 if a previously-passing blocking rule now fails under the same scan scope + corpus release (informational-only in --json unless this flag is set)").addHelpText("after", `
|
|
@@ -3915,8 +4220,8 @@ async function runScan(ctx) {
|
|
|
3915
4220
|
logger.info("Detecting stack...");
|
|
3916
4221
|
}
|
|
3917
4222
|
try {
|
|
3918
|
-
const { fetchProRules } = await import("./pro-scanner-
|
|
3919
|
-
const { hasConfig, generateConfig } = await import("./config-generator-
|
|
4223
|
+
const { fetchProRules } = await import("./pro-scanner-QDOFUEXZ.js");
|
|
4224
|
+
const { hasConfig, generateConfig } = await import("./config-generator-2BVUZGEU.js");
|
|
3920
4225
|
const frameworks = detectedFrameworks;
|
|
3921
4226
|
if (!hasConfig(cwd)) {
|
|
3922
4227
|
const configPath = generateConfig(cwd, frameworks);
|
|
@@ -4173,39 +4478,20 @@ async function runScan(ctx) {
|
|
|
4173
4478
|
reportPaths
|
|
4174
4479
|
));
|
|
4175
4480
|
}
|
|
4176
|
-
|
|
4177
|
-
fetch(`${opts.apiUrl}/api/telemetry/ingest`, {
|
|
4178
|
-
method: "POST",
|
|
4179
|
-
headers: { "Content-Type": "application/json" },
|
|
4180
|
-
body: JSON.stringify({
|
|
4181
|
-
scanId,
|
|
4182
|
-
findingsCount: result.findings.length,
|
|
4183
|
-
blocked: result.riskScore.blockingCount > 0,
|
|
4184
|
-
riskScore: result.riskScore.score,
|
|
4185
|
-
recommendation: result.riskScore.recommendation,
|
|
4186
|
-
severityBreakdown: {
|
|
4187
|
-
critical: result.riskScore.criticalCount,
|
|
4188
|
-
high: result.riskScore.highCount,
|
|
4189
|
-
medium: result.riskScore.mediumCount,
|
|
4190
|
-
low: result.riskScore.lowCount,
|
|
4191
|
-
info: result.riskScore.infoCount
|
|
4192
|
-
},
|
|
4193
|
-
rulesApplied: proRules?.length ?? 0
|
|
4194
|
-
})
|
|
4195
|
-
}).catch(() => {
|
|
4196
|
-
});
|
|
4197
|
-
}
|
|
4481
|
+
let telemetryDone = void 0;
|
|
4198
4482
|
try {
|
|
4199
4483
|
const elapsedMs = Date.now() - startTime;
|
|
4200
4484
|
const verdictBucket = result.degraded ? "review" : result.riskScore.blockingCount > 0 ? "blocked" : result.riskScore.recommendation === "REVIEW_BEFORE_SHIP" ? "review" : "safe";
|
|
4201
|
-
sendTelemetry(
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4485
|
+
telemetryDone = sendTelemetry(
|
|
4486
|
+
{
|
|
4487
|
+
cliVersion: CLI_VERSION,
|
|
4488
|
+
verdict: verdictBucket,
|
|
4489
|
+
durationMs: elapsedMs
|
|
4490
|
+
},
|
|
4491
|
+
{ policy, projectDir: cwd }
|
|
4492
|
+
);
|
|
4493
|
+
} catch (err) {
|
|
4494
|
+
logger.debug(`telemetry: skipped (ignored): ${err instanceof Error ? err.message : String(err)}`);
|
|
4209
4495
|
}
|
|
4210
4496
|
let exitCode = resolveExitCode({
|
|
4211
4497
|
strict: scanOptions.strict,
|
|
@@ -4238,6 +4524,7 @@ async function runScan(ctx) {
|
|
|
4238
4524
|
logger.warn(`--check-regressions: ${result.regressions?.length} previously-passing rule(s) now fail \u2014 exiting with code 1`);
|
|
4239
4525
|
}
|
|
4240
4526
|
}
|
|
4527
|
+
await telemetryDone;
|
|
4241
4528
|
if (exitCode !== EXIT_CODES.SAFE) {
|
|
4242
4529
|
process.exit(exitCode);
|
|
4243
4530
|
}
|
|
@@ -4346,7 +4633,7 @@ function statusCommand() {
|
|
|
4346
4633
|
// src/commands/history.ts
|
|
4347
4634
|
import { Command as Command6 } from "commander";
|
|
4348
4635
|
import { resolve as resolve5 } from "path";
|
|
4349
|
-
var CLI_VERSION2 = true ? "0.
|
|
4636
|
+
var CLI_VERSION2 = true ? "0.7.1" : process.env.npm_package_version ?? "0.0.0-dev";
|
|
4350
4637
|
function historyCommand() {
|
|
4351
4638
|
return new Command6("history").description("Show recent local scan history for this repo (read-only; --json for machine output)").argument("[path]", "Path to project root (defaults to current directory)").option("--json", "Output as JSON").option("--limit <n>", "Number of recent scans to show", (v) => Number.parseInt(v, 10) || 10, 10).action(async (scanPath, opts) => {
|
|
4352
4639
|
const cwd = scanPath ? resolve5(scanPath) : process.cwd();
|
|
@@ -4410,8 +4697,8 @@ function historyCommand() {
|
|
|
4410
4697
|
// src/commands/hook.ts
|
|
4411
4698
|
import { Command as Command7 } from "commander";
|
|
4412
4699
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
4413
|
-
import { chmodSync, existsSync as
|
|
4414
|
-
import { dirname as dirname5, isAbsolute, join as
|
|
4700
|
+
import { chmodSync, existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
4701
|
+
import { dirname as dirname5, isAbsolute, join as join8, relative as relative2, resolve as resolve6 } from "path";
|
|
4415
4702
|
|
|
4416
4703
|
// src/core/hook-templates.ts
|
|
4417
4704
|
var HOOK_BLOCK_VERSION = 1;
|
|
@@ -4503,13 +4790,13 @@ function isManaged(content) {
|
|
|
4503
4790
|
|
|
4504
4791
|
// src/commands/hook.ts
|
|
4505
4792
|
function writeManaged(path, whole, block, executable) {
|
|
4506
|
-
if (!
|
|
4507
|
-
|
|
4508
|
-
|
|
4793
|
+
if (!existsSync7(path)) {
|
|
4794
|
+
mkdirSync3(dirname5(path), { recursive: true });
|
|
4795
|
+
writeFileSync2(path, whole, "utf-8");
|
|
4509
4796
|
if (executable) chmodSync(path, 493);
|
|
4510
4797
|
return { path, status: "created" };
|
|
4511
4798
|
}
|
|
4512
|
-
const current =
|
|
4799
|
+
const current = readFileSync3(path, "utf-8");
|
|
4513
4800
|
if (!isManaged(current)) {
|
|
4514
4801
|
return {
|
|
4515
4802
|
path,
|
|
@@ -4519,7 +4806,7 @@ function writeManaged(path, whole, block, executable) {
|
|
|
4519
4806
|
}
|
|
4520
4807
|
const merged = replaceManagedBlock(current, block) ?? whole;
|
|
4521
4808
|
if (merged === current) return { path, status: "unchanged" };
|
|
4522
|
-
|
|
4809
|
+
writeFileSync2(path, merged, "utf-8");
|
|
4523
4810
|
if (executable) chmodSync(path, 493);
|
|
4524
4811
|
return { path, status: "updated" };
|
|
4525
4812
|
}
|
|
@@ -4534,18 +4821,18 @@ function resolveGitHooksDir(cwd) {
|
|
|
4534
4821
|
function installGit(cwd) {
|
|
4535
4822
|
const hooksDir = resolveGitHooksDir(cwd);
|
|
4536
4823
|
return GIT_HOOK_NAMES.map(
|
|
4537
|
-
(name) => writeManaged(
|
|
4824
|
+
(name) => writeManaged(join8(hooksDir, name), gitHookScript(name), gitHookBlock(name), true)
|
|
4538
4825
|
);
|
|
4539
4826
|
}
|
|
4540
4827
|
function installClaude(cwd) {
|
|
4541
|
-
const path =
|
|
4828
|
+
const path = join8(cwd, ".claude", "settings.json");
|
|
4542
4829
|
const entry = { matcher: "Bash", hooks: [{ type: "command", command: CLAUDE_HOOK_COMMAND }] };
|
|
4543
|
-
if (!
|
|
4544
|
-
|
|
4545
|
-
|
|
4830
|
+
if (!existsSync7(path)) {
|
|
4831
|
+
mkdirSync3(dirname5(path), { recursive: true });
|
|
4832
|
+
writeFileSync2(path, JSON.stringify({ hooks: { PreToolUse: [entry] } }, null, 2) + "\n", "utf-8");
|
|
4546
4833
|
return [{ path, status: "created" }];
|
|
4547
4834
|
}
|
|
4548
|
-
const raw2 =
|
|
4835
|
+
const raw2 = readFileSync3(path, "utf-8");
|
|
4549
4836
|
let settings;
|
|
4550
4837
|
try {
|
|
4551
4838
|
settings = JSON.parse(raw2);
|
|
@@ -4575,12 +4862,12 @@ function installClaude(cwd) {
|
|
|
4575
4862
|
...settings,
|
|
4576
4863
|
hooks: { ...settings.hooks ?? {}, PreToolUse: next }
|
|
4577
4864
|
};
|
|
4578
|
-
|
|
4865
|
+
writeFileSync2(path, JSON.stringify(merged, null, 2) + "\n", "utf-8");
|
|
4579
4866
|
}
|
|
4580
4867
|
return [{ path, status }];
|
|
4581
4868
|
}
|
|
4582
4869
|
function installCi(cwd) {
|
|
4583
|
-
const path =
|
|
4870
|
+
const path = join8(cwd, ".github", "workflows", "shipguard.yml");
|
|
4584
4871
|
const yaml = ciWorkflowYaml();
|
|
4585
4872
|
return [writeManaged(path, yaml, yaml, false)];
|
|
4586
4873
|
}
|
|
@@ -4666,7 +4953,7 @@ Exit codes:
|
|
|
4666
4953
|
|
|
4667
4954
|
// src/commands/schema.ts
|
|
4668
4955
|
import { Command as Command8 } from "commander";
|
|
4669
|
-
var CLI_VERSION3 = true ? "0.
|
|
4956
|
+
var CLI_VERSION3 = true ? "0.7.1" : process.env.npm_package_version ?? "0.0.0-dev";
|
|
4670
4957
|
var CURRENT_SCHEMA_VERSION2 = "5";
|
|
4671
4958
|
function buildSchemaContract(limits) {
|
|
4672
4959
|
const src = (value, fallback) => value === fallback ? "default" : "policy";
|
|
@@ -4838,43 +5125,11 @@ function renderSchemaHuman(c) {
|
|
|
4838
5125
|
|
|
4839
5126
|
// src/commands/feedback.ts
|
|
4840
5127
|
import { Command as Command9 } from "commander";
|
|
5128
|
+
var ISSUES_URL2 = "https://github.com/agenticcli/shipguard/issues";
|
|
4841
5129
|
function feedbackCommand() {
|
|
4842
|
-
return new Command9("feedback").description("
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
const t = await getAuthToken();
|
|
4846
|
-
if (!t) {
|
|
4847
|
-
logger.error("Not authenticated. Run `shipguard login` first.");
|
|
4848
|
-
return;
|
|
4849
|
-
}
|
|
4850
|
-
token = t;
|
|
4851
|
-
} catch (err) {
|
|
4852
|
-
logger.error(`Authentication failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4853
|
-
return;
|
|
4854
|
-
}
|
|
4855
|
-
const creds = loadCredentials();
|
|
4856
|
-
if (!creds) {
|
|
4857
|
-
logger.error("No credentials found. Run `shipguard login` first.");
|
|
4858
|
-
return;
|
|
4859
|
-
}
|
|
4860
|
-
try {
|
|
4861
|
-
assertTrustedApiUrl(creds.apiUrl);
|
|
4862
|
-
const res = await fetch(`${creds.apiUrl}/api/feedback`, {
|
|
4863
|
-
method: "POST",
|
|
4864
|
-
headers: {
|
|
4865
|
-
"Authorization": `Bearer ${token}`,
|
|
4866
|
-
"Content-Type": "application/json"
|
|
4867
|
-
},
|
|
4868
|
-
body: JSON.stringify({ freeText: text })
|
|
4869
|
-
});
|
|
4870
|
-
if (!res.ok) {
|
|
4871
|
-
logger.error(`Feedback submission failed: ${res.statusText}`);
|
|
4872
|
-
return;
|
|
4873
|
-
}
|
|
4874
|
-
logger.success("Feedback submitted \u2014 thank you!");
|
|
4875
|
-
} catch (err) {
|
|
4876
|
-
logger.error(`Failed to send feedback: ${err instanceof Error ? err.message : String(err)}`);
|
|
4877
|
-
}
|
|
5130
|
+
return new Command9("feedback").description("Tell us what you think: prints where to send feedback (no network call)").argument("[text]", "Ignored. Feedback is not sent from the CLI; open an issue instead").action(() => {
|
|
5131
|
+
logger.info(`Feedback and bug reports go to GitHub issues: ${ISSUES_URL2}`);
|
|
5132
|
+
logger.info("The CLI does not send your feedback anywhere itself.");
|
|
4878
5133
|
});
|
|
4879
5134
|
}
|
|
4880
5135
|
function rateCommand() {
|
|
@@ -4930,10 +5185,92 @@ function rateCommand() {
|
|
|
4930
5185
|
});
|
|
4931
5186
|
}
|
|
4932
5187
|
|
|
5188
|
+
// src/commands/telemetry.ts
|
|
5189
|
+
import { Command as Command10 } from "commander";
|
|
5190
|
+
var DOCS = "https://agenticcli.dev/docs#telemetry";
|
|
5191
|
+
var SOURCE_TEXT = {
|
|
5192
|
+
"env:SHIPGUARD_TELEMETRY": "SHIPGUARD_TELEMETRY=0 is set in the environment",
|
|
5193
|
+
"env:DO_NOT_TRACK": "DO_NOT_TRACK=1 is set in the environment",
|
|
5194
|
+
"user-config": "turned off with `shipguard telemetry disable`",
|
|
5195
|
+
"project-policy": "`telemetry.enabled: false` in shipguard.policy.yml or .shipguard.yml",
|
|
5196
|
+
default: "default (on)"
|
|
5197
|
+
};
|
|
5198
|
+
function telemetryCommand() {
|
|
5199
|
+
const cmd = new Command10("telemetry").description(
|
|
5200
|
+
"Show or change the pseudonymous usage ping (status, enable, disable, reset)"
|
|
5201
|
+
);
|
|
5202
|
+
cmd.command("status").description("Show whether usage pings are on, why, and where they would go").option("--json", "Machine-readable output").action(async (o) => {
|
|
5203
|
+
const decision = decideTelemetry({ projectDir: process.cwd() });
|
|
5204
|
+
const provenance = getProvenance();
|
|
5205
|
+
const endpoint = resolveEndpoint();
|
|
5206
|
+
const installId = readInstallId() ?? null;
|
|
5207
|
+
const info = {
|
|
5208
|
+
version: 2,
|
|
5209
|
+
enabled: decision.enabled,
|
|
5210
|
+
source: decision.source,
|
|
5211
|
+
provenance,
|
|
5212
|
+
endpoint,
|
|
5213
|
+
noticeShown: noticeShown(),
|
|
5214
|
+
installIdPresent: installId !== null,
|
|
5215
|
+
installId,
|
|
5216
|
+
ci: detectCi(),
|
|
5217
|
+
configFile: configFilePath(),
|
|
5218
|
+
optOut: ["SHIPGUARD_TELEMETRY=0", "DO_NOT_TRACK=1", "shipguard telemetry disable"]
|
|
5219
|
+
};
|
|
5220
|
+
if (o.json) {
|
|
5221
|
+
console.log(JSON.stringify(info, null, 2));
|
|
5222
|
+
return;
|
|
5223
|
+
}
|
|
5224
|
+
console.log(`Usage pings: ${decision.enabled ? "ON" : "OFF"} (${SOURCE_TEXT[decision.source]})`);
|
|
5225
|
+
console.log(
|
|
5226
|
+
`Build: ${provenance}` + (provenance === "dev" ? " (a dev build never pings production; only a loopback SHIPGUARD_TELEMETRY_URL)" : "")
|
|
5227
|
+
);
|
|
5228
|
+
console.log(`Endpoint: ${endpoint ?? "none"}`);
|
|
5229
|
+
console.log(
|
|
5230
|
+
`Install id: ${installId ?? "none yet"}` + (installId ? "" : " (a random id is made on the first ping outside CI)") + (detectCi() ? " (CI detected: no install id is created or sent)" : "")
|
|
5231
|
+
);
|
|
5232
|
+
console.log(`Sends: CLI version, verdict, duration bucket, CI flag, build type, install id (null in CI). Never code, paths, repo names or your account.`);
|
|
5233
|
+
console.log(`Turn off: SHIPGUARD_TELEMETRY=0 | DO_NOT_TRACK=1 | shipguard telemetry disable`);
|
|
5234
|
+
console.log(`Inspect: SHIPGUARD_TELEMETRY_DEBUG=1 shipguard scan (prints the exact payload, sends nothing)`);
|
|
5235
|
+
console.log(`Details: ${DOCS}`);
|
|
5236
|
+
});
|
|
5237
|
+
for (const [name, enabled] of [["enable", true], ["disable", false]]) {
|
|
5238
|
+
cmd.command(name).description(enabled ? "Turn usage pings on for this user" : "Turn usage pings off for this user").action(() => {
|
|
5239
|
+
try {
|
|
5240
|
+
const file = writeUserEnabled(getConfigDir(), enabled);
|
|
5241
|
+
console.log(`Usage pings ${enabled ? "enabled" : "disabled"} for this user (${file}).`);
|
|
5242
|
+
} catch (err) {
|
|
5243
|
+
logger.error(`Could not save the setting: ${err instanceof Error ? err.message : String(err)}`);
|
|
5244
|
+
process.exitCode = EXIT_CODES.RUNTIME_ERROR;
|
|
5245
|
+
return;
|
|
5246
|
+
}
|
|
5247
|
+
const decision = decideTelemetry({ projectDir: process.cwd() });
|
|
5248
|
+
if (enabled && !decision.enabled) {
|
|
5249
|
+
logger.warn(`Pings stay OFF: ${SOURCE_TEXT[decision.source]}.`);
|
|
5250
|
+
}
|
|
5251
|
+
});
|
|
5252
|
+
}
|
|
5253
|
+
cmd.command("reset").description("Forget the local install id (a new random one is made on the next ping)").action(() => {
|
|
5254
|
+
try {
|
|
5255
|
+
const { hadId, oldId } = resetInstallId(getConfigDir());
|
|
5256
|
+
console.log(hadId ? "Install id deleted. A new random one is made on the next ping." : "No install id was stored. Nothing to reset.");
|
|
5257
|
+
if (oldId) console.log(`Old install id: ${oldId}`);
|
|
5258
|
+
console.log(
|
|
5259
|
+
"Pings already sent stay on the server under the old id. Past events can be deleted on request" + (oldId ? ": quote the old install id above." : ".") + ` Retention and deletion: ${DOCS}`
|
|
5260
|
+
);
|
|
5261
|
+
} catch (err) {
|
|
5262
|
+
logger.error(`Could not reset the install id: ${err instanceof Error ? err.message : String(err)}`);
|
|
5263
|
+
process.exitCode = EXIT_CODES.RUNTIME_ERROR;
|
|
5264
|
+
}
|
|
5265
|
+
});
|
|
5266
|
+
for (const sub of cmd.commands) sub.exitOverride();
|
|
5267
|
+
return cmd;
|
|
5268
|
+
}
|
|
5269
|
+
|
|
4933
5270
|
// src/handlers.ts
|
|
4934
|
-
var
|
|
5271
|
+
var ISSUES_URL3 = "https://github.com/agenticcli/shipguard/issues";
|
|
4935
5272
|
var DOCS_URL2 = "https://agenticcli.dev/docs";
|
|
4936
|
-
var REPORT_LINE = `Report this: ${
|
|
5273
|
+
var REPORT_LINE = `Report this: ${ISSUES_URL3} \xB7 Docs: ${DOCS_URL2}`;
|
|
4937
5274
|
function handleUncaughtException(error) {
|
|
4938
5275
|
const message = error instanceof Error ? error.message : String(error);
|
|
4939
5276
|
console.error(`\x1B[31m\u2717\x1B[0m Unexpected error: ${message}`);
|
|
@@ -4962,20 +5299,20 @@ process.on("uncaughtException", handleUncaughtException);
|
|
|
4962
5299
|
process.on("unhandledRejection", handleUnhandledRejection);
|
|
4963
5300
|
process.on("SIGINT", handleSignal);
|
|
4964
5301
|
process.on("SIGTERM", handleSignal);
|
|
4965
|
-
var
|
|
4966
|
-
var program = new
|
|
5302
|
+
var ISSUES_URL4 = "https://github.com/agenticcli/shipguard/issues";
|
|
5303
|
+
var program = new Command11();
|
|
4967
5304
|
var rawArgs = process.argv.slice(2);
|
|
4968
5305
|
if (rawArgs[0] === "?") {
|
|
4969
5306
|
process.argv = [process.argv[0], process.argv[1], "help"];
|
|
4970
5307
|
}
|
|
4971
5308
|
program.name("shipguard").description("CLI-first release gate for AI-built apps").version(
|
|
4972
|
-
true ? "0.
|
|
5309
|
+
true ? "0.7.1" : process.env.npm_package_version ?? "0.0.0-dev"
|
|
4973
5310
|
).helpCommand(false).addHelpText("after", `
|
|
4974
5311
|
Learn more:
|
|
4975
5312
|
Docs https://agenticcli.dev/docs
|
|
4976
5313
|
Site https://agenticcli.dev
|
|
4977
5314
|
Pricing https://agenticcli.dev/pricing
|
|
4978
|
-
Issues ${
|
|
5315
|
+
Issues ${ISSUES_URL4}`);
|
|
4979
5316
|
program.exitOverride();
|
|
4980
5317
|
function addSubcommand(cmd) {
|
|
4981
5318
|
cmd.exitOverride();
|
|
@@ -4991,8 +5328,9 @@ addSubcommand(hookCommand());
|
|
|
4991
5328
|
addSubcommand(schemaCommand());
|
|
4992
5329
|
addSubcommand(feedbackCommand());
|
|
4993
5330
|
addSubcommand(rateCommand());
|
|
5331
|
+
addSubcommand(telemetryCommand());
|
|
4994
5332
|
program.addCommand(
|
|
4995
|
-
new
|
|
5333
|
+
new Command11("help").description("Show the quickstart guide").action(() => {
|
|
4996
5334
|
const isTTY = Boolean(process.stdout.isTTY);
|
|
4997
5335
|
process.stdout.write(quickstartHelp(isTTY) + "\n");
|
|
4998
5336
|
})
|
|
@@ -5017,7 +5355,7 @@ function levenshtein(a, b) {
|
|
|
5017
5355
|
return dp[m][n];
|
|
5018
5356
|
}
|
|
5019
5357
|
function closestCommand(input) {
|
|
5020
|
-
const names = ["scan", "init", "login", "logout", "status", "history", "hook", "schema", "feedback", "rate", "help"];
|
|
5358
|
+
const names = ["scan", "init", "login", "logout", "status", "history", "hook", "schema", "feedback", "rate", "telemetry", "help"];
|
|
5021
5359
|
let best;
|
|
5022
5360
|
let bestDist = Infinity;
|
|
5023
5361
|
for (const name of names) {
|
|
@@ -5030,7 +5368,7 @@ function closestCommand(input) {
|
|
|
5030
5368
|
return bestDist <= 3 ? best : void 0;
|
|
5031
5369
|
}
|
|
5032
5370
|
(async () => {
|
|
5033
|
-
const KNOWN_COMMANDS = /* @__PURE__ */ new Set(["scan", "init", "login", "logout", "status", "history", "hook", "schema", "feedback", "rate", "help"]);
|
|
5371
|
+
const KNOWN_COMMANDS = /* @__PURE__ */ new Set(["scan", "init", "login", "logout", "status", "history", "hook", "schema", "feedback", "rate", "telemetry", "help"]);
|
|
5034
5372
|
const firstNonFlag = process.argv.slice(2).find((a) => !a.startsWith("-"));
|
|
5035
5373
|
if (firstNonFlag && firstNonFlag !== "?" && !KNOWN_COMMANDS.has(firstNonFlag)) {
|
|
5036
5374
|
const suggestion = closestCommand(firstNonFlag);
|
|
@@ -56,6 +56,7 @@ limits:
|
|
|
56
56
|
# Maximum number of files to scan \u2014 scan stops if exceeded (degraded mode)
|
|
57
57
|
maxFiles: ${DEFAULT_MAX_FILES}
|
|
58
58
|
|
|
59
|
+
# Pseudonymous usage ping (see \`shipguard telemetry status\`). Set enabled: false to opt out in this project.
|
|
59
60
|
telemetry:
|
|
60
61
|
enabled: true
|
|
61
62
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agenticcli/shipguard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "CLI-first release gate for AI-built apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cli.js",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"tsup": "^8.5.1",
|
|
33
33
|
"typescript": "^5.8.0",
|
|
34
34
|
"vitest": "^3.2.0",
|
|
35
|
-
"@agenticcli/
|
|
36
|
-
"@agenticcli/
|
|
35
|
+
"@agenticcli/matcher-contract": "0.5.1",
|
|
36
|
+
"@agenticcli/shared": "0.1.0"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"shipguard",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "tsup",
|
|
72
|
+
"build:publish": "SHIPGUARD_PUBLISHED_BUILD=1 tsup",
|
|
72
73
|
"dev": "tsup --watch",
|
|
73
74
|
"lint": "eslint src --ext .ts",
|
|
74
75
|
"test": "vitest run",
|
package/rules/free-bundle.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"description": "Offline free rule bundle compiled from rule-corpus/*/rule.yaml where bundleEligible=true and enabled=true. Governed by rules.md §4/§5/§9. Generated by scripts/build-free-bundle.ts — never hand-edited.",
|
|
4
|
-
"corpusVersion":
|
|
5
|
-
"corpusHash": "sha256:
|
|
4
|
+
"corpusVersion": 18,
|
|
5
|
+
"corpusHash": "sha256:6762d562afaa997b54e3cfdc7169a749e40b48e7680d1dd7f796358dda735cfe",
|
|
6
6
|
"ruleCount": 30,
|
|
7
|
-
"contentHash": "sha256:
|
|
7
|
+
"contentHash": "sha256:fce96295cc50f6345ad4ddee6745710ba1671156b8e04702ef21793427d399cb",
|
|
8
8
|
"rules": [
|
|
9
9
|
{
|
|
10
10
|
"id": "generic.auth.jwt-none-algorithm",
|
|
@@ -194,36 +194,56 @@
|
|
|
194
194
|
"severity": "high",
|
|
195
195
|
"confidence": "MEDIUM",
|
|
196
196
|
"action": "warn",
|
|
197
|
-
"version":
|
|
197
|
+
"version": 5,
|
|
198
198
|
"status": "experimental",
|
|
199
199
|
"cwe": [
|
|
200
|
-
"CWE-942"
|
|
200
|
+
"CWE-942",
|
|
201
|
+
"CWE-346"
|
|
201
202
|
],
|
|
202
203
|
"owasp": [
|
|
203
204
|
"A05:2021"
|
|
204
205
|
],
|
|
205
206
|
"matcher": {
|
|
206
207
|
"type": "pattern",
|
|
207
|
-
"fileGlob": "**/*.{ts,js,tsx,jsx,py,go,rb,java,yaml,yml,conf}",
|
|
208
|
+
"fileGlob": "**/*.{ts,js,tsx,jsx,py,go,rb,java,yaml,yml,conf,json,jsonc,json5}",
|
|
208
209
|
"patterns": [
|
|
209
210
|
"Access-Control-Allow-Origin['\",:\\s]+[*]",
|
|
210
211
|
"(setHeader|header|res\\.set)\\s*\\(\\s*['\"]Access-Control-Allow-Origin['\"]\\s*,\\s*['\"][*]['\"]",
|
|
211
212
|
"cors\\s*\\(\\s*\\{\\s*origin\\s*:\\s*['\"][*]['\"]",
|
|
212
|
-
"allow_origins\\s*=\\s*\\[\\s*['\"][*]['\"]"
|
|
213
|
+
"allow_origins\\s*=\\s*\\[\\s*['\"][*]['\"]",
|
|
214
|
+
"Access-Control-Allow-Origin['\"]\\s{0,40},\\s{0,40}['\"]?value['\"]?\\s{0,40}:\\s{0,40}['\"]\\*['\"]",
|
|
215
|
+
"['\"]?value['\"]?\\s{0,40}:\\s{0,40}['\"]\\*['\"]\\s{0,40},\\s{0,40}['\"]?key['\"]?\\s{0,40}:\\s{0,40}['\"]Access-Control-Allow-Origin['\"]",
|
|
216
|
+
"\\b(?:cors|enableCors)\\s{0,10}\\(\\s{0,10}\\{[^{}(]{0,200}\\borigin['\"]?\\s{0,10}:\\s{0,10}(?:true\\b|\\[[^\\[\\]]{0,100}['\"]\\*['\"])",
|
|
217
|
+
"\\b[cC]ors(?:Options?|Config|Opts?)?['\"]?\\s{0,10}[:=]\\s{0,10}\\{[^{}(]{0,120}\\borigin['\"]?\\s{0,10}:\\s{0,10}(?:true\\b|\\[[^\\[\\]]{0,100}['\"]\\*['\"])",
|
|
218
|
+
"\\bregister\\s{0,10}\\(\\s{0,10}(?:cors|fastifyCors|require\\s{0,10}\\(\\s{0,10}['\"]@fastify/cors['\"]\\s{0,10}\\))\\s{0,10},\\s{0,10}\\{[^{}(]{0,200}\\borigin['\"]?\\s{0,10}:\\s{0,10}(?:true\\b|\\[[^\\[\\]]{0,100}['\"]\\*['\"])",
|
|
219
|
+
"\\b(?:[Aa]llow[Oo]rigin|Cors)['\"]?\\s{0,10}:\\s{0,10}['\"]{1,2}\\*['\"]{1,2}",
|
|
220
|
+
"\\b[Aa]llow[Oo]rigins['\"]?\\s{0,20}:\\s{0,20}(?:\\[[^\\[\\]]{0,200}['\"]\\*['\"]|-\\s{0,10}['\"]\\*['\"])"
|
|
213
221
|
],
|
|
214
222
|
"antiPatterns": [
|
|
215
223
|
"\\btest\\b|\\bspec\\b|__fixtures__|__tests__",
|
|
216
|
-
"static|assets|cdn|fonts|images|public-api|intentional-wildcard"
|
|
224
|
+
"static|assets|cdn|fonts|images|public-api|intentional-wildcard",
|
|
225
|
+
"\\.(?:woff2?|ttf|otf|eot)\\b|font\\.css",
|
|
226
|
+
"[:,\\[]\\s{0,10}\"[^\"\\n]{0,300}[\\s(](?:Access-Control-Allow-Origin|[cC]ors[({:=]|[Aa]llow[Oo]rigins?:|origin:)",
|
|
227
|
+
":\\s{0,10}\"(?:Access-Control-Allow-Origin\\s{0,3}:|[cC]ors\\w{0,20}\\s{0,3}[({])"
|
|
217
228
|
],
|
|
218
229
|
"flags": ""
|
|
219
230
|
},
|
|
220
|
-
"explanation": "A wildcard CORS origin (Access-Control-Allow-Origin: *) was detected. For API endpoints returning user data, this allows any origin on the internet to read responses. Combined with credentials: 'include', wildcard origins are rejected by browsers — but without credentials, sensitive data is still exposed to cross-origin requests from attacker-controlled pages.\nv4 (founder ruling 2026-08-08, batch item 11): upgraded MEDIUM -> HIGH. This closes a severity disagreement the CLI's own dedup logic had been surfacing since it shipped (packages/cli/src/core/legacy-corpus-map.ts, `dedupeLegacyAgainstCorpus` doc comment): the legacy hand-written deployment check already rates the same wildcard-CORS defect `high` (packages/cli/src/checks/deployment.ts, `deployment_cors_wildcard` / `deployment_config_cors_wildcard_origin`) and dedup kept both findings because it can never silently soften a report. Canonical ruling: CORS misconfiguration is HIGH severity — nothing about the detection pattern, confidence, or action (warn) changed, only the severity label.",
|
|
231
|
+
"explanation": "A wildcard CORS origin (Access-Control-Allow-Origin: *) was detected. For API endpoints returning user data, this allows any origin on the internet to read responses. Combined with credentials: 'include', wildcard origins are rejected by browsers — but without credentials, sensitive data is still exposed to cross-origin requests from attacker-controlled pages.\nv4 (founder ruling 2026-08-08, batch item 11): upgraded MEDIUM -> HIGH. This closes a severity disagreement the CLI's own dedup logic had been surfacing since it shipped (packages/cli/src/core/legacy-corpus-map.ts, `dedupeLegacyAgainstCorpus` doc comment): the legacy hand-written deployment check already rates the same wildcard-CORS defect `high` (packages/cli/src/checks/deployment.ts, `deployment_cors_wildcard` / `deployment_config_cors_wildcard_origin`) and dedup kept both findings because it can never silently soften a report. Canonical ruling: CORS misconfiguration is HIGH severity — nothing about the detection pattern, confidence, or action (warn) changed, only the severity label.\nv5 (2026-09-30): detection widened to setups v4 missed. The rule now also covers JSON/JSONC/JSON5 files and these shapes: a cors middleware or option object whose origin is true (reflects every requesting origin, so credentialed requests from any site succeed) or is a list containing the wildcard; key/value header entries such as the Vercel vercel.json and Firebase Hosting firebase.json headers arrays; and AWS API Gateway (SAM AllowOrigin, HTTP API AllowOrigins, method response header parameters). Severity, confidence, action (warn) and tier are unchanged. False-positive guards: origin true is matched only inside cors()/enableCors()/register(cors) calls or cors option objects, never on a bare origin key; JSON string values that merely describe the header are ignored; font-file rules and the existing test/static markers still suppress.",
|
|
221
232
|
"recommendation": "Replace the wildcard with an explicit allowlist of trusted origins. Use environment variables for origin configuration (ALLOWED_ORIGINS) so production and development settings can differ. Audit whether this endpoint requires CORS at all.",
|
|
222
233
|
"fix": "Replace `'*'` with `process.env.ALLOWED_ORIGIN` and validate against an allowlist.",
|
|
223
234
|
"findingType": "vulnerability",
|
|
224
235
|
"aiCodeTarget": true,
|
|
225
236
|
"references": [
|
|
226
|
-
"https://cwe.mitre.org/data/definitions/942.html"
|
|
237
|
+
"https://cwe.mitre.org/data/definitions/942.html",
|
|
238
|
+
"https://cwe.mitre.org/data/definitions/346.html",
|
|
239
|
+
"https://github.com/expressjs/cors#configuration-options",
|
|
240
|
+
"https://github.com/fastify/fastify-cors#options",
|
|
241
|
+
"https://vercel.com/docs/project-configuration",
|
|
242
|
+
"https://firebase.google.com/docs/hosting/full-config#headers",
|
|
243
|
+
"https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-api-corsconfiguration.html",
|
|
244
|
+
"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html",
|
|
245
|
+
"https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html",
|
|
246
|
+
"https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin"
|
|
227
247
|
]
|
|
228
248
|
},
|
|
229
249
|
{
|