@agenticcli/shipguard 0.1.0 → 0.1.2

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.
@@ -0,0 +1,115 @@
1
+ // src/utils/fs.ts
2
+ import fg from "fast-glob";
3
+ import { readFile, stat } from "fs/promises";
4
+ import { join } from "path";
5
+ var DEFAULT_MAX_FILE_SIZE_BYTES = 512 * 1024;
6
+ var DEFAULT_MAX_TOTAL_BYTES = 256 * 1024 * 1024;
7
+ var DEFAULT_MAX_FILES = 5e3;
8
+ var BINARY_CHECK_BYTES = 8192;
9
+ var DEFAULT_IGNORE = [
10
+ "node_modules/**",
11
+ "dist/**",
12
+ "build/**",
13
+ ".next/**",
14
+ "coverage/**",
15
+ ".git/**",
16
+ "*.lock",
17
+ "pnpm-lock.yaml",
18
+ "package-lock.json",
19
+ // Extended — large artifact directories
20
+ ".cache/**",
21
+ ".turbo/**",
22
+ ".venv/**",
23
+ "venv/**",
24
+ "vendor/**",
25
+ "tmp/**",
26
+ "out/**",
27
+ // Large file extensions — binary and generated
28
+ "*.log",
29
+ "*.min.js",
30
+ "*.map",
31
+ "*.png",
32
+ "*.jpg",
33
+ "*.jpeg",
34
+ "*.gif",
35
+ "*.webp",
36
+ "*.ico",
37
+ "*.pdf",
38
+ "*.zip",
39
+ "*.gz",
40
+ "*.tar",
41
+ "*.mp4",
42
+ "*.mov",
43
+ "*.wasm",
44
+ "*.node",
45
+ ".DS_Store",
46
+ // ShipGuard's own report output — never scan the tool's own artifacts
47
+ ".shipguard/**"
48
+ ];
49
+ async function readFiles(rootDir, patterns = ["**/*"], ignorePatterns = [], options = {}) {
50
+ const maxFileSizeBytes = options.maxFileSizeBytes ?? DEFAULT_MAX_FILE_SIZE_BYTES;
51
+ const maxTotalBytes = options.maxTotalBytes ?? DEFAULT_MAX_TOTAL_BYTES;
52
+ const maxFiles = options.maxFiles ?? DEFAULT_MAX_FILES;
53
+ const { onProgress } = options;
54
+ const allIgnore = [...DEFAULT_IGNORE, ...ignorePatterns];
55
+ const filePaths = await fg(patterns, {
56
+ cwd: rootDir,
57
+ ignore: allIgnore,
58
+ dot: true,
59
+ absolute: false,
60
+ onlyFiles: true
61
+ });
62
+ const total = filePaths.length;
63
+ const files = [];
64
+ let skippedTooLarge = 0;
65
+ let skippedBinary = 0;
66
+ let truncated = false;
67
+ let totalBytes = 0;
68
+ let processed = 0;
69
+ for (const fp of filePaths) {
70
+ if (files.length >= maxFiles || totalBytes >= maxTotalBytes) {
71
+ truncated = true;
72
+ break;
73
+ }
74
+ const fullPath = join(rootDir, fp);
75
+ try {
76
+ const fileStat = await stat(fullPath);
77
+ if (fileStat.size > maxFileSizeBytes) {
78
+ skippedTooLarge++;
79
+ onProgress?.(++processed, total, fp);
80
+ continue;
81
+ }
82
+ const buffer = await readFile(fullPath);
83
+ const checkLen = Math.min(buffer.length, BINARY_CHECK_BYTES);
84
+ let isBinary = false;
85
+ for (let i = 0; i < checkLen; i++) {
86
+ if (buffer[i] === 0) {
87
+ isBinary = true;
88
+ break;
89
+ }
90
+ }
91
+ if (isBinary) {
92
+ skippedBinary++;
93
+ onProgress?.(++processed, total, fp);
94
+ continue;
95
+ }
96
+ const content = buffer.toString("utf-8");
97
+ totalBytes += buffer.length;
98
+ files.push({
99
+ path: fullPath,
100
+ content,
101
+ relativePath: fp
102
+ });
103
+ } catch {
104
+ }
105
+ onProgress?.(++processed, total, fp);
106
+ }
107
+ return { files, skippedTooLarge, skippedBinary, truncated };
108
+ }
109
+
110
+ export {
111
+ DEFAULT_MAX_FILE_SIZE_BYTES,
112
+ DEFAULT_MAX_TOTAL_BYTES,
113
+ DEFAULT_MAX_FILES,
114
+ readFiles
115
+ };
@@ -145,6 +145,7 @@ var SECRET_PATTERNS = [
145
145
  name: "OpenAI API Key",
146
146
  regex: /['"]?(sk-proj-[a-zA-Z0-9_\-]{20,})['"]?/m,
147
147
  severity: "high",
148
+ confidence: "HIGH",
148
149
  explanation: "Hardcoded OpenAI API key detected. Leaking this key allows unauthorized use of your OpenAI account, incurring charges.",
149
150
  recommendation: "Remove the key from source code. Use process.env.OPENAI_API_KEY and store the value in a .env file that is gitignored."
150
151
  },
@@ -154,6 +155,7 @@ var SECRET_PATTERNS = [
154
155
  name: "OpenAI Legacy API Key",
155
156
  regex: /(?:openai[_\-]?(?:api[_\-]?)?key|OPENAI[_\-]?(?:API[_\-]?)?KEY)\s*[=:]\s*['"]?(sk-[a-zA-Z0-9]{20,})['"]?/im,
156
157
  severity: "high",
158
+ confidence: "HIGH",
157
159
  explanation: "Hardcoded OpenAI API key detected. Leaking this key allows unauthorized use of your OpenAI account, incurring charges.",
158
160
  recommendation: "Remove the key from source code. Use process.env.OPENAI_API_KEY and store the value in a .env file that is gitignored."
159
161
  },
@@ -163,6 +165,7 @@ var SECRET_PATTERNS = [
163
165
  name: "Anthropic API Key",
164
166
  regex: /['"]?(sk-ant-(?:api\d+-)?[a-zA-Z0-9_\-]{20,})['"]?/im,
165
167
  severity: "high",
168
+ confidence: "HIGH",
166
169
  explanation: "Hardcoded Anthropic API key detected. Leaking this key allows unauthorized use of Anthropic Claude, incurring charges.",
167
170
  recommendation: "Remove the key from source code. Use process.env.ANTHROPIC_API_KEY and store the value in a .env file that is gitignored."
168
171
  },
@@ -172,6 +175,7 @@ var SECRET_PATTERNS = [
172
175
  name: "Stripe Live Secret Key",
173
176
  regex: /['"]?(sk_live_[a-zA-Z0-9]{24,})['"]?/im,
174
177
  severity: "critical",
178
+ confidence: "HIGH",
175
179
  explanation: "Hardcoded Stripe live secret key detected. This key can be used to make charges, refunds, and access customer data in your live Stripe account.",
176
180
  recommendation: "Remove immediately. Use process.env.STRIPE_SECRET_KEY. Rotate the key in the Stripe Dashboard."
177
181
  },
@@ -181,6 +185,7 @@ var SECRET_PATTERNS = [
181
185
  name: "Stripe Test Secret Key",
182
186
  regex: /['"]?(sk_test_[a-zA-Z0-9]{24,})['"]?/im,
183
187
  severity: "medium",
188
+ confidence: "HIGH",
184
189
  explanation: "Hardcoded Stripe test secret key detected. While test keys cannot process real payments, committing them is a bad practice that often leads to live key exposure.",
185
190
  recommendation: "Remove from source code. Use process.env.STRIPE_SECRET_KEY with a .env file that is gitignored."
186
191
  },
@@ -190,6 +195,7 @@ var SECRET_PATTERNS = [
190
195
  name: "AWS Access Key ID",
191
196
  regex: /['"]?(AKIA[0-9A-Z]{16})['"]?/m,
192
197
  severity: "high",
198
+ confidence: "HIGH",
193
199
  explanation: "Hardcoded AWS Access Key ID detected. Combined with the secret key, this allows full AWS API access under your account.",
194
200
  recommendation: "Remove and rotate immediately via IAM. Use environment variables or AWS credential profiles instead."
195
201
  },
@@ -199,6 +205,7 @@ var SECRET_PATTERNS = [
199
205
  name: "AWS Secret Access Key",
200
206
  regex: /(?:aws[_\-]?secret[_\-]?(?:access[_\-]?)?key|AWS_SECRET_ACCESS_KEY)\s*[=:]\s*['"]?([a-zA-Z0-9\/+]{40})['"]?/im,
201
207
  severity: "high",
208
+ confidence: "HIGH",
202
209
  explanation: "Hardcoded AWS Secret Access Key detected. This credential enables full programmatic access to AWS services.",
203
210
  recommendation: "Remove and rotate immediately via IAM. Use environment variables or AWS credential profiles instead."
204
211
  },
@@ -208,6 +215,7 @@ var SECRET_PATTERNS = [
208
215
  name: "Google API Key",
209
216
  regex: /['"]?(AIza[0-9A-Za-z\-_]{35})['"]?/m,
210
217
  severity: "high",
218
+ confidence: "HIGH",
211
219
  explanation: "Hardcoded Google API key detected. This key can be used to access Google Cloud services or Google Maps, incurring charges.",
212
220
  recommendation: "Remove from source code. Restrict key usage in the Google Cloud Console and use environment variables."
213
221
  },
@@ -217,6 +225,7 @@ var SECRET_PATTERNS = [
217
225
  name: "GitHub Personal Access Token",
218
226
  regex: /['"]?(ghp_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9_]{82})['"]?/m,
219
227
  severity: "high",
228
+ confidence: "HIGH",
220
229
  explanation: "Hardcoded GitHub Personal Access Token detected. This token grants access to GitHub repositories and actions under your account.",
221
230
  recommendation: "Remove and revoke the token at github.com/settings/tokens. Use environment variables."
222
231
  },
@@ -226,6 +235,7 @@ var SECRET_PATTERNS = [
226
235
  name: "Razorpay Secret Key",
227
236
  regex: /(?:razorpay[_\-]?(?:key[_\-]?)?secret|RAZORPAY_KEY_SECRET)\s*[=:]\s*['"]?([a-zA-Z0-9]{20,})['"]?/im,
228
237
  severity: "high",
238
+ confidence: "HIGH",
229
239
  explanation: "Hardcoded Razorpay secret key detected. This allows unauthorized access to your Razorpay payment account.",
230
240
  recommendation: "Remove from source code. Use process.env.RAZORPAY_KEY_SECRET and store in a gitignored .env file."
231
241
  },
@@ -235,6 +245,7 @@ var SECRET_PATTERNS = [
235
245
  name: "JWT Secret",
236
246
  regex: /(?:jwt[_\-]?secret|JWT_SECRET)\s*[=:]\s*['"]([^'"]{16,})['"]?/im,
237
247
  severity: "high",
248
+ confidence: "HIGH",
238
249
  explanation: "Hardcoded JWT secret detected. Exposing this allows attackers to forge valid JWT tokens and bypass authentication.",
239
250
  recommendation: "Remove from source code. Generate a strong random secret, store it in environment variables."
240
251
  },
@@ -245,6 +256,7 @@ var SECRET_PATTERNS = [
245
256
  name: "Database URL with Credentials",
246
257
  regex: /(?:(?:database[_\-]?url|DATABASE_URL|db[_\-]?url|DB_URL|connection[_\-]?string|CONNECTION_STRING)\s*[=:]\s*)?['"]?((?:postgres|postgresql|mysql|mongodb|mongodb\+srv|redis|amqp|rabbitmq):\/\/[^:'"]+:[^@'"]+@[^'"]+)['"]?/im,
247
258
  severity: "critical",
259
+ confidence: "HIGH",
248
260
  explanation: "Database URL with embedded credentials detected. This exposes the database host, username, and password directly.",
249
261
  recommendation: "Remove credentials from the URL. Use environment variables and ensure the .env file is gitignored."
250
262
  },
@@ -255,6 +267,7 @@ var SECRET_PATTERNS = [
255
267
  name: "High-Entropy Secret String",
256
268
  regex: /(?:api[_\-]?key|secret|token|password|passwd|auth[_\-]?key|access[_\-]?key)\s*[=:]\s*['"]([a-zA-Z0-9\/+_\-]{32,64})['"](?!\s*\+|\.)/im,
257
269
  severity: "medium",
270
+ confidence: "MEDIUM",
258
271
  explanation: "A variable with a secret-sounding name is assigned a long literal string that resembles an API key or token.",
259
272
  recommendation: "Move this value to a .env file and reference it via process.env. Never hardcode credentials."
260
273
  }
@@ -274,6 +287,7 @@ function checkSecrets(files, policy) {
274
287
  severity: "high",
275
288
  category: "secrets",
276
289
  file: relativePath,
290
+ confidence: "HIGH",
277
291
  explanation: "A .env file is tracked in the repository. These files often contain secrets such as API keys, database credentials, and tokens that should never be committed.",
278
292
  recommendation: "Add .env (and its variants like .env.local, .env.production) to .gitignore. Remove the file from git history using `git rm --cached .env`.",
279
293
  blocking: policy.block.includes(id)
@@ -291,6 +305,7 @@ function checkSecrets(files, policy) {
291
305
  file: relativePath,
292
306
  line: lineNum,
293
307
  evidence: pkMatch[0].trim(),
308
+ confidence: "HIGH",
294
309
  explanation: "A PEM private key block is embedded in the source file. This exposes cryptographic material that can be used to impersonate services, decrypt data, or forge signatures.",
295
310
  recommendation: "Remove the private key from the codebase immediately. Store keys in a secrets manager (e.g., AWS Secrets Manager, Vault) or as environment variables.",
296
311
  blocking: policy.block.includes(id)
@@ -311,6 +326,7 @@ function checkSecrets(files, policy) {
311
326
  file: relativePath,
312
327
  line: i + 1,
313
328
  evidence: `${line.split("=")[0].trim()}=${redact(match[1])}`,
329
+ confidence: "HIGH",
314
330
  explanation: "An environment variable with NEXT_PUBLIC_ prefix containing a secret-sounding name is used in a frontend file. NEXT_PUBLIC_ variables are bundled into client-side JavaScript and exposed to all users.",
315
331
  recommendation: "Move secret API calls to a server-side route (e.g., Next.js API route or Server Action). Never use NEXT_PUBLIC_ for keys, tokens, or secrets.",
316
332
  blocking: policy.block.includes(id)
@@ -336,6 +352,7 @@ function checkSecrets(files, policy) {
336
352
  file: relativePath,
337
353
  line: i + 1,
338
354
  evidence: `...${redact(secretValue)}...`,
355
+ confidence: pattern.confidence,
339
356
  explanation: pattern.explanation,
340
357
  recommendation: pattern.recommendation,
341
358
  blocking: policy.block.includes(pattern.id)
@@ -422,6 +439,7 @@ var authCheck = {
422
439
  severity: "high",
423
440
  category: "auth",
424
441
  file: "middleware.ts",
442
+ confidence: "MEDIUM",
425
443
  explanation: "No middleware.ts file was found. Next.js App Router relies on middleware to enforce route-level auth for admin, dashboard, and billing routes. Without it, protection depends entirely on individual Server Components and Route Handlers, which is error-prone.",
426
444
  recommendation: "Create middleware.ts at the project root (or src/middleware.ts) and add a matcher that covers /admin, /dashboard, and /billing. Use auth() from next-auth/auth.js or clerkMiddleware() to redirect unauthenticated requests.",
427
445
  blocking: policy.block.includes("public_admin_route")
@@ -433,6 +451,7 @@ var authCheck = {
433
451
  severity: "high",
434
452
  category: "auth",
435
453
  file: middlewareFile.relativePath,
454
+ confidence: "MEDIUM",
436
455
  explanation: "A middleware.ts file exists but its content does not reference admin, dashboard, billing, account, or management routes. Sensitive routes may not be protected at the edge/middleware layer.",
437
456
  recommendation: 'Add a matcher config to middleware.ts that covers protected route prefixes:\n export const config = { matcher: ["/admin/:path*", "/dashboard/:path*"] }',
438
457
  blocking: policy.block.includes("public_admin_route")
@@ -453,6 +472,7 @@ var authCheck = {
453
472
  severity: "high",
454
473
  category: "auth",
455
474
  file: rp,
475
+ confidence: "MEDIUM",
456
476
  explanation: wasRemoved ? `${rp} previously had an auth call that appears to have been commented out. This page is now accessible without authentication.` : `${rp} is in a sensitive route segment (admin/dashboard/billing) but contains no active auth call (auth(), getServerSession(), requireAuth(), etc.). Server Components must verify the session even when middleware is in place \u2014 middleware is not a security boundary (see CVE-2025-29927).`,
457
477
  recommendation: 'Add `const session = await auth()` at the top of the Server Component and redirect unauthenticated users with `if (!session) redirect("/login")`.',
458
478
  blocking: policy.block.includes("public_admin_route")
@@ -469,6 +489,7 @@ var authCheck = {
469
489
  severity: "high",
470
490
  category: "auth",
471
491
  file: rp,
492
+ confidence: "MEDIUM",
472
493
  explanation: wasRemoved ? `${rp} previously had an auth call that appears to have been commented out. This API route now responds to requests without verifying the caller.` : `${rp} is an API Route Handler under a sensitive path (admin/users/billing) but contains no auth guard. Any caller \u2014 including unauthenticated requests \u2014 can invoke it.`,
473
494
  recommendation: "Add `const session = await auth()` (next-auth) or `const { userId } = await currentUser()` (Clerk) at the start of each exported HTTP handler. Return a 401 if no session.",
474
495
  blocking: policy.block.includes("auth_route_without_guard")
@@ -484,6 +505,7 @@ var authCheck = {
484
505
  severity: "medium",
485
506
  category: "auth",
486
507
  file: rp,
508
+ confidence: "LOW",
487
509
  explanation: `${rp} registers a route on a sensitive URL segment (admin/users/billing) without an apparent auth middleware guard. In Express, protect routes by passing auth middleware before the handler or by calling router.use(authMiddleware) above the sensitive routes.`,
488
510
  recommendation: 'Use `router.use(requireAuth)` before sensitive routes, or pass it inline:\n router.get("/admin/users", requireAuth, handler)\nFor Fastify, use a `preHandler` hook or `onRequest` hook.',
489
511
  blocking: policy.block.includes("auth_route_without_guard")
@@ -532,6 +554,7 @@ var SQL_PATTERNS = [
532
554
  id: "db-drop-table",
533
555
  title: "Destructive migration: DROP TABLE",
534
556
  severity: "critical",
557
+ confidence: "HIGH",
535
558
  explanation: "DROP TABLE permanently deletes a table and all its data. In production this causes irreversible data loss and immediate application failure for any query targeting that table.",
536
559
  recommendation: "Never drop a table in the same migration that removes code references. Use an expand-contract strategy: deprecate code first, then drop in a later release after confirming no traffic.",
537
560
  pattern: /\bDROP\s+TABLE\b/i
@@ -540,6 +563,7 @@ var SQL_PATTERNS = [
540
563
  id: "db-drop-column",
541
564
  title: "Destructive migration: DROP COLUMN",
542
565
  severity: "high",
566
+ confidence: "HIGH",
543
567
  explanation: "DROP COLUMN removes a column and its data permanently. Running this while old application code still reads the column causes immediate query failures.",
544
568
  recommendation: "Deprecate the column in code first, deploy, confirm no usage, then run the drop in a separate migration.",
545
569
  pattern: /\bDROP\s+COLUMN\b/i
@@ -548,6 +572,7 @@ var SQL_PATTERNS = [
548
572
  id: "db-truncate",
549
573
  title: "Destructive migration: TRUNCATE",
550
574
  severity: "high",
575
+ confidence: "HIGH",
551
576
  explanation: "TRUNCATE deletes all rows in a table instantly without logging individual row deletions, making it very fast but also unrecoverable without a full backup restore.",
552
577
  recommendation: "Remove TRUNCATE from migration files. Data wipes should be explicit operational procedures, not automatic schema changes.",
553
578
  pattern: /\bTRUNCATE\b/i
@@ -556,6 +581,7 @@ var SQL_PATTERNS = [
556
581
  id: "db-delete-without-where",
557
582
  title: "Unsafe migration: DELETE FROM without WHERE clause",
558
583
  severity: "high",
584
+ confidence: "HIGH",
559
585
  explanation: "DELETE FROM without a WHERE clause deletes every row in the table. In a migration file this almost always indicates a copy-paste error or oversight.",
560
586
  recommendation: "Add a WHERE clause, or replace with TRUNCATE (and add a review gate) if a full wipe is truly intended.",
561
587
  pattern: /\bDELETE\s+FROM\b/i,
@@ -565,6 +591,7 @@ var SQL_PATTERNS = [
565
591
  id: "db-alter-drop",
566
592
  title: "Potentially destructive migration: ALTER TABLE DROP",
567
593
  severity: "medium",
594
+ confidence: "MEDIUM",
568
595
  explanation: "ALTER TABLE \u2026 DROP (other than DROP COLUMN, which is flagged separately) can drop constraints, indexes, or partitions. Dropping a NOT NULL constraint or unique index affects data integrity and query plans.",
569
596
  recommendation: "Review what exactly is being dropped. Ensure application code is already compatible with the removed constraint before deploying.",
570
597
  // Avoid double-flagging lines that already match DROP COLUMN (handled above)
@@ -612,6 +639,7 @@ function checkSqlFile(file, findings) {
612
639
  file: file.relativePath,
613
640
  line: lineNumber,
614
641
  evidence: evidenceLine,
642
+ confidence: pattern.confidence,
615
643
  explanation: pattern.explanation,
616
644
  recommendation: pattern.recommendation,
617
645
  blocking: pattern.severity === "critical" || pattern.severity === "high"
@@ -641,6 +669,7 @@ function checkPackageJson(file, findings) {
641
669
  category: "database",
642
670
  file: file.relativePath,
643
671
  evidence: `"${scriptName}": "${scriptValue.slice(0, 120)}"`,
672
+ confidence: "HIGH",
644
673
  explanation: `The "${tool}" command bypasses migration files and applies schema changes directly to the database without an audit trail. In production or CI this can silently drop columns, tables, or constraints with no rollback path.`,
645
674
  recommendation: 'Replace with "prisma migrate deploy" (Prisma) or "drizzle-kit migrate" (Drizzle) in all non-local scripts. Reserve db push for local prototype databases only.',
646
675
  blocking: false
@@ -661,6 +690,7 @@ function checkPrismaSchemaWithoutMigration(files, findings) {
661
690
  severity: "medium",
662
691
  category: "database",
663
692
  file: schemaFile.relativePath,
693
+ confidence: "MEDIUM",
664
694
  explanation: 'The Prisma schema was modified but no migration file appears in the changed file set. In production you must run "prisma migrate dev" to generate a migration, then commit it before deploying.',
665
695
  recommendation: 'Run "npx prisma migrate dev --name <description>" locally, commit the generated migration file in prisma/migrations/, and re-scan.',
666
696
  blocking: false
@@ -714,6 +744,7 @@ function checkNextConfig(file) {
714
744
  file: relativePath,
715
745
  line,
716
746
  evidence: "Access-Control-Allow-Origin: *",
747
+ confidence: "HIGH",
717
748
  explanation: "A wildcard CORS policy allows any origin to read responses from your API. Combined with credentials, this can expose user data to malicious sites.",
718
749
  recommendation: "Replace the wildcard with an explicit list of trusted origins in the headers() configuration.",
719
750
  blocking: true
@@ -730,6 +761,7 @@ function checkNextConfig(file) {
730
761
  file: relativePath,
731
762
  line,
732
763
  evidence: "productionBrowserSourceMaps: true",
764
+ confidence: "HIGH",
733
765
  explanation: "Enabling production source maps exposes your original application source code to anyone inspecting browser devtools, aiding reverse engineering and vulnerability discovery.",
734
766
  recommendation: "Remove productionBrowserSourceMaps: true or set it to false for production builds.",
735
767
  blocking: false
@@ -745,6 +777,7 @@ function checkNextConfig(file) {
745
777
  severity: "medium",
746
778
  category: "deployment",
747
779
  file: relativePath,
780
+ confidence: "MEDIUM",
748
781
  explanation: "X-Frame-Options prevents your site from being embedded in an iframe, protecting users against clickjacking attacks.",
749
782
  recommendation: "Add { key: 'X-Frame-Options', value: 'DENY' } to your headers() configuration in next.config.js.",
750
783
  blocking: false
@@ -757,6 +790,7 @@ function checkNextConfig(file) {
757
790
  severity: "medium",
758
791
  category: "deployment",
759
792
  file: relativePath,
793
+ confidence: "MEDIUM",
760
794
  explanation: "X-Content-Type-Options: nosniff prevents MIME-type sniffing attacks where browsers execute content as a different type than declared.",
761
795
  recommendation: "Add { key: 'X-Content-Type-Options', value: 'nosniff' } to your headers() configuration.",
762
796
  blocking: false
@@ -778,6 +812,7 @@ function checkDockerfile(file) {
778
812
  severity: "medium",
779
813
  category: "deployment",
780
814
  file: relativePath,
815
+ confidence: "MEDIUM",
781
816
  explanation: "Running containers as root amplifies the blast radius of a container escape. A non-root user limits what an attacker can do if they gain code execution inside the container.",
782
817
  recommendation: "Add a USER directive with a non-root user (e.g., USER node or create a dedicated user with addgroup/adduser).",
783
818
  blocking: false
@@ -802,6 +837,7 @@ function checkDockerfile(file) {
802
837
  file: relativePath,
803
838
  line: lineNum,
804
839
  evidence: line.trim(),
840
+ confidence: "HIGH",
805
841
  explanation: "Using :latest or no tag means the base image can change silently between builds, introducing unreviewed dependency updates or security regressions.",
806
842
  recommendation: `Pin the image to a specific digest or version tag (e.g., ${image.split(":")[0]}:20-alpine or with a SHA digest).`,
807
843
  blocking: false
@@ -828,6 +864,7 @@ function checkDockerCompose(file) {
828
864
  category: "deployment",
829
865
  file: relativePath,
830
866
  evidence: line.trim(),
867
+ confidence: "HIGH",
831
868
  explanation: "Unpinned images in docker-compose can silently pull breaking or vulnerable upstream changes.",
832
869
  recommendation: `Pin to a specific version tag or SHA digest for ${image.split(":")[0]}.`,
833
870
  blocking: false
@@ -849,6 +886,7 @@ function checkVercelConfig(file) {
849
886
  category: "deployment",
850
887
  file: relativePath,
851
888
  line,
889
+ confidence: "MEDIUM",
852
890
  explanation: "Catch-all rewrite rules can accidentally expose internal routes or proxy unintended paths, creating an open redirect or SSRF surface.",
853
891
  recommendation: "Narrow the source pattern to only the specific paths that need rewriting.",
854
892
  blocking: false
@@ -862,6 +900,7 @@ function checkVercelConfig(file) {
862
900
  severity: "medium",
863
901
  category: "deployment",
864
902
  file: relativePath,
903
+ confidence: "MEDIUM",
865
904
  explanation: "Without explicit headers in vercel.json, responses lack security headers like X-Frame-Options, X-Content-Type-Options, and CSP, leaving users exposed to clickjacking and XSS.",
866
905
  recommendation: 'Add a "headers" block to vercel.json or configure security headers in next.config.js instead.',
867
906
  blocking: false
@@ -880,6 +919,7 @@ function checkNetlifyConfig(file) {
880
919
  severity: "medium",
881
920
  category: "deployment",
882
921
  file: relativePath,
922
+ confidence: "MEDIUM",
883
923
  explanation: "Without a [[headers]] block, Netlify deployments lack security headers, exposing the app to clickjacking and content-type sniffing attacks.",
884
924
  recommendation: "Add a [[headers]] section to netlify.toml with X-Frame-Options, X-Content-Type-Options, and other security headers.",
885
925
  blocking: false
@@ -900,6 +940,7 @@ function checkEnvFiles(files) {
900
940
  severity: "low",
901
941
  category: "deployment",
902
942
  file: envFile.relativePath,
943
+ confidence: "HIGH",
903
944
  explanation: "Without a .env.example, new contributors have no template for required environment variables, increasing the risk of misconfigured deployments.",
904
945
  recommendation: "Create a .env.example file with all required variable keys (and safe placeholder values) so the team can onboard without guessing configuration.",
905
946
  blocking: false
@@ -930,6 +971,7 @@ function checkEnvFiles(files) {
930
971
  category: "deployment",
931
972
  file: envFile.relativePath,
932
973
  evidence: undocumentedKeys.join(", "),
974
+ confidence: "HIGH",
933
975
  explanation: "Keys present in .env but missing from .env.example leave teammates and deployment pipelines without the full required configuration, causing runtime failures.",
934
976
  recommendation: `Add the following keys to .env.example: ${undocumentedKeys.join(", ")}`,
935
977
  blocking: false
@@ -960,6 +1002,7 @@ function checkPackageJson2(file) {
960
1002
  category: "deployment",
961
1003
  file: relativePath,
962
1004
  evidence: `"${name}": "${value}"`,
1005
+ confidence: "HIGH",
963
1006
  explanation: "Running with NODE_ENV=development in production disables performance optimisations and may enable verbose error output, leaking stack traces to end users.",
964
1007
  recommendation: `Remove NODE_ENV=development from the "${name}" script or set NODE_ENV=production explicitly.`,
965
1008
  blocking: true
@@ -973,6 +1016,7 @@ function checkPackageJson2(file) {
973
1016
  category: "deployment",
974
1017
  file: relativePath,
975
1018
  evidence: `"${name}": "${value}"`,
1019
+ confidence: "HIGH",
976
1020
  explanation: "DEBUG=true or DEBUG=* enables verbose logging in many Node.js libraries, which can leak internal paths, secrets, and request details in production logs.",
977
1021
  recommendation: `Remove the DEBUG flag from the "${name}" script.`,
978
1022
  blocking: true
@@ -995,6 +1039,7 @@ function checkGeneralConfigs(file) {
995
1039
  file: relativePath,
996
1040
  line,
997
1041
  evidence: "origin: *",
1042
+ confidence: "MEDIUM",
998
1043
  explanation: "Setting CORS origin to * allows any website to make credentialed requests to your API, bypassing Same-Origin Policy protections.",
999
1044
  recommendation: "Replace the wildcard origin with an explicit allowlist of trusted domains.",
1000
1045
  blocking: true
@@ -1011,6 +1056,7 @@ function checkGeneralConfigs(file) {
1011
1056
  file: relativePath,
1012
1057
  line,
1013
1058
  evidence: "debug: true",
1059
+ confidence: "MEDIUM",
1014
1060
  explanation: "Debug mode in production configs exposes verbose logs, internal stack traces, and configuration details that aid attackers.",
1015
1061
  recommendation: "Set debug: false or remove the debug flag from production configuration.",
1016
1062
  blocking: true
@@ -1112,6 +1158,7 @@ var payments = {
1112
1158
  category: "payments",
1113
1159
  file: relativePath,
1114
1160
  evidence: "No call to stripe.webhooks.constructEvent() found",
1161
+ confidence: "MEDIUM",
1115
1162
  explanation: "Without calling stripe.webhooks.constructEvent(), the webhook endpoint cannot verify that requests originate from Stripe. Attackers can send forged events to trigger payment logic (e.g., fake payment_intent.succeeded) without making a real payment.",
1116
1163
  recommendation: "Verify every incoming webhook with stripe.webhooks.constructEvent(rawBody, sig, webhookSecret). Pass the raw request body \u2014 not a parsed JSON object \u2014 to prevent HMAC mismatch.",
1117
1164
  blocking: isBlocking(id, policy)
@@ -1126,6 +1173,7 @@ var payments = {
1126
1173
  category: "payments",
1127
1174
  file: relativePath,
1128
1175
  evidence: "No reference to stripe-signature header found",
1176
+ confidence: "MEDIUM",
1129
1177
  explanation: "The Stripe-Signature header carries the HMAC timestamp+hash that proves the request originated from Stripe. Without reading it, signature verification is impossible.",
1130
1178
  recommendation: 'Read the header with request.headers.get("stripe-signature") (Next.js) or req.headers["stripe-signature"] (Express) before calling constructEvent().',
1131
1179
  blocking: isBlocking(id, policy)
@@ -1142,6 +1190,7 @@ var payments = {
1142
1190
  category: "payments",
1143
1191
  file: relativePath,
1144
1192
  evidence: "No call to validateWebhookSignature() found",
1193
+ confidence: "MEDIUM",
1145
1194
  explanation: "Without validateWebhookSignature(), the webhook endpoint cannot verify that requests originate from Razorpay. An attacker can send forged payment confirmation events without completing an actual payment.",
1146
1195
  recommendation: "Use Razorpay.validateWebhookSignature(rawBody, signature, webhookSecret) where signature is taken from the x-razorpay-signature header. Always pass the raw (unparsed) body.",
1147
1196
  blocking: isBlocking(id, policy)
@@ -1160,6 +1209,7 @@ var payments = {
1160
1209
  category: "payments",
1161
1210
  file: relativePath,
1162
1211
  evidence: "Reference to STRIPE_SECRET_KEY found in a client-bundle file",
1212
+ confidence: "MEDIUM",
1163
1213
  explanation: "STRIPE_SECRET_KEY is a server-only secret. If it is bundled into client-side code it will be exposed in the browser, allowing anyone to make API calls on your behalf \u2014 creating charges, accessing customer data, or issuing refunds.",
1164
1214
  recommendation: "Move Stripe secret key usage exclusively to API routes (app/api/ or pages/api/). Use NEXT_PUBLIC_ prefix only for the Stripe publishable key.",
1165
1215
  blocking: isBlocking(id, policy)
@@ -1174,6 +1224,7 @@ var payments = {
1174
1224
  category: "payments",
1175
1225
  file: relativePath,
1176
1226
  evidence: "Reference to RAZORPAY_KEY_SECRET found in a client-bundle file",
1227
+ confidence: "MEDIUM",
1177
1228
  explanation: "RAZORPAY_KEY_SECRET is a server-only secret. Exposure in client-side code allows attackers to forge payment signatures and verify payments without completing them.",
1178
1229
  recommendation: "Use RAZORPAY_KEY_SECRET only in server-side API routes. For the client, only use the Razorpay key_id (public).",
1179
1230
  blocking: isBlocking(id, policy)
@@ -1190,6 +1241,7 @@ var payments = {
1190
1241
  category: "payments",
1191
1242
  file: relativePath,
1192
1243
  evidence: "No idempotency key, event.id check, or duplicate-detection logic found",
1244
+ confidence: "LOW",
1193
1245
  explanation: "Payment providers may deliver the same webhook event more than once (retries after network failure, provider-side bugs). Without idempotency guards, duplicate deliveries can cause double-charges, double-fulfillments, or double-refunds.",
1194
1246
  recommendation: "Record processed event IDs (e.g., store event.id in a database) before acting on the event. If the ID already exists, return 200 immediately without reprocessing.",
1195
1247
  blocking: isBlocking(id, policy)
@@ -1206,6 +1258,7 @@ var payments = {
1206
1258
  category: "payments",
1207
1259
  file: relativePath,
1208
1260
  evidence: "No try/catch block found in payment-related route",
1261
+ confidence: "LOW",
1209
1262
  explanation: "Unhandled exceptions in payment routes can leak stack traces to the client, cause silent failures in payment processing, and make debugging production incidents harder.",
1210
1263
  recommendation: "Wrap payment logic in try/catch. Return a structured error response (e.g., 500 with a generic message) and log the full error server-side.",
1211
1264
  blocking: isBlocking(id, policy)