@agenticcli/shipguard 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/dist/checksum-manifest.json +5 -5
- package/dist/{chunk-KYVEU6H4.js → chunk-BVWCA2VJ.js} +11 -2
- package/dist/cli-facts.json +5 -5
- package/dist/cli.js +477 -140
- package/dist/{config-generator-2AC37XZ2.js → config-generator-2BVUZGEU.js} +1 -0
- package/dist/{pro-scanner-3DY7KU5C.js → pro-scanner-SFOR7SGK.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": "a841f9b4db785bb555205bf73de0f3a1390a5e6676d17f5125e1e3898f3cc55b",
|
|
3
|
+
"auth": "a841f9b4db785bb555205bf73de0f3a1390a5e6676d17f5125e1e3898f3cc55b",
|
|
4
|
+
"database": "a841f9b4db785bb555205bf73de0f3a1390a5e6676d17f5125e1e3898f3cc55b",
|
|
5
|
+
"deployment": "a841f9b4db785bb555205bf73de0f3a1390a5e6676d17f5125e1e3898f3cc55b",
|
|
6
|
+
"payments": "a841f9b4db785bb555205bf73de0f3a1390a5e6676d17f5125e1e3898f3cc55b"
|
|
7
7
|
}
|
|
@@ -2467,6 +2467,15 @@ function findLine(content, pattern) {
|
|
|
2467
2467
|
}
|
|
2468
2468
|
return void 0;
|
|
2469
2469
|
}
|
|
2470
|
+
function findMatchStartLine(content, pattern) {
|
|
2471
|
+
const m = pattern.exec(content);
|
|
2472
|
+
if (!m) return void 0;
|
|
2473
|
+
let line = 1;
|
|
2474
|
+
for (let i = 0; i < m.index; i++) {
|
|
2475
|
+
if (content.charCodeAt(i) === 10) line++;
|
|
2476
|
+
}
|
|
2477
|
+
return line;
|
|
2478
|
+
}
|
|
2470
2479
|
function findLineStr(content, literal) {
|
|
2471
2480
|
const lines = content.split("\n");
|
|
2472
2481
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -2479,7 +2488,7 @@ function checkNextConfig(file) {
|
|
|
2479
2488
|
const { content, relativePath } = file;
|
|
2480
2489
|
if (RE_CORS_NEXT_VALUE.test(content) || RE_CORS_NEXT_HEADER.test(content)) {
|
|
2481
2490
|
const matchedPattern = RE_CORS_NEXT_VALUE.test(content) ? RE_CORS_NEXT_VALUE : RE_CORS_NEXT_HEADER;
|
|
2482
|
-
const line =
|
|
2491
|
+
const line = findMatchStartLine(content, matchedPattern);
|
|
2483
2492
|
findings.push({
|
|
2484
2493
|
id: makeId("cors_wildcard"),
|
|
2485
2494
|
title: "Permissive CORS: Access-Control-Allow-Origin set to wildcard (*)",
|
|
@@ -2786,7 +2795,7 @@ function checkGeneralConfigs(file) {
|
|
|
2786
2795
|
const { content, relativePath } = file;
|
|
2787
2796
|
const corsRe = JSON_FAMILY_EXTENSIONS.has(extname(relativePath).toLowerCase()) ? RE_CONFIG_CORS_WILDCARD_JSON : RE_CONFIG_CORS_WILDCARD;
|
|
2788
2797
|
if (corsRe.test(content)) {
|
|
2789
|
-
const line =
|
|
2798
|
+
const line = findMatchStartLine(content, corsRe);
|
|
2790
2799
|
findings.push({
|
|
2791
2800
|
id: makeId("config_cors_wildcard_origin"),
|
|
2792
2801
|
title: `CORS origin wildcard (*) detected in ${relativePath}`,
|
package/dist/cli-facts.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.7.0",
|
|
3
3
|
"packageName": "@agenticcli/shipguard",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"licenseDisplay": "ELv2",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"postgresql.auth.trust-auth-method"
|
|
84
84
|
],
|
|
85
85
|
"bundledCorpusRuleCount": 30,
|
|
86
|
-
"corpusVersion":
|
|
87
|
-
"bundleContentHash": "sha256:
|
|
86
|
+
"corpusVersion": 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-01T12:43:43.901Z"
|
|
146
146
|
}
|
package/dist/cli.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
saveCredentials,
|
|
22
22
|
secretsCheck,
|
|
23
23
|
validateBundleCompile
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-BVWCA2VJ.js";
|
|
25
25
|
import {
|
|
26
26
|
DEFAULT_MAX_FILES,
|
|
27
27
|
DEFAULT_MAX_FILE_SIZE_BYTES,
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
} from "./chunk-MPQ42F54.js";
|
|
38
38
|
|
|
39
39
|
// src/cli.ts
|
|
40
|
-
import { Command as
|
|
40
|
+
import { Command as Command11, CommanderError } from "commander";
|
|
41
41
|
|
|
42
42
|
// src/commands/init.ts
|
|
43
43
|
import { Command } from "commander";
|
|
@@ -180,8 +180,8 @@ function initCommand() {
|
|
|
180
180
|
|
|
181
181
|
// src/commands/scan.ts
|
|
182
182
|
import { Command as Command2 } from "commander";
|
|
183
|
-
import { existsSync as
|
|
184
|
-
import { join as
|
|
183
|
+
import { existsSync as existsSync6 } from "fs";
|
|
184
|
+
import { join as join7, resolve as resolve4 } from "path";
|
|
185
185
|
|
|
186
186
|
// src/core/scanner.ts
|
|
187
187
|
import { readFile as readFile2, stat, realpath } from "fs/promises";
|
|
@@ -484,10 +484,10 @@ function getChangedFiles(dir) {
|
|
|
484
484
|
var free_bundle_default = {
|
|
485
485
|
schemaVersion: 1,
|
|
486
486
|
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:
|
|
487
|
+
corpusVersion: 18,
|
|
488
|
+
corpusHash: "sha256:6762d562afaa997b54e3cfdc7169a749e40b48e7680d1dd7f796358dda735cfe",
|
|
489
489
|
ruleCount: 30,
|
|
490
|
-
contentHash: "sha256:
|
|
490
|
+
contentHash: "sha256:fce96295cc50f6345ad4ddee6745710ba1671156b8e04702ef21793427d399cb",
|
|
491
491
|
rules: [
|
|
492
492
|
{
|
|
493
493
|
id: "generic.auth.jwt-none-algorithm",
|
|
@@ -677,36 +677,56 @@ var free_bundle_default = {
|
|
|
677
677
|
severity: "high",
|
|
678
678
|
confidence: "MEDIUM",
|
|
679
679
|
action: "warn",
|
|
680
|
-
version:
|
|
680
|
+
version: 5,
|
|
681
681
|
status: "experimental",
|
|
682
682
|
cwe: [
|
|
683
|
-
"CWE-942"
|
|
683
|
+
"CWE-942",
|
|
684
|
+
"CWE-346"
|
|
684
685
|
],
|
|
685
686
|
owasp: [
|
|
686
687
|
"A05:2021"
|
|
687
688
|
],
|
|
688
689
|
matcher: {
|
|
689
690
|
type: "pattern",
|
|
690
|
-
fileGlob: "**/*.{ts,js,tsx,jsx,py,go,rb,java,yaml,yml,conf}",
|
|
691
|
+
fileGlob: "**/*.{ts,js,tsx,jsx,py,go,rb,java,yaml,yml,conf,json,jsonc,json5}",
|
|
691
692
|
patterns: [
|
|
692
693
|
`Access-Control-Allow-Origin['",:\\s]+[*]`,
|
|
693
694
|
`(setHeader|header|res\\.set)\\s*\\(\\s*['"]Access-Control-Allow-Origin['"]\\s*,\\s*['"][*]['"]`,
|
|
694
695
|
`cors\\s*\\(\\s*\\{\\s*origin\\s*:\\s*['"][*]['"]`,
|
|
695
|
-
`allow_origins\\s*=\\s*\\[\\s*['"][*]['"]
|
|
696
|
+
`allow_origins\\s*=\\s*\\[\\s*['"][*]['"]`,
|
|
697
|
+
`Access-Control-Allow-Origin['"]\\s{0,40},\\s{0,40}['"]?value['"]?\\s{0,40}:\\s{0,40}['"]\\*['"]`,
|
|
698
|
+
`['"]?value['"]?\\s{0,40}:\\s{0,40}['"]\\*['"]\\s{0,40},\\s{0,40}['"]?key['"]?\\s{0,40}:\\s{0,40}['"]Access-Control-Allow-Origin['"]`,
|
|
699
|
+
`\\b(?:cors|enableCors)\\s{0,10}\\(\\s{0,10}\\{[^{}(]{0,200}\\borigin['"]?\\s{0,10}:\\s{0,10}(?:true\\b|\\[[^\\[\\]]{0,100}['"]\\*['"])`,
|
|
700
|
+
`\\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}['"]\\*['"])`,
|
|
701
|
+
`\\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}['"]\\*['"])`,
|
|
702
|
+
`\\b(?:[Aa]llow[Oo]rigin|Cors)['"]?\\s{0,10}:\\s{0,10}['"]{1,2}\\*['"]{1,2}`,
|
|
703
|
+
`\\b[Aa]llow[Oo]rigins['"]?\\s{0,20}:\\s{0,20}(?:\\[[^\\[\\]]{0,200}['"]\\*['"]|-\\s{0,10}['"]\\*['"])`
|
|
696
704
|
],
|
|
697
705
|
antiPatterns: [
|
|
698
706
|
"\\btest\\b|\\bspec\\b|__fixtures__|__tests__",
|
|
699
|
-
"static|assets|cdn|fonts|images|public-api|intentional-wildcard"
|
|
707
|
+
"static|assets|cdn|fonts|images|public-api|intentional-wildcard",
|
|
708
|
+
"\\.(?:woff2?|ttf|otf|eot)\\b|font\\.css",
|
|
709
|
+
'[:,\\[]\\s{0,10}"[^"\\n]{0,300}[\\s(](?:Access-Control-Allow-Origin|[cC]ors[({:=]|[Aa]llow[Oo]rigins?:|origin:)',
|
|
710
|
+
':\\s{0,10}"(?:Access-Control-Allow-Origin\\s{0,3}:|[cC]ors\\w{0,20}\\s{0,3}[({])'
|
|
700
711
|
],
|
|
701
712
|
flags: ""
|
|
702
713
|
},
|
|
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.",
|
|
714
|
+
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
715
|
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
716
|
fix: "Replace `'*'` with `process.env.ALLOWED_ORIGIN` and validate against an allowlist.",
|
|
706
717
|
findingType: "vulnerability",
|
|
707
718
|
aiCodeTarget: true,
|
|
708
719
|
references: [
|
|
709
|
-
"https://cwe.mitre.org/data/definitions/942.html"
|
|
720
|
+
"https://cwe.mitre.org/data/definitions/942.html",
|
|
721
|
+
"https://cwe.mitre.org/data/definitions/346.html",
|
|
722
|
+
"https://github.com/expressjs/cors#configuration-options",
|
|
723
|
+
"https://github.com/fastify/fastify-cors#options",
|
|
724
|
+
"https://vercel.com/docs/project-configuration",
|
|
725
|
+
"https://firebase.google.com/docs/hosting/full-config#headers",
|
|
726
|
+
"https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-api-corsconfiguration.html",
|
|
727
|
+
"https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html",
|
|
728
|
+
"https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html",
|
|
729
|
+
"https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin"
|
|
710
730
|
]
|
|
711
731
|
},
|
|
712
732
|
{
|
|
@@ -2533,8 +2553,9 @@ function quickstartHelp(isTTY) {
|
|
|
2533
2553
|
lines.push(` ${chalk.cyan("status")} Show auth status and credits`);
|
|
2534
2554
|
lines.push(` ${chalk.cyan("hook")} ${chalk.dim("--target")} Install the gate at the merge boundary`);
|
|
2535
2555
|
lines.push(` ${chalk.cyan("schema")} ${chalk.dim("--json")} Print the machine-readable scan contract`);
|
|
2536
|
-
lines.push(` ${chalk.cyan("feedback")}
|
|
2556
|
+
lines.push(` ${chalk.cyan("feedback")} Where to send feedback (GitHub issues)`);
|
|
2537
2557
|
lines.push(` ${chalk.cyan("rate")} ${chalk.dim("<id> up|down")} Rate a rule finding`);
|
|
2558
|
+
lines.push(` ${chalk.cyan("telemetry")} ${chalk.dim("status")} Show or change the pseudonymous usage ping`);
|
|
2538
2559
|
lines.push(` ${chalk.cyan("help")} ${chalk.dim("/ ?")} Show this screen`);
|
|
2539
2560
|
lines.push("");
|
|
2540
2561
|
lines.push(chalk.bold(" Exit codes (verdict-neutral \u2014 read the JSON for the verdict):"));
|
|
@@ -2566,8 +2587,9 @@ function quickstartHelp(isTTY) {
|
|
|
2566
2587
|
lines.push(" status Auth status + credits");
|
|
2567
2588
|
lines.push(" hook --target Install the gate at the merge boundary");
|
|
2568
2589
|
lines.push(" schema --json Machine-readable scan contract");
|
|
2569
|
-
lines.push(" feedback
|
|
2590
|
+
lines.push(" feedback Where to send feedback (GitHub issues)");
|
|
2570
2591
|
lines.push(" rate <id> up|down Rate a finding");
|
|
2592
|
+
lines.push(" telemetry status|enable|disable|reset Pseudonymous usage ping");
|
|
2571
2593
|
lines.push(" help / ? Show this screen");
|
|
2572
2594
|
lines.push("");
|
|
2573
2595
|
lines.push(" Exit codes: 0=completed (verdict in JSON) 1=blocked (--strict only: blocking findings or unfinished scan) 2=config-error 3=runtime-error");
|
|
@@ -2858,8 +2880,8 @@ function welcomeBanner(configDir) {
|
|
|
2858
2880
|
empty,
|
|
2859
2881
|
bannerLine(`Docs: ${chalk.underline(DOCS_URL)}`),
|
|
2860
2882
|
empty,
|
|
2861
|
-
bannerLine(chalk.dim("
|
|
2862
|
-
bannerLine(chalk.dim(`Details: ${chalk.underline("agenticcli.dev/docs#telemetry")}`)),
|
|
2883
|
+
bannerLine(chalk.dim("Pseudonymous usage ping \u2014 opt out: shipguard telemetry disable")),
|
|
2884
|
+
bannerLine(chalk.dim(`or SHIPGUARD_TELEMETRY=0 \xB7 Details: ${chalk.underline("agenticcli.dev/docs#telemetry")}`)),
|
|
2863
2885
|
bottom,
|
|
2864
2886
|
""
|
|
2865
2887
|
].join("\n");
|
|
@@ -3718,38 +3740,320 @@ async function recordScanHistory(input) {
|
|
|
3718
3740
|
}
|
|
3719
3741
|
|
|
3720
3742
|
// src/core/telemetry.ts
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3743
|
+
import { randomUUID as randomUUID6 } from "crypto";
|
|
3744
|
+
|
|
3745
|
+
// src/core/telemetry-config.ts
|
|
3746
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
3747
|
+
import { chmodSync, existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
3748
|
+
import { homedir as homedir2 } from "os";
|
|
3749
|
+
import { join as join6 } from "path";
|
|
3750
|
+
import YAML2 from "yaml";
|
|
3751
|
+
var CONFIG_FILE = "telemetry.json";
|
|
3752
|
+
var NOTICE_MARKER = "telemetry-notice-shown";
|
|
3753
|
+
function getConfigDir() {
|
|
3754
|
+
return join6(homedir2(), ".config", "shipguard");
|
|
3755
|
+
}
|
|
3756
|
+
function configFilePath(dir = getConfigDir()) {
|
|
3757
|
+
return join6(dir, CONFIG_FILE);
|
|
3758
|
+
}
|
|
3759
|
+
function readUserConfig(dir = getConfigDir()) {
|
|
3760
|
+
const file = configFilePath(dir);
|
|
3761
|
+
try {
|
|
3762
|
+
if (!existsSync5(file)) return {};
|
|
3763
|
+
const parsed = JSON.parse(readFileSync2(file, "utf-8"));
|
|
3764
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
3765
|
+
} catch (err) {
|
|
3766
|
+
logger.debug(`telemetry: ignoring unreadable ${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3767
|
+
return {};
|
|
3768
|
+
}
|
|
3769
|
+
}
|
|
3770
|
+
function userConfigUnreadable(dir = getConfigDir()) {
|
|
3771
|
+
const file = configFilePath(dir);
|
|
3772
|
+
try {
|
|
3773
|
+
if (!existsSync5(file)) return false;
|
|
3774
|
+
const parsed = JSON.parse(readFileSync2(file, "utf-8"));
|
|
3775
|
+
return !(parsed && typeof parsed === "object" && !Array.isArray(parsed));
|
|
3776
|
+
} catch {
|
|
3777
|
+
return true;
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
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}$/;
|
|
3781
|
+
function writeConfig(dir, next) {
|
|
3782
|
+
const file = configFilePath(dir);
|
|
3783
|
+
mkdirSync4(dir, { recursive: true, mode: 448 });
|
|
3784
|
+
writeFileSync3(file, JSON.stringify(next, null, 2) + "\n", { encoding: "utf-8", mode: 384 });
|
|
3785
|
+
chmodSync(file, 384);
|
|
3786
|
+
return file;
|
|
3787
|
+
}
|
|
3788
|
+
function readInstallId(dir = getConfigDir()) {
|
|
3789
|
+
const id = readUserConfig(dir).installId;
|
|
3790
|
+
return typeof id === "string" && UUID_V4.test(id) ? id : void 0;
|
|
3791
|
+
}
|
|
3792
|
+
function getOrCreateInstallId(dir = getConfigDir()) {
|
|
3793
|
+
const existing = readInstallId(dir);
|
|
3794
|
+
if (existing) return existing;
|
|
3795
|
+
try {
|
|
3796
|
+
const installId = randomUUID5();
|
|
3797
|
+
writeConfig(dir, { ...readUserConfig(dir), installId });
|
|
3798
|
+
return installId;
|
|
3799
|
+
} catch (err) {
|
|
3800
|
+
logger.debug(`telemetry: could not persist the install id: ${err instanceof Error ? err.message : String(err)}`);
|
|
3801
|
+
return void 0;
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
function resetInstallId(dir = getConfigDir()) {
|
|
3805
|
+
const cfg = readUserConfig(dir);
|
|
3806
|
+
const hadId = "installId" in cfg;
|
|
3807
|
+
const oldId = readInstallId(dir);
|
|
3808
|
+
if (hadId) {
|
|
3809
|
+
delete cfg.installId;
|
|
3810
|
+
writeConfig(dir, cfg);
|
|
3811
|
+
}
|
|
3812
|
+
return { hadId, oldId };
|
|
3813
|
+
}
|
|
3814
|
+
function writeUserEnabled(dir, enabled) {
|
|
3815
|
+
return writeConfig(dir, { ...readUserConfig(dir), enabled });
|
|
3816
|
+
}
|
|
3817
|
+
function noticeShown(dir = getConfigDir()) {
|
|
3818
|
+
return existsSync5(join6(dir, NOTICE_MARKER));
|
|
3819
|
+
}
|
|
3820
|
+
function markNoticeShown(dir = getConfigDir()) {
|
|
3821
|
+
try {
|
|
3822
|
+
mkdirSync4(dir, { recursive: true, mode: 448 });
|
|
3823
|
+
writeFileSync3(join6(dir, NOTICE_MARKER), "1\n", { encoding: "utf-8", mode: 384 });
|
|
3824
|
+
} catch (err) {
|
|
3825
|
+
logger.debug(`telemetry: could not persist the notice marker: ${err instanceof Error ? err.message : String(err)}`);
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
var FALSE_LIKE = /* @__PURE__ */ new Set(["false", "off", "no", "0"]);
|
|
3829
|
+
var GENERATED_CONFIG_FILE = ".shipguard.yml";
|
|
3830
|
+
function policyTelemetryEnabled(policy) {
|
|
3831
|
+
if (!policy || typeof policy !== "object") return void 0;
|
|
3832
|
+
const t = policy.telemetry;
|
|
3833
|
+
if (!t || typeof t !== "object") return void 0;
|
|
3834
|
+
const v = t.enabled;
|
|
3835
|
+
if (v === false || v === 0) return false;
|
|
3836
|
+
if (typeof v === "string" && FALSE_LIKE.has(v.trim().toLowerCase())) return false;
|
|
3837
|
+
if (v === true) return true;
|
|
3838
|
+
return void 0;
|
|
3839
|
+
}
|
|
3840
|
+
function readYamlToggle(file) {
|
|
3841
|
+
try {
|
|
3842
|
+
if (!existsSync5(file)) return void 0;
|
|
3843
|
+
return policyTelemetryEnabled(YAML2.parse(readFileSync2(file, "utf-8")));
|
|
3844
|
+
} catch (err) {
|
|
3845
|
+
logger.debug(`telemetry: ignoring unreadable ${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3846
|
+
return void 0;
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
function projectTelemetryEnabled(input) {
|
|
3850
|
+
const values = [policyTelemetryEnabled(input.policy)];
|
|
3851
|
+
if (input.projectDir) {
|
|
3852
|
+
if (input.policy === void 0) values.push(readYamlToggle(join6(input.projectDir, DEFAULT_POLICY_PATH)));
|
|
3853
|
+
values.push(readYamlToggle(join6(input.projectDir, GENERATED_CONFIG_FILE)));
|
|
3854
|
+
}
|
|
3855
|
+
if (values.includes(false)) return false;
|
|
3856
|
+
if (values.includes(true)) return true;
|
|
3857
|
+
return void 0;
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3860
|
+
// src/core/telemetry.ts
|
|
3861
|
+
var IS_PUBLISHED_BUILD = true;
|
|
3862
|
+
function getProvenance(published = IS_PUBLISHED_BUILD) {
|
|
3863
|
+
return published ? "published" : "dev";
|
|
3864
|
+
}
|
|
3865
|
+
var PROD_TELEMETRY_ENDPOINT = "https://cheery-toucan-348.convex.site/cli-telemetry";
|
|
3866
|
+
function isLoopbackUrl(raw2) {
|
|
3867
|
+
if (!raw2) return false;
|
|
3868
|
+
try {
|
|
3869
|
+
const host = new URL(raw2).hostname;
|
|
3870
|
+
return host === "127.0.0.1" || host === "localhost" || host === "[::1]" || host === "::1";
|
|
3871
|
+
} catch {
|
|
3872
|
+
return false;
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
function resolveEndpoint(published = IS_PUBLISHED_BUILD, env = process.env) {
|
|
3876
|
+
const override = env.SHIPGUARD_TELEMETRY_URL;
|
|
3877
|
+
if (published) return override || PROD_TELEMETRY_ENDPOINT;
|
|
3878
|
+
return isLoopbackUrl(override) ? override : null;
|
|
3879
|
+
}
|
|
3880
|
+
var ALLOWED_KEYS = [
|
|
3881
|
+
"schema",
|
|
3882
|
+
"eventId",
|
|
3883
|
+
"installId",
|
|
3884
|
+
"cliVersion",
|
|
3885
|
+
"provenance",
|
|
3886
|
+
"verdict",
|
|
3887
|
+
"durationBucket",
|
|
3888
|
+
"ci"
|
|
3889
|
+
];
|
|
3890
|
+
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})?$/;
|
|
3891
|
+
var DURATION_BUCKETS = ["lt1s", "1to5s", "5to30s", "gt30s"];
|
|
3892
|
+
function durationBucket(ms) {
|
|
3893
|
+
if (!(ms >= 1e3)) return "lt1s";
|
|
3894
|
+
if (ms < 5e3) return "1to5s";
|
|
3895
|
+
if (ms < 3e4) return "5to30s";
|
|
3896
|
+
return "gt30s";
|
|
3897
|
+
}
|
|
3898
|
+
var CI_PROVIDER_VARS = [
|
|
3899
|
+
"GITHUB_ACTIONS",
|
|
3900
|
+
"GITLAB_CI",
|
|
3901
|
+
"CIRCLECI",
|
|
3902
|
+
"TRAVIS",
|
|
3903
|
+
"BUILDKITE",
|
|
3904
|
+
"JENKINS_URL",
|
|
3905
|
+
"TF_BUILD",
|
|
3906
|
+
"TEAMCITY_VERSION",
|
|
3907
|
+
"BITBUCKET_BUILD_NUMBER",
|
|
3908
|
+
"APPVEYOR",
|
|
3909
|
+
"DRONE",
|
|
3910
|
+
"CODEBUILD_BUILD_ID",
|
|
3911
|
+
"SEMAPHORE",
|
|
3912
|
+
"BUILD_BUILDID",
|
|
3913
|
+
"CF_BUILD_ID",
|
|
3914
|
+
"NETLIFY",
|
|
3915
|
+
"VERCEL",
|
|
3916
|
+
"WOODPECKER",
|
|
3917
|
+
"BUDDY",
|
|
3918
|
+
"HUDSON_URL"
|
|
3919
|
+
];
|
|
3920
|
+
function detectCi(env = process.env) {
|
|
3921
|
+
const ci = env.CI;
|
|
3922
|
+
if (ci !== void 0 && !["", "0", "false"].includes(ci.trim().toLowerCase())) return true;
|
|
3923
|
+
return CI_PROVIDER_VARS.some((k) => env[k] !== void 0);
|
|
3924
|
+
}
|
|
3925
|
+
function isTruthyOff(v, offValues) {
|
|
3926
|
+
return v !== void 0 && offValues.includes(v.trim().toLowerCase());
|
|
3927
|
+
}
|
|
3928
|
+
function envOptOut(env) {
|
|
3929
|
+
if (isTruthyOff(env.SHIPGUARD_TELEMETRY, ["0", "false"])) return "env:SHIPGUARD_TELEMETRY";
|
|
3930
|
+
if (isTruthyOff(env.DO_NOT_TRACK, ["1", "true"])) return "env:DO_NOT_TRACK";
|
|
3931
|
+
return null;
|
|
3725
3932
|
}
|
|
3726
3933
|
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
|
-
|
|
3934
|
+
const { schema, eventId, installId, cliVersion, provenance, verdict, durationBucket: durationBucket2, ci } = input;
|
|
3935
|
+
return { schema, eventId, installId, cliVersion, provenance, verdict, durationBucket: durationBucket2, ci };
|
|
3936
|
+
}
|
|
3937
|
+
function validatePayload(payload) {
|
|
3938
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return false;
|
|
3939
|
+
const obj = payload;
|
|
3940
|
+
const keys = Object.keys(obj);
|
|
3941
|
+
if (keys.length !== ALLOWED_KEYS.length) return false;
|
|
3942
|
+
for (const k of ALLOWED_KEYS) if (!(k in obj)) return false;
|
|
3943
|
+
if (obj.schema !== 2) return false;
|
|
3944
|
+
if (typeof obj.eventId !== "string" || !UUID_V4.test(obj.eventId)) return false;
|
|
3945
|
+
if (typeof obj.ci !== "boolean") return false;
|
|
3946
|
+
if (obj.ci) {
|
|
3947
|
+
if (obj.installId !== null) return false;
|
|
3948
|
+
} else if (typeof obj.installId !== "string" || !UUID_V4.test(obj.installId)) {
|
|
3949
|
+
return false;
|
|
3950
|
+
}
|
|
3951
|
+
if (typeof obj.cliVersion !== "string" || obj.cliVersion.length > 40 || !VERSION_RE.test(obj.cliVersion)) return false;
|
|
3952
|
+
if (obj.provenance !== "published" && obj.provenance !== "dev") return false;
|
|
3953
|
+
if (!["safe", "review", "blocked", "error"].includes(obj.verdict)) return false;
|
|
3954
|
+
if (!DURATION_BUCKETS.includes(obj.durationBucket)) return false;
|
|
3955
|
+
return true;
|
|
3956
|
+
}
|
|
3957
|
+
function decideTelemetry(input = {}) {
|
|
3958
|
+
const env = input.env ?? process.env;
|
|
3959
|
+
const envOff = envOptOut(env);
|
|
3960
|
+
if (envOff) return { enabled: false, source: envOff };
|
|
3961
|
+
const dir = input.configDir ?? getConfigDir();
|
|
3962
|
+
if (userConfigUnreadable(dir) || readUserConfig(dir).enabled === false) {
|
|
3963
|
+
return { enabled: false, source: "user-config" };
|
|
3964
|
+
}
|
|
3965
|
+
if (projectTelemetryEnabled({ policy: input.policy, projectDir: input.projectDir }) === false) return { enabled: false, source: "project-policy" };
|
|
3966
|
+
return { enabled: true, source: "default" };
|
|
3967
|
+
}
|
|
3968
|
+
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";
|
|
3969
|
+
var PING_WAIT_MS = 1500;
|
|
3970
|
+
var FETCH_TIMEOUT_MS = 1e3;
|
|
3971
|
+
function debugEnabled(env) {
|
|
3972
|
+
const v = env.SHIPGUARD_TELEMETRY_DEBUG;
|
|
3973
|
+
return Boolean(v) && v !== "0";
|
|
3974
|
+
}
|
|
3975
|
+
function sendTelemetry(input, opts = {}) {
|
|
3976
|
+
try {
|
|
3977
|
+
const env = opts.env ?? process.env;
|
|
3978
|
+
const configDir = opts.configDir ?? getConfigDir();
|
|
3979
|
+
const published = opts.published ?? IS_PUBLISHED_BUILD;
|
|
3980
|
+
const debug = debugEnabled(env);
|
|
3981
|
+
const decision = decideTelemetry({ env, configDir, policy: opts.policy, projectDir: opts.projectDir });
|
|
3982
|
+
if (!decision.enabled) {
|
|
3983
|
+
if (debug) process.stderr.write(`[shipguard:telemetry] disabled (${decision.source}); nothing would be sent
|
|
3984
|
+
`);
|
|
3985
|
+
return Promise.resolve();
|
|
3744
3986
|
}
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3987
|
+
const endpoint = resolveEndpoint(published, env);
|
|
3988
|
+
const ci = detectCi(env);
|
|
3989
|
+
const base = {
|
|
3990
|
+
schema: 2,
|
|
3991
|
+
eventId: randomUUID6(),
|
|
3992
|
+
cliVersion: input.cliVersion,
|
|
3993
|
+
provenance: getProvenance(published),
|
|
3994
|
+
verdict: input.verdict,
|
|
3995
|
+
durationBucket: durationBucket(input.durationMs),
|
|
3996
|
+
ci
|
|
3997
|
+
};
|
|
3998
|
+
if (debug) {
|
|
3999
|
+
const stored = ci ? null : readInstallId(configDir);
|
|
4000
|
+
const installId2 = ci ? null : stored ?? randomUUID6();
|
|
4001
|
+
const note = !ci && !stored ? " (installId is a preview: none saved yet, one is created on the first real ping)" : "";
|
|
4002
|
+
process.stderr.write(
|
|
4003
|
+
`[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}
|
|
4004
|
+
`
|
|
4005
|
+
);
|
|
4006
|
+
return Promise.resolve();
|
|
4007
|
+
}
|
|
4008
|
+
if (endpoint === null) {
|
|
4009
|
+
logger.debug("telemetry: dev build, not sending (set a loopback SHIPGUARD_TELEMETRY_URL to capture)");
|
|
4010
|
+
return Promise.resolve();
|
|
4011
|
+
}
|
|
4012
|
+
if (!noticeShown(configDir)) {
|
|
4013
|
+
process.stderr.write(NOTICE_TEXT + "\n");
|
|
4014
|
+
markNoticeShown(configDir);
|
|
4015
|
+
}
|
|
4016
|
+
const installId = ci ? null : getOrCreateInstallId(configDir) ?? void 0;
|
|
4017
|
+
if (installId === void 0) {
|
|
4018
|
+
logger.debug("telemetry: no install id could be saved; not sending");
|
|
4019
|
+
return Promise.resolve();
|
|
4020
|
+
}
|
|
4021
|
+
const payload = buildPayload({ ...base, installId });
|
|
4022
|
+
if (!validatePayload(payload)) {
|
|
4023
|
+
logger.debug("telemetry: payload failed validation; not sending");
|
|
4024
|
+
return Promise.resolve();
|
|
4025
|
+
}
|
|
4026
|
+
const body = JSON.stringify(payload);
|
|
4027
|
+
const controller = new AbortController();
|
|
4028
|
+
const abortTimer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
4029
|
+
const request = fetch(endpoint, {
|
|
4030
|
+
method: "POST",
|
|
4031
|
+
headers: { "Content-Type": "application/json" },
|
|
4032
|
+
body,
|
|
4033
|
+
signal: controller.signal
|
|
4034
|
+
}).then(
|
|
4035
|
+
() => void 0,
|
|
4036
|
+
(err) => {
|
|
4037
|
+
logger.debug(`telemetry: ping failed (ignored): ${err instanceof Error ? err.message : String(err)}`);
|
|
4038
|
+
}
|
|
4039
|
+
).finally(() => clearTimeout(abortTimer));
|
|
4040
|
+
return new Promise((resolve7) => {
|
|
4041
|
+
const cap = setTimeout(resolve7, PING_WAIT_MS);
|
|
4042
|
+
cap.unref();
|
|
4043
|
+
void request.then(() => {
|
|
4044
|
+
clearTimeout(cap);
|
|
4045
|
+
resolve7();
|
|
4046
|
+
});
|
|
4047
|
+
});
|
|
4048
|
+
} catch (err) {
|
|
4049
|
+
logger.debug(`telemetry: skipped after error (ignored): ${err instanceof Error ? err.message : String(err)}`);
|
|
4050
|
+
return Promise.resolve();
|
|
4051
|
+
}
|
|
3748
4052
|
}
|
|
3749
4053
|
|
|
3750
4054
|
// src/commands/scan.ts
|
|
3751
4055
|
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.
|
|
4056
|
+
var CLI_VERSION = true ? "0.7.0" : process.env.npm_package_version ?? "0.0.0-dev";
|
|
3753
4057
|
function resolveExitCode(opts) {
|
|
3754
4058
|
if (opts.strict && (opts.blockingCount > 0 || opts.degraded === true || opts.recommendation === "DO_NOT_SHIP")) {
|
|
3755
4059
|
return EXIT_CODES.BLOCKED;
|
|
@@ -3775,7 +4079,7 @@ function proFetchActionHint(code, retryAfterSeconds) {
|
|
|
3775
4079
|
}
|
|
3776
4080
|
}
|
|
3777
4081
|
function isProjectRoot(dir) {
|
|
3778
|
-
return
|
|
4082
|
+
return existsSync6(join7(dir, "package.json")) || existsSync6(join7(dir, ".git"));
|
|
3779
4083
|
}
|
|
3780
4084
|
function scanCommand() {
|
|
3781
4085
|
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 +4219,8 @@ async function runScan(ctx) {
|
|
|
3915
4219
|
logger.info("Detecting stack...");
|
|
3916
4220
|
}
|
|
3917
4221
|
try {
|
|
3918
|
-
const { fetchProRules } = await import("./pro-scanner-
|
|
3919
|
-
const { hasConfig, generateConfig } = await import("./config-generator-
|
|
4222
|
+
const { fetchProRules } = await import("./pro-scanner-SFOR7SGK.js");
|
|
4223
|
+
const { hasConfig, generateConfig } = await import("./config-generator-2BVUZGEU.js");
|
|
3920
4224
|
const frameworks = detectedFrameworks;
|
|
3921
4225
|
if (!hasConfig(cwd)) {
|
|
3922
4226
|
const configPath = generateConfig(cwd, frameworks);
|
|
@@ -4173,39 +4477,20 @@ async function runScan(ctx) {
|
|
|
4173
4477
|
reportPaths
|
|
4174
4478
|
));
|
|
4175
4479
|
}
|
|
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
|
-
}
|
|
4480
|
+
let telemetryDone = void 0;
|
|
4198
4481
|
try {
|
|
4199
4482
|
const elapsedMs = Date.now() - startTime;
|
|
4200
4483
|
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
|
-
|
|
4484
|
+
telemetryDone = sendTelemetry(
|
|
4485
|
+
{
|
|
4486
|
+
cliVersion: CLI_VERSION,
|
|
4487
|
+
verdict: verdictBucket,
|
|
4488
|
+
durationMs: elapsedMs
|
|
4489
|
+
},
|
|
4490
|
+
{ policy, projectDir: cwd }
|
|
4491
|
+
);
|
|
4492
|
+
} catch (err) {
|
|
4493
|
+
logger.debug(`telemetry: skipped (ignored): ${err instanceof Error ? err.message : String(err)}`);
|
|
4209
4494
|
}
|
|
4210
4495
|
let exitCode = resolveExitCode({
|
|
4211
4496
|
strict: scanOptions.strict,
|
|
@@ -4238,6 +4523,7 @@ async function runScan(ctx) {
|
|
|
4238
4523
|
logger.warn(`--check-regressions: ${result.regressions?.length} previously-passing rule(s) now fail \u2014 exiting with code 1`);
|
|
4239
4524
|
}
|
|
4240
4525
|
}
|
|
4526
|
+
await telemetryDone;
|
|
4241
4527
|
if (exitCode !== EXIT_CODES.SAFE) {
|
|
4242
4528
|
process.exit(exitCode);
|
|
4243
4529
|
}
|
|
@@ -4346,7 +4632,7 @@ function statusCommand() {
|
|
|
4346
4632
|
// src/commands/history.ts
|
|
4347
4633
|
import { Command as Command6 } from "commander";
|
|
4348
4634
|
import { resolve as resolve5 } from "path";
|
|
4349
|
-
var CLI_VERSION2 = true ? "0.
|
|
4635
|
+
var CLI_VERSION2 = true ? "0.7.0" : process.env.npm_package_version ?? "0.0.0-dev";
|
|
4350
4636
|
function historyCommand() {
|
|
4351
4637
|
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
4638
|
const cwd = scanPath ? resolve5(scanPath) : process.cwd();
|
|
@@ -4410,8 +4696,8 @@ function historyCommand() {
|
|
|
4410
4696
|
// src/commands/hook.ts
|
|
4411
4697
|
import { Command as Command7 } from "commander";
|
|
4412
4698
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
4413
|
-
import { chmodSync, existsSync as
|
|
4414
|
-
import { dirname as dirname5, isAbsolute, join as
|
|
4699
|
+
import { chmodSync as chmodSync2, existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
4700
|
+
import { dirname as dirname5, isAbsolute, join as join8, relative as relative2, resolve as resolve6 } from "path";
|
|
4415
4701
|
|
|
4416
4702
|
// src/core/hook-templates.ts
|
|
4417
4703
|
var HOOK_BLOCK_VERSION = 1;
|
|
@@ -4503,13 +4789,13 @@ function isManaged(content) {
|
|
|
4503
4789
|
|
|
4504
4790
|
// src/commands/hook.ts
|
|
4505
4791
|
function writeManaged(path, whole, block, executable) {
|
|
4506
|
-
if (!
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
if (executable)
|
|
4792
|
+
if (!existsSync7(path)) {
|
|
4793
|
+
mkdirSync5(dirname5(path), { recursive: true });
|
|
4794
|
+
writeFileSync4(path, whole, "utf-8");
|
|
4795
|
+
if (executable) chmodSync2(path, 493);
|
|
4510
4796
|
return { path, status: "created" };
|
|
4511
4797
|
}
|
|
4512
|
-
const current =
|
|
4798
|
+
const current = readFileSync3(path, "utf-8");
|
|
4513
4799
|
if (!isManaged(current)) {
|
|
4514
4800
|
return {
|
|
4515
4801
|
path,
|
|
@@ -4519,8 +4805,8 @@ function writeManaged(path, whole, block, executable) {
|
|
|
4519
4805
|
}
|
|
4520
4806
|
const merged = replaceManagedBlock(current, block) ?? whole;
|
|
4521
4807
|
if (merged === current) return { path, status: "unchanged" };
|
|
4522
|
-
|
|
4523
|
-
if (executable)
|
|
4808
|
+
writeFileSync4(path, merged, "utf-8");
|
|
4809
|
+
if (executable) chmodSync2(path, 493);
|
|
4524
4810
|
return { path, status: "updated" };
|
|
4525
4811
|
}
|
|
4526
4812
|
function resolveGitHooksDir(cwd) {
|
|
@@ -4534,18 +4820,18 @@ function resolveGitHooksDir(cwd) {
|
|
|
4534
4820
|
function installGit(cwd) {
|
|
4535
4821
|
const hooksDir = resolveGitHooksDir(cwd);
|
|
4536
4822
|
return GIT_HOOK_NAMES.map(
|
|
4537
|
-
(name) => writeManaged(
|
|
4823
|
+
(name) => writeManaged(join8(hooksDir, name), gitHookScript(name), gitHookBlock(name), true)
|
|
4538
4824
|
);
|
|
4539
4825
|
}
|
|
4540
4826
|
function installClaude(cwd) {
|
|
4541
|
-
const path =
|
|
4827
|
+
const path = join8(cwd, ".claude", "settings.json");
|
|
4542
4828
|
const entry = { matcher: "Bash", hooks: [{ type: "command", command: CLAUDE_HOOK_COMMAND }] };
|
|
4543
|
-
if (!
|
|
4544
|
-
|
|
4545
|
-
|
|
4829
|
+
if (!existsSync7(path)) {
|
|
4830
|
+
mkdirSync5(dirname5(path), { recursive: true });
|
|
4831
|
+
writeFileSync4(path, JSON.stringify({ hooks: { PreToolUse: [entry] } }, null, 2) + "\n", "utf-8");
|
|
4546
4832
|
return [{ path, status: "created" }];
|
|
4547
4833
|
}
|
|
4548
|
-
const raw2 =
|
|
4834
|
+
const raw2 = readFileSync3(path, "utf-8");
|
|
4549
4835
|
let settings;
|
|
4550
4836
|
try {
|
|
4551
4837
|
settings = JSON.parse(raw2);
|
|
@@ -4575,12 +4861,12 @@ function installClaude(cwd) {
|
|
|
4575
4861
|
...settings,
|
|
4576
4862
|
hooks: { ...settings.hooks ?? {}, PreToolUse: next }
|
|
4577
4863
|
};
|
|
4578
|
-
|
|
4864
|
+
writeFileSync4(path, JSON.stringify(merged, null, 2) + "\n", "utf-8");
|
|
4579
4865
|
}
|
|
4580
4866
|
return [{ path, status }];
|
|
4581
4867
|
}
|
|
4582
4868
|
function installCi(cwd) {
|
|
4583
|
-
const path =
|
|
4869
|
+
const path = join8(cwd, ".github", "workflows", "shipguard.yml");
|
|
4584
4870
|
const yaml = ciWorkflowYaml();
|
|
4585
4871
|
return [writeManaged(path, yaml, yaml, false)];
|
|
4586
4872
|
}
|
|
@@ -4666,7 +4952,7 @@ Exit codes:
|
|
|
4666
4952
|
|
|
4667
4953
|
// src/commands/schema.ts
|
|
4668
4954
|
import { Command as Command8 } from "commander";
|
|
4669
|
-
var CLI_VERSION3 = true ? "0.
|
|
4955
|
+
var CLI_VERSION3 = true ? "0.7.0" : process.env.npm_package_version ?? "0.0.0-dev";
|
|
4670
4956
|
var CURRENT_SCHEMA_VERSION2 = "5";
|
|
4671
4957
|
function buildSchemaContract(limits) {
|
|
4672
4958
|
const src = (value, fallback) => value === fallback ? "default" : "policy";
|
|
@@ -4838,43 +5124,11 @@ function renderSchemaHuman(c) {
|
|
|
4838
5124
|
|
|
4839
5125
|
// src/commands/feedback.ts
|
|
4840
5126
|
import { Command as Command9 } from "commander";
|
|
5127
|
+
var ISSUES_URL2 = "https://github.com/agenticcli/shipguard/issues";
|
|
4841
5128
|
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
|
-
}
|
|
5129
|
+
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(() => {
|
|
5130
|
+
logger.info(`Feedback and bug reports go to GitHub issues: ${ISSUES_URL2}`);
|
|
5131
|
+
logger.info("The CLI does not send your feedback anywhere itself.");
|
|
4878
5132
|
});
|
|
4879
5133
|
}
|
|
4880
5134
|
function rateCommand() {
|
|
@@ -4930,10 +5184,92 @@ function rateCommand() {
|
|
|
4930
5184
|
});
|
|
4931
5185
|
}
|
|
4932
5186
|
|
|
5187
|
+
// src/commands/telemetry.ts
|
|
5188
|
+
import { Command as Command10 } from "commander";
|
|
5189
|
+
var DOCS = "https://agenticcli.dev/docs#telemetry";
|
|
5190
|
+
var SOURCE_TEXT = {
|
|
5191
|
+
"env:SHIPGUARD_TELEMETRY": "SHIPGUARD_TELEMETRY=0 is set in the environment",
|
|
5192
|
+
"env:DO_NOT_TRACK": "DO_NOT_TRACK=1 is set in the environment",
|
|
5193
|
+
"user-config": "turned off with `shipguard telemetry disable`",
|
|
5194
|
+
"project-policy": "`telemetry.enabled: false` in shipguard.policy.yml or .shipguard.yml",
|
|
5195
|
+
default: "default (on)"
|
|
5196
|
+
};
|
|
5197
|
+
function telemetryCommand() {
|
|
5198
|
+
const cmd = new Command10("telemetry").description(
|
|
5199
|
+
"Show or change the pseudonymous usage ping (status, enable, disable, reset)"
|
|
5200
|
+
);
|
|
5201
|
+
cmd.command("status").description("Show whether usage pings are on, why, and where they would go").option("--json", "Machine-readable output").action(async (o) => {
|
|
5202
|
+
const decision = decideTelemetry({ projectDir: process.cwd() });
|
|
5203
|
+
const provenance = getProvenance();
|
|
5204
|
+
const endpoint = resolveEndpoint();
|
|
5205
|
+
const installId = readInstallId() ?? null;
|
|
5206
|
+
const info = {
|
|
5207
|
+
version: 2,
|
|
5208
|
+
enabled: decision.enabled,
|
|
5209
|
+
source: decision.source,
|
|
5210
|
+
provenance,
|
|
5211
|
+
endpoint,
|
|
5212
|
+
noticeShown: noticeShown(),
|
|
5213
|
+
installIdPresent: installId !== null,
|
|
5214
|
+
installId,
|
|
5215
|
+
ci: detectCi(),
|
|
5216
|
+
configFile: configFilePath(),
|
|
5217
|
+
optOut: ["SHIPGUARD_TELEMETRY=0", "DO_NOT_TRACK=1", "shipguard telemetry disable"]
|
|
5218
|
+
};
|
|
5219
|
+
if (o.json) {
|
|
5220
|
+
console.log(JSON.stringify(info, null, 2));
|
|
5221
|
+
return;
|
|
5222
|
+
}
|
|
5223
|
+
console.log(`Usage pings: ${decision.enabled ? "ON" : "OFF"} (${SOURCE_TEXT[decision.source]})`);
|
|
5224
|
+
console.log(
|
|
5225
|
+
`Build: ${provenance}` + (provenance === "dev" ? " (a dev build never pings production; only a loopback SHIPGUARD_TELEMETRY_URL)" : "")
|
|
5226
|
+
);
|
|
5227
|
+
console.log(`Endpoint: ${endpoint ?? "none"}`);
|
|
5228
|
+
console.log(
|
|
5229
|
+
`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)" : "")
|
|
5230
|
+
);
|
|
5231
|
+
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.`);
|
|
5232
|
+
console.log(`Turn off: SHIPGUARD_TELEMETRY=0 | DO_NOT_TRACK=1 | shipguard telemetry disable`);
|
|
5233
|
+
console.log(`Inspect: SHIPGUARD_TELEMETRY_DEBUG=1 shipguard scan (prints the exact payload, sends nothing)`);
|
|
5234
|
+
console.log(`Details: ${DOCS}`);
|
|
5235
|
+
});
|
|
5236
|
+
for (const [name, enabled] of [["enable", true], ["disable", false]]) {
|
|
5237
|
+
cmd.command(name).description(enabled ? "Turn usage pings on for this user" : "Turn usage pings off for this user").action(() => {
|
|
5238
|
+
try {
|
|
5239
|
+
const file = writeUserEnabled(getConfigDir(), enabled);
|
|
5240
|
+
console.log(`Usage pings ${enabled ? "enabled" : "disabled"} for this user (${file}).`);
|
|
5241
|
+
} catch (err) {
|
|
5242
|
+
logger.error(`Could not save the setting: ${err instanceof Error ? err.message : String(err)}`);
|
|
5243
|
+
process.exitCode = EXIT_CODES.RUNTIME_ERROR;
|
|
5244
|
+
return;
|
|
5245
|
+
}
|
|
5246
|
+
const decision = decideTelemetry({ projectDir: process.cwd() });
|
|
5247
|
+
if (enabled && !decision.enabled) {
|
|
5248
|
+
logger.warn(`Pings stay OFF: ${SOURCE_TEXT[decision.source]}.`);
|
|
5249
|
+
}
|
|
5250
|
+
});
|
|
5251
|
+
}
|
|
5252
|
+
cmd.command("reset").description("Forget the local install id (a new random one is made on the next ping)").action(() => {
|
|
5253
|
+
try {
|
|
5254
|
+
const { hadId, oldId } = resetInstallId(getConfigDir());
|
|
5255
|
+
console.log(hadId ? "Install id deleted. A new random one is made on the next ping." : "No install id was stored. Nothing to reset.");
|
|
5256
|
+
if (oldId) console.log(`Old install id: ${oldId}`);
|
|
5257
|
+
console.log(
|
|
5258
|
+
"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}`
|
|
5259
|
+
);
|
|
5260
|
+
} catch (err) {
|
|
5261
|
+
logger.error(`Could not reset the install id: ${err instanceof Error ? err.message : String(err)}`);
|
|
5262
|
+
process.exitCode = EXIT_CODES.RUNTIME_ERROR;
|
|
5263
|
+
}
|
|
5264
|
+
});
|
|
5265
|
+
for (const sub of cmd.commands) sub.exitOverride();
|
|
5266
|
+
return cmd;
|
|
5267
|
+
}
|
|
5268
|
+
|
|
4933
5269
|
// src/handlers.ts
|
|
4934
|
-
var
|
|
5270
|
+
var ISSUES_URL3 = "https://github.com/agenticcli/shipguard/issues";
|
|
4935
5271
|
var DOCS_URL2 = "https://agenticcli.dev/docs";
|
|
4936
|
-
var REPORT_LINE = `Report this: ${
|
|
5272
|
+
var REPORT_LINE = `Report this: ${ISSUES_URL3} \xB7 Docs: ${DOCS_URL2}`;
|
|
4937
5273
|
function handleUncaughtException(error) {
|
|
4938
5274
|
const message = error instanceof Error ? error.message : String(error);
|
|
4939
5275
|
console.error(`\x1B[31m\u2717\x1B[0m Unexpected error: ${message}`);
|
|
@@ -4962,20 +5298,20 @@ process.on("uncaughtException", handleUncaughtException);
|
|
|
4962
5298
|
process.on("unhandledRejection", handleUnhandledRejection);
|
|
4963
5299
|
process.on("SIGINT", handleSignal);
|
|
4964
5300
|
process.on("SIGTERM", handleSignal);
|
|
4965
|
-
var
|
|
4966
|
-
var program = new
|
|
5301
|
+
var ISSUES_URL4 = "https://github.com/agenticcli/shipguard/issues";
|
|
5302
|
+
var program = new Command11();
|
|
4967
5303
|
var rawArgs = process.argv.slice(2);
|
|
4968
5304
|
if (rawArgs[0] === "?") {
|
|
4969
5305
|
process.argv = [process.argv[0], process.argv[1], "help"];
|
|
4970
5306
|
}
|
|
4971
5307
|
program.name("shipguard").description("CLI-first release gate for AI-built apps").version(
|
|
4972
|
-
true ? "0.
|
|
5308
|
+
true ? "0.7.0" : process.env.npm_package_version ?? "0.0.0-dev"
|
|
4973
5309
|
).helpCommand(false).addHelpText("after", `
|
|
4974
5310
|
Learn more:
|
|
4975
5311
|
Docs https://agenticcli.dev/docs
|
|
4976
5312
|
Site https://agenticcli.dev
|
|
4977
5313
|
Pricing https://agenticcli.dev/pricing
|
|
4978
|
-
Issues ${
|
|
5314
|
+
Issues ${ISSUES_URL4}`);
|
|
4979
5315
|
program.exitOverride();
|
|
4980
5316
|
function addSubcommand(cmd) {
|
|
4981
5317
|
cmd.exitOverride();
|
|
@@ -4991,8 +5327,9 @@ addSubcommand(hookCommand());
|
|
|
4991
5327
|
addSubcommand(schemaCommand());
|
|
4992
5328
|
addSubcommand(feedbackCommand());
|
|
4993
5329
|
addSubcommand(rateCommand());
|
|
5330
|
+
addSubcommand(telemetryCommand());
|
|
4994
5331
|
program.addCommand(
|
|
4995
|
-
new
|
|
5332
|
+
new Command11("help").description("Show the quickstart guide").action(() => {
|
|
4996
5333
|
const isTTY = Boolean(process.stdout.isTTY);
|
|
4997
5334
|
process.stdout.write(quickstartHelp(isTTY) + "\n");
|
|
4998
5335
|
})
|
|
@@ -5017,7 +5354,7 @@ function levenshtein(a, b) {
|
|
|
5017
5354
|
return dp[m][n];
|
|
5018
5355
|
}
|
|
5019
5356
|
function closestCommand(input) {
|
|
5020
|
-
const names = ["scan", "init", "login", "logout", "status", "history", "hook", "schema", "feedback", "rate", "help"];
|
|
5357
|
+
const names = ["scan", "init", "login", "logout", "status", "history", "hook", "schema", "feedback", "rate", "telemetry", "help"];
|
|
5021
5358
|
let best;
|
|
5022
5359
|
let bestDist = Infinity;
|
|
5023
5360
|
for (const name of names) {
|
|
@@ -5030,7 +5367,7 @@ function closestCommand(input) {
|
|
|
5030
5367
|
return bestDist <= 3 ? best : void 0;
|
|
5031
5368
|
}
|
|
5032
5369
|
(async () => {
|
|
5033
|
-
const KNOWN_COMMANDS = /* @__PURE__ */ new Set(["scan", "init", "login", "logout", "status", "history", "hook", "schema", "feedback", "rate", "help"]);
|
|
5370
|
+
const KNOWN_COMMANDS = /* @__PURE__ */ new Set(["scan", "init", "login", "logout", "status", "history", "hook", "schema", "feedback", "rate", "telemetry", "help"]);
|
|
5034
5371
|
const firstNonFlag = process.argv.slice(2).find((a) => !a.startsWith("-"));
|
|
5035
5372
|
if (firstNonFlag && firstNonFlag !== "?" && !KNOWN_COMMANDS.has(firstNonFlag)) {
|
|
5036
5373
|
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.0",
|
|
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
|
{
|