ship-safe 3.1.0 → 3.2.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 CHANGED
@@ -5,6 +5,9 @@
5
5
 
6
6
  <p align="center">
7
7
  <a href="https://www.npmjs.com/package/ship-safe"><img src="https://badge.fury.io/js/ship-safe.svg" alt="npm version" /></a>
8
+ <a href="https://www.npmjs.com/package/ship-safe"><img src="https://img.shields.io/npm/dm/ship-safe.svg" alt="npm downloads" /></a>
9
+ <a href="https://github.com/asamassekou10/ship-safe/actions/workflows/ci.yml"><img src="https://github.com/asamassekou10/ship-safe/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
10
+ <a href="https://nodejs.org"><img src="https://img.shields.io/node/v/ship-safe" alt="Node.js version" /></a>
8
11
  <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT" /></a>
9
12
  </p>
10
13
 
@@ -19,23 +22,33 @@ You're shipping fast. You're using AI to write code. You're one `git push` away
19
22
  ## Quick Start
20
23
 
21
24
  ```bash
22
- # Scan for leaked secrets (no install required!)
25
+ # AI-powered audit: scan, classify with Claude, auto-fix confirmed secrets
26
+ npx ship-safe agent .
27
+
28
+ # Scan for secrets AND code vulnerabilities (SQL injection, XSS, etc.)
23
29
  npx ship-safe scan .
24
30
 
25
- # Auto-generate .env.example from found secrets
26
- npx ship-safe fix
31
+ # Security health score (0-100, A–F grade)
32
+ npx ship-safe score .
27
33
 
28
- # Block git push if secrets are found
29
- npx ship-safe guard
34
+ # Audit dependencies for known CVEs
35
+ npx ship-safe deps .
30
36
 
31
- # Run the launch-day security checklist
32
- npx ship-safe checklist
37
+ # Auto-fix hardcoded secrets: rewrite code + write .env
38
+ npx ship-safe remediate .
33
39
 
34
- # Add security configs to your project
35
- npx ship-safe init
40
+ # Revoke exposed keys opens provider dashboards with step-by-step guide
41
+ npx ship-safe rotate .
36
42
  ```
37
43
 
38
- That's it. Five commands to secure your MVP.
44
+ Or if you prefer the manual toolkit:
45
+
46
+ ```bash
47
+ npx ship-safe fix # Generate .env.example from secrets
48
+ npx ship-safe guard # Block git push if secrets found
49
+ npx ship-safe checklist # Run launch-day security checklist
50
+ npx ship-safe init # Add security configs to your project
51
+ ```
39
52
 
40
53
  ![ship-safe terminal demo](.github/assets/ship%20safe%20terminal.jpg)
41
54
 
@@ -67,9 +80,35 @@ This repo is your co-pilot for security. Copy, paste, ship safely.
67
80
 
68
81
  ## CLI Commands
69
82
 
83
+ ### `npx ship-safe agent [path]`
84
+
85
+ AI-powered security audit. Scans for both secrets and code vulnerabilities, sends findings to Claude for classification, auto-fixes confirmed secrets, and provides specific fix suggestions for code issues.
86
+
87
+ ```bash
88
+ # Full AI audit (requires ANTHROPIC_API_KEY)
89
+ npx ship-safe agent .
90
+
91
+ # Preview classification without writing any files
92
+ npx ship-safe agent . --dry-run
93
+
94
+ # Use a specific Claude model
95
+ npx ship-safe agent . --model claude-opus-4-6
96
+ ```
97
+
98
+ **Flow:**
99
+ 1. Scan for secrets + code vulnerabilities (XSS, SQLi, command injection, etc.)
100
+ 2. Send findings to Claude — classify each as `REAL` or `FALSE_POSITIVE`
101
+ 3. For secrets: auto-remediate confirmed findings (rewrite code + write `.env`)
102
+ 4. For code vulns: print Claude's verdict + specific 1-line fix suggestion
103
+ 5. Re-scan to verify secrets are gone
104
+
105
+ No `ANTHROPIC_API_KEY`? Falls back to `remediate` for secrets automatically.
106
+
107
+ ---
108
+
70
109
  ### `npx ship-safe scan [path]`
71
110
 
72
- Scans your codebase for leaked secrets: API keys, passwords, private keys, database URLs.
111
+ Scans your codebase for leaked secrets **and** code vulnerabilities.
73
112
 
74
113
  ```bash
75
114
  # Scan current directory
@@ -81,11 +120,14 @@ npx ship-safe scan ./src
81
120
  # Get JSON output (for CI pipelines)
82
121
  npx ship-safe scan . --json
83
122
 
123
+ # SARIF output for GitHub Code Scanning
124
+ npx ship-safe scan . --sarif
125
+
84
126
  # Verbose mode (show files being scanned)
85
127
  npx ship-safe scan . -v
86
128
  ```
87
129
 
88
- **Exit codes:** Returns `1` if secrets found (useful for CI), `0` if clean.
130
+ **Exit codes:** Returns `1` if issues found (useful for CI), `0` if clean.
89
131
 
90
132
  **Flags:**
91
133
  - `--json` — structured JSON output for CI pipelines
@@ -122,6 +164,109 @@ Or exclude paths with `.ship-safeignore` (gitignore syntax).
122
164
  - **Messaging:** Twilio, SendGrid, Resend
123
165
  - **And more:** GitHub tokens, private keys, JWTs, generic secrets
124
166
 
167
+ **Detects 18 code vulnerability patterns (OWASP Top 10):**
168
+ - **Injection:** SQL injection (template literals), command injection, code injection (`eval`)
169
+ - **XSS:** `dangerouslySetInnerHTML`, `innerHTML` assignment, `document.write`
170
+ - **Crypto:** MD5 / SHA-1 for passwords, weak random number generation
171
+ - **TLS:** `NODE_TLS_REJECT_UNAUTHORIZED=0`, `rejectUnauthorized: false`, Python `verify=False`
172
+ - **Deserialization:** `pickle.loads`, `yaml.load` without `Loader`
173
+ - **Misconfiguration:** CORS wildcard (`*`), deprecated `new Buffer()`
174
+
175
+ ---
176
+
177
+ ### `npx ship-safe remediate [path]`
178
+
179
+ Auto-fix hardcoded secrets: rewrites source files to use `process.env` variables, writes a `.env` file with the actual values, and updates `.gitignore`.
180
+
181
+ ```bash
182
+ # Auto-fix secrets
183
+ npx ship-safe remediate .
184
+
185
+ # Preview changes without writing any files
186
+ npx ship-safe remediate . --dry-run
187
+
188
+ # Apply all fixes without prompting (for CI)
189
+ npx ship-safe remediate . --yes
190
+
191
+ # Also run git add on modified files
192
+ npx ship-safe remediate . --stage
193
+ ```
194
+
195
+ ---
196
+
197
+ ### `npx ship-safe rotate [path]`
198
+
199
+ Revoke and rotate exposed secrets. Detects which providers your secrets belong to and opens the right dashboard with step-by-step revocation instructions.
200
+
201
+ ```bash
202
+ # Open dashboards for all detected secrets
203
+ npx ship-safe rotate .
204
+
205
+ # Rotate only a specific provider
206
+ npx ship-safe rotate . --provider github
207
+ npx ship-safe rotate . --provider stripe
208
+ npx ship-safe rotate . --provider openai
209
+ ```
210
+
211
+ **Supports:** OpenAI, Anthropic, GitHub, Stripe, AWS, Google Cloud, Supabase, and more.
212
+
213
+ ---
214
+
215
+ ### `npx ship-safe deps [path]`
216
+
217
+ Audit your dependencies for known CVEs using the project's native package manager.
218
+
219
+ ```bash
220
+ # Audit dependencies
221
+ npx ship-safe deps .
222
+
223
+ # Also run the package manager's auto-fix command
224
+ npx ship-safe deps . --fix
225
+ ```
226
+
227
+ **Supported package managers:**
228
+ - `npm` → `npm audit`
229
+ - `yarn` → `yarn audit`
230
+ - `pnpm` → `pnpm audit`
231
+ - `pip` → `pip-audit` (install with `pip install pip-audit`)
232
+ - `bundler` → `bundle-audit` (install with `gem install bundler-audit`)
233
+
234
+ Auto-detected from your lock file. Gracefully skips if the tool isn't installed.
235
+
236
+ ---
237
+
238
+ ### `npx ship-safe score [path]`
239
+
240
+ Compute a 0–100 security health score for your project. Combines secret detection, code vulnerability detection, and dependency CVEs into a single grade. No API key needed — instant and free.
241
+
242
+ ```bash
243
+ # Score the project
244
+ npx ship-safe score .
245
+
246
+ # Skip dependency audit (faster)
247
+ npx ship-safe score . --no-deps
248
+ ```
249
+
250
+ **Scoring (starts at 100):**
251
+
252
+ | Category | Critical | High | Medium | Cap |
253
+ |----------|----------|------|--------|-----|
254
+ | Secrets | −25 | −15 | −5 | −40 |
255
+ | Code Vulns | −20 | −10 | −3 | −30 |
256
+ | Dependencies | −20 | −10 | −5 | −30 |
257
+
258
+ **Grades:**
259
+
260
+ | Score | Grade | Verdict |
261
+ |-------|-------|---------|
262
+ | 90–100 | A | Ship it! |
263
+ | 75–89 | B | Minor issues to review |
264
+ | 60–74 | C | Fix before shipping |
265
+ | 40–59 | D | Significant security risks |
266
+ | 0–39 | F | Not safe to ship |
267
+
268
+ **Exit codes:** Returns `0` for A/B (≥ 75), `1` for C/D/F.
269
+
125
270
  ---
126
271
 
127
272
  ### `npx ship-safe checklist`
@@ -389,27 +534,46 @@ name: Security Scan
389
534
  on: [push, pull_request]
390
535
 
391
536
  jobs:
392
- scan-secrets:
537
+ security:
393
538
  runs-on: ubuntu-latest
394
539
  steps:
395
540
  - uses: actions/checkout@v4
396
- - name: Scan for secrets
541
+
542
+ - name: Scan for secrets and code vulnerabilities
397
543
  run: npx ship-safe scan . --json
544
+
545
+ - name: Audit dependencies for CVEs
546
+ run: npx ship-safe deps .
547
+
548
+ - name: Security health score (fail if C or below)
549
+ run: npx ship-safe score . --no-deps
398
550
  ```
399
551
 
400
- The scan exits with code `1` if secrets are found, failing your build.
552
+ Each command exits with code `1` on findings, failing your build. Use `--sarif` with `scan` to send results to GitHub's Security tab:
553
+
554
+ ```yaml
555
+ - name: Scan (SARIF for GitHub Security tab)
556
+ run: npx ship-safe scan . --sarif > results.sarif
557
+
558
+ - name: Upload to GitHub Security tab
559
+ uses: github/codeql-action/upload-sarif@v3
560
+ with:
561
+ sarif_file: results.sarif
562
+ ```
401
563
 
402
564
  ---
403
565
 
404
566
  ## The 5-Minute Security Checklist
405
567
 
406
- 1. ✅ Run `npx ship-safe scan .` on your project
407
- 2. ✅ Run `npx ship-safe init` to add security configs
408
- 3. ✅ Add security headers to your Next.js config
409
- 4. ✅ Run `npx ship-safe checklist` before launching
410
- 5. ✅ If using AI features, implement [cost protection](./ai-defense/cost-protection.md)
411
- 6. ✅ If using Supabase, check the [RLS checklist](./configs/supabase/security-checklist.md)
412
- 7. ✅ If using Firebase, check the [Firebase checklist](./configs/firebase/security-checklist.md)
568
+ 1. ✅ Run `npx ship-safe agent .` AI audit: finds + classifies + fixes secrets and code vulns
569
+ 2. ✅ Run `npx ship-safe deps .` audit your dependencies for known CVEs
570
+ 3. ✅ Run `npx ship-safe score .` — check your overall security health score
571
+ 4. ✅ Run `npx ship-safe init` add security configs (.gitignore, security headers)
572
+ 5. ✅ Run `npx ship-safe guard` install git hook to block pushes if secrets found
573
+ 6. ✅ Run `npx ship-safe checklist` — run the interactive launch-day security checklist
574
+ 7. ✅ If using AI features, implement [cost protection](./ai-defense/cost-protection.md)
575
+ 8. ✅ If using Supabase, check the [RLS checklist](./configs/supabase/security-checklist.md)
576
+ 9. ✅ If using Firebase, check the [Firebase checklist](./configs/firebase/security-checklist.md)
413
577
 
414
578
  ---
415
579
 
@@ -451,6 +615,12 @@ MIT - Use it, share it, secure your stuff.
451
615
 
452
616
  ---
453
617
 
618
+ ## Star History
619
+
620
+ [![Star History Chart](https://api.star-history.com/svg?repos=asamassekou10/ship-safe&type=Date)](https://star-history.com/#asamassekou10/ship-safe&Date)
621
+
622
+ ---
623
+
454
624
  **Remember: Security isn't about being paranoid. It's about being prepared.**
455
625
 
456
626
  Ship fast. Ship safe.
@@ -28,11 +28,16 @@ import { guardCommand } from '../commands/guard.js';
28
28
  import { mcpCommand } from '../commands/mcp.js';
29
29
  import { remediateCommand } from '../commands/remediate.js';
30
30
  import { rotateCommand } from '../commands/rotate.js';
31
+ import { agentCommand } from '../commands/agent.js';
32
+ import { depsCommand } from '../commands/deps.js';
33
+ import { scoreCommand } from '../commands/score.js';
31
34
 
32
35
  // =============================================================================
33
36
  // CLI CONFIGURATION
34
37
  // =============================================================================
35
38
 
39
+ const DEFAULT_MODEL = 'claude-haiku-4-5-20251001';
40
+
36
41
  // Read version from package.json
37
42
  const __filename = fileURLToPath(import.meta.url);
38
43
  const __dirname = dirname(__filename);
@@ -92,6 +97,7 @@ program
92
97
  .option('-f, --force', 'Overwrite existing files')
93
98
  .option('--gitignore', 'Only copy .gitignore')
94
99
  .option('--headers', 'Only copy security headers config')
100
+ .option('--agents', 'Only add security rules to AI agent instruction files (CLAUDE.md, .cursor/rules/, .windsurfrules, copilot-instructions.md)')
95
101
  .action(initCommand);
96
102
 
97
103
  // -----------------------------------------------------------------------------
@@ -140,6 +146,34 @@ program
140
146
  .option('--provider <name>', 'Only rotate secrets for a specific provider (e.g. github, stripe, openai)')
141
147
  .action(rotateCommand);
142
148
 
149
+ // -----------------------------------------------------------------------------
150
+ // AGENT COMMAND
151
+ // -----------------------------------------------------------------------------
152
+ program
153
+ .command('agent [path]')
154
+ .description('AI-powered security audit: scan, classify with Claude, auto-remediate confirmed secrets')
155
+ .option('--dry-run', 'Show classification and plan without writing any files')
156
+ .option('--model <model>', `Claude model to use (default: ${DEFAULT_MODEL})`)
157
+ .action(agentCommand);
158
+
159
+ // -----------------------------------------------------------------------------
160
+ // DEPS COMMAND
161
+ // -----------------------------------------------------------------------------
162
+ program
163
+ .command('deps [path]')
164
+ .description('Audit dependencies for known CVEs (npm, yarn, pnpm, pip-audit, bundler-audit)')
165
+ .option('--fix', 'Run the package manager fix command after auditing')
166
+ .action(depsCommand);
167
+
168
+ // -----------------------------------------------------------------------------
169
+ // SCORE COMMAND
170
+ // -----------------------------------------------------------------------------
171
+ program
172
+ .command('score [path]')
173
+ .description('Compute a 0-100 security health score for your project')
174
+ .option('--no-deps', 'Skip dependency audit')
175
+ .action(scoreCommand);
176
+
143
177
  // -----------------------------------------------------------------------------
144
178
  // PARSE AND RUN
145
179
  // -----------------------------------------------------------------------------
@@ -148,12 +182,15 @@ program
148
182
  if (process.argv.length === 2) {
149
183
  console.log(banner);
150
184
  console.log(chalk.yellow('\nQuick start:\n'));
185
+ console.log(chalk.white(' npx ship-safe agent . ') + chalk.gray('# AI audit: scan + classify + auto-fix'));
151
186
  console.log(chalk.white(' npx ship-safe scan . ') + chalk.gray('# Scan for secrets'));
152
187
  console.log(chalk.white(' npx ship-safe remediate . ') + chalk.gray('# Auto-fix: rewrite code + write .env'));
153
188
  console.log(chalk.white(' npx ship-safe rotate . ') + chalk.gray('# Revoke exposed keys (provider guides)'));
154
189
  console.log(chalk.white(' npx ship-safe fix ') + chalk.gray('# Generate .env.example from secrets'));
155
190
  console.log(chalk.white(' npx ship-safe guard ') + chalk.gray('# Block git push if secrets found'));
156
191
  console.log(chalk.white(' npx ship-safe checklist ') + chalk.gray('# Run security checklist'));
192
+ console.log(chalk.white(' npx ship-safe deps . ') + chalk.gray('# Audit dependencies for CVEs'));
193
+ console.log(chalk.white(' npx ship-safe score . ') + chalk.gray('# Security health score (0-100)'));
157
194
  console.log(chalk.white(' npx ship-safe init ') + chalk.gray('# Add security configs to your project'));
158
195
  console.log(chalk.white('\n npx ship-safe --help ') + chalk.gray('# Show all options'));
159
196
  console.log();