security-reporter 1.0.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +21 -0
  3. package/README.md +452 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +272 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/core/checks/docker.d.ts +6 -0
  9. package/dist/core/checks/docker.d.ts.map +1 -0
  10. package/dist/core/checks/docker.js +69 -0
  11. package/dist/core/checks/docker.js.map +1 -0
  12. package/dist/core/checks/quality.d.ts +6 -0
  13. package/dist/core/checks/quality.d.ts.map +1 -0
  14. package/dist/core/checks/quality.js +89 -0
  15. package/dist/core/checks/quality.js.map +1 -0
  16. package/dist/core/checks/security.d.ts +6 -0
  17. package/dist/core/checks/security.d.ts.map +1 -0
  18. package/dist/core/checks/security.js +927 -0
  19. package/dist/core/checks/security.js.map +1 -0
  20. package/dist/core/checks/tests.d.ts +6 -0
  21. package/dist/core/checks/tests.d.ts.map +1 -0
  22. package/dist/core/checks/tests.js +204 -0
  23. package/dist/core/checks/tests.js.map +1 -0
  24. package/dist/core/html-reporter.d.ts +11 -0
  25. package/dist/core/html-reporter.d.ts.map +1 -0
  26. package/dist/core/html-reporter.js +474 -0
  27. package/dist/core/html-reporter.js.map +1 -0
  28. package/dist/core/pdf-reporter.d.ts +6 -0
  29. package/dist/core/pdf-reporter.d.ts.map +1 -0
  30. package/dist/core/pdf-reporter.js +147 -0
  31. package/dist/core/pdf-reporter.js.map +1 -0
  32. package/dist/core/quality-advanced.d.ts +6 -0
  33. package/dist/core/quality-advanced.d.ts.map +1 -0
  34. package/dist/core/quality-advanced.js +536 -0
  35. package/dist/core/quality-advanced.js.map +1 -0
  36. package/dist/core/reporter.d.ts +18 -0
  37. package/dist/core/reporter.d.ts.map +1 -0
  38. package/dist/core/reporter.js +389 -0
  39. package/dist/core/reporter.js.map +1 -0
  40. package/dist/core/security-advanced.d.ts +6 -0
  41. package/dist/core/security-advanced.d.ts.map +1 -0
  42. package/dist/core/security-advanced.js +676 -0
  43. package/dist/core/security-advanced.js.map +1 -0
  44. package/dist/core/validators.d.ts +6 -0
  45. package/dist/core/validators.d.ts.map +1 -0
  46. package/dist/core/validators.js +81 -0
  47. package/dist/core/validators.js.map +1 -0
  48. package/dist/index.d.ts +5 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +14 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/interfaces/Types.d.ts +63 -0
  53. package/dist/interfaces/Types.d.ts.map +1 -0
  54. package/dist/interfaces/Types.js +3 -0
  55. package/dist/interfaces/Types.js.map +1 -0
  56. package/dist/test/security.test.d.ts +2 -0
  57. package/dist/test/security.test.d.ts.map +1 -0
  58. package/dist/test/security.test.js +16 -0
  59. package/dist/test/security.test.js.map +1 -0
  60. package/dist/test/test.d.ts +2 -0
  61. package/dist/test/test.d.ts.map +1 -0
  62. package/dist/test/test.js +11 -0
  63. package/dist/test/test.js.map +1 -0
  64. package/dist/test/test.spec.d.ts +2 -0
  65. package/dist/test/test.spec.d.ts.map +1 -0
  66. package/dist/test/test.spec.js +7 -0
  67. package/dist/test/test.spec.js.map +1 -0
  68. package/dist/types/cli.d.ts +4 -0
  69. package/dist/types/cli.d.ts.map +1 -0
  70. package/dist/types/core/checks/docker.d.ts +11 -0
  71. package/dist/types/core/checks/docker.d.ts.map +1 -0
  72. package/dist/types/core/checks/quality.d.ts +13 -0
  73. package/dist/types/core/checks/quality.d.ts.map +1 -0
  74. package/dist/types/core/checks/security.d.ts +13 -0
  75. package/dist/types/core/checks/security.d.ts.map +1 -0
  76. package/dist/types/core/checks/tests.d.ts +9 -0
  77. package/dist/types/core/checks/tests.d.ts.map +1 -0
  78. package/dist/types/core/reporter.d.ts +13 -0
  79. package/dist/types/core/reporter.d.ts.map +1 -0
  80. package/dist/types/index.d.ts +3 -0
  81. package/dist/types/index.d.ts.map +1 -0
  82. package/dist/types/interfaces/Types.d.ts +27 -0
  83. package/dist/types/interfaces/Types.d.ts.map +1 -0
  84. package/package.json +75 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [1.1.2] - 2025-06-24
6
+
7
+ ### Changed
8
+
9
+ - The engines in package.json was to strict, only `"node": ">=16"` needed.
10
+
11
+ ## [1.1.1] - 2025-06-17
12
+
13
+ ### Changed
14
+
15
+ - Improved readme
16
+
17
+ ## [1.1.0] - 2025-06-12
18
+
19
+ ### Fixed
20
+
21
+ - Refactored `httpErrorFormatter` to accept the error directly as an argument `httpErrorFormatter(err)` instead of an object `httpErrorFormatter({ err })`, improving usability and simplifying the helper.
22
+ - Removed unnecessary async keyword from `httpErrorFormatter` function since no asynchronous operations are performed, enhancing clarity and performance.
23
+ - Updated README to include usage examples for the `error-drawings` package, providing clearer documentation and better onboarding for new users.
24
+
25
+ ## [1.0.4] - 2025-06-11
26
+
27
+ ### Fixed
28
+
29
+ # Changelog
30
+
31
+ ## 0.1.0 - Initial repository creation
32
+
33
+ - Repository created for `security-reporter`.
34
+ - See `PROJECT_SUMMARY.md` for project scope, goals and configuration notes.
35
+ - Initial `package.json`, `.gitignore` and basic project layout added.
36
+
37
+ Further changes will be recorded here following Keep a Changelog conventions.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Erik Sturesson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,452 @@
1
+ # License: MIT © Erik Sturesson
2
+
3
+ # 🛡️ Security Reporter
4
+
5
+ > Security and quality reporter for Node.js projects
6
+
7
+ ![npm version](https://img.shields.io/npm/v/@eriksturesson%2Fsecurity-reporter)
8
+ ![npm downloads (monthly)](https://img.shields.io/npm/dm/@eriksturesson%2Fsecurity-reporter)
9
+ ![npm license](https://img.shields.io/npm/l/@eriksturesson%2Fsecurity-reporter)
10
+
11
+ Security Reporter is a local CLI tool that scans a repository for common security and quality issues and writes human- and machine-readable reports to `reports/`.
12
+
13
+ Quick facts:
14
+
15
+ - Runs entirely locally by default; network checks are opt‑in.
16
+ - Reports are written to the `reports/` directory (gitignored by default).
17
+ - The project is currently `private` to prevent accidental publishing.
18
+
19
+ Install (local/test):
20
+
21
+ ```bash
22
+ # Install dev dependency
23
+ npm install --save-dev .
24
+
25
+ # Or run directly with npx from the repo root
26
+ npx ./dist/cli.js
27
+ ```
28
+
29
+ Run the scan:
30
+
31
+ ```bash
32
+ npm run report
33
+ # or
34
+ security-reporter
35
+ ```
36
+
37
+ Output:
38
+
39
+ - `reports/security-report.json` (JSON report)
40
+ - `reports/security-report.html` (human-readable HTML)
41
+ - `reports/sbom-npm-ls.json` (optional, when enabled)
42
+
43
+ Security notes (short):
44
+
45
+ - The package is marked `private: true` to avoid accidental publish to npm.
46
+ - Install-time lifecycle scripts were removed to reduce risk; review `package.json` for any remaining scripts.
47
+ - If you must publish this package to npm, follow the public checklist in `README_PUBLIC.md` and remove `private` only when ready.
48
+
49
+ Want a public-ready guide or contribution guidelines? See `README_PUBLIC.md`, `CONTRIBUTING.md`, and `SECURITY.md`.
50
+
51
+ Security Reporter is a comprehensive security and quality scanning tool for Node.js projects. It performs security audits, scans for secrets, validates dependencies, and generates detailed reports in multiple formats (terminal, JSON, Markdown, PDF).
52
+
53
+ **⚠️ Privacy Promise:** This tool NEVER saves, stores, or transmits your `.env` files or secrets. All scanning is done locally, and sensitive data stays in your repository.
54
+
55
+ **📋 Important:** This is a reporting tool. It identifies security and quality issues but does not automatically fix them. You remain in full control of your codebase.
56
+
57
+ **📚 Based on:** [OWASP NPM Security Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/NPM_Security_Cheat_Sheet.html)
58
+
59
+ ## ✨ Features
60
+
61
+ - 🔒 **Security Checks**
62
+ - npm audit for vulnerabilities
63
+ - Secret scanning in source code
64
+ - .env file validation
65
+ - License compliance checking
66
+
67
+ - 📦 **Quality Checks**
68
+ - Unused dependencies detection
69
+ - Duplicate dependencies
70
+ - Outdated packages
71
+ - Missing peer dependencies
72
+
73
+ - 🐳 **Docker Validation**
74
+ - Environment variable security
75
+ - .dockerignore configuration
76
+ - Build argument validation
77
+
78
+ - 🧪 **Test Verification**
79
+ - Test setup validation
80
+ - Build script checking
81
+
82
+ - 📊 **Smart Reporting**
83
+ - Terminal output with colors and emojis
84
+ - JSON export for CI/CD
85
+ - Executive summary
86
+ - Actionable suggestions
87
+
88
+ ## 📦 Installation
89
+
90
+ ```bash
91
+ # Global installation (recommended)
92
+ npm install -g security-reporter
93
+
94
+ # Or use in project
95
+ npm install --save-dev security-reporter
96
+
97
+ # Or run directly with npx
98
+ npx security-reporter
99
+ ```
100
+
101
+ ## 🚀 Quick Start
102
+
103
+ ```bash
104
+ # Run security scan
105
+ security-reporter
106
+
107
+ # Or use the short alias
108
+ sr
109
+
110
+ # Initialize config file
111
+ security-reporter init
112
+
113
+ # Generate Markdown report
114
+ security-reporter --format markdown --output security-report.md
115
+
116
+ # Generate JSON for CI/CD
117
+ security-reporter --format json --output report.json
118
+
119
+ # Strict mode (warnings fail CI)
120
+ security-reporter --strict
121
+ ```
122
+
123
+ ## ⚙️ Configuration
124
+
125
+ Create a `.guardianrc.json` file in your project root:
126
+
127
+ ```json
128
+ {
129
+ "projectType": "backend",
130
+ "security": {
131
+ "auditLevel": "moderate",
132
+ "checkSecrets": true,
133
+ "allowedLicenses": ["MIT", "Apache-2.0"]
134
+ },
135
+ "quality": {
136
+ "checkUnused": true,
137
+ "checkDuplicates": true,
138
+ "checkOutdated": true,
139
+ "allowUnused": ["@types/*"]
140
+ },
141
+ "docker": {
142
+ "checkEnvInBuild": true,
143
+ "requiredEnvVars": ["NODE_ENV"]
144
+ },
145
+ "tests": {
146
+ "run": false
147
+ }
148
+ }
149
+ ```
150
+
151
+ ### Project Types
152
+
153
+ - `backend` - Node.js backend projects (Express, Fastify, NestJS, etc.)
154
+ - `frontend` - Frontend projects (React, Vue, Angular, etc.)
155
+ - `fullstack` - Full-stack projects with both frontend and backend
156
+
157
+ Different project types have slightly different validation rules.
158
+
159
+ ## 📋 Usage Examples
160
+
161
+ ### Basic Usage
162
+
163
+ ```bash
164
+ # Run all checks
165
+ repo-guardian
166
+
167
+ # Skip specific check categories
168
+ repo-guardian --no-docker --no-tests
169
+
170
+ # Specify project type
171
+ repo-guardian --project-type frontend
172
+ ```
173
+
174
+ ### CI/CD Integration
175
+
176
+ **GitHub Actions:**
177
+
178
+ ```yaml
179
+ name: Code Validation
180
+
181
+ on: [push, pull_request]
182
+
183
+ jobs:
184
+ validate:
185
+ runs-on: ubuntu-latest
186
+ steps:
187
+ - uses: actions/checkout@v3
188
+ - uses: actions/setup-node@v3
189
+ with:
190
+ node-version: "18"
191
+ - run: npm install
192
+ - run: npx repo-guardian --strict --format json --output report.json
193
+ - uses: actions/upload-artifact@v3
194
+ if: always()
195
+ with:
196
+ name: validation-report
197
+ path: report.json
198
+ ```
199
+
200
+ **GitLab CI:**
201
+
202
+ ```yaml
203
+ validate:
204
+ stage: test
205
+ script:
206
+ - npm install
207
+ - npx repo-guardian --strict
208
+ artifacts:
209
+ when: always
210
+ reports:
211
+ junit: report.json
212
+ ```
213
+
214
+ ### Package.json Scripts
215
+
216
+ ```json
217
+ {
218
+ "scripts": {
219
+ "validate": "repo-guardian",
220
+ "validate:ci": "repo-guardian --strict --format json",
221
+ "precommit": "repo-guardian --no-tests"
222
+ }
223
+ }
224
+ ```
225
+
226
+ ### Programmatic Usage
227
+
228
+ ```typescript
229
+ import { runValidation, reportToTerminal } from "repo-guardian";
230
+
231
+ const config = {
232
+ projectType: "backend",
233
+ security: {
234
+ auditLevel: "high",
235
+ checkSecrets: true,
236
+ },
237
+ };
238
+
239
+ const report = await runValidation(config);
240
+ reportToTerminal(report);
241
+
242
+ if (report.overallStatus === "fail") {
243
+ process.exit(1);
244
+ }
245
+ ```
246
+
247
+ ## 🔍 What Gets Checked?
248
+
249
+ ### Security
250
+
251
+ - ✅ npm vulnerabilities (via `npm audit`)
252
+ - ✅ Hardcoded secrets (API keys, tokens, passwords)
253
+ - ✅ .env file exposure
254
+ - ✅ License compliance
255
+ - ✅ Outdated security patches
256
+
257
+ ### Quality
258
+
259
+ - ✅ Unused dependencies
260
+ - ✅ Duplicate packages
261
+ - ✅ Outdated dependencies
262
+ - ✅ Missing peer dependencies
263
+ - ✅ Package size optimization
264
+
265
+ ### Docker (if Dockerfile present)
266
+
267
+ - ✅ .env not copied into image
268
+ - ✅ Secrets not hardcoded
269
+ - ✅ .dockerignore configuration
270
+ - ✅ Build argument validation
271
+
272
+ ### Tests & Build
273
+
274
+ - ✅ Test script configured
275
+ - ✅ Test files present
276
+ - ✅ Build script works
277
+ - ✅ TypeScript compilation
278
+
279
+ ## 📊 Example Output
280
+
281
+ ```
282
+ ======================================================================
283
+ 🛡️ Repo Guardian - Validation Report
284
+ ======================================================================
285
+ Project Type: backend
286
+ Timestamp: 2025-01-15T10:30:00.000Z
287
+ Execution Time: 1234ms
288
+ ======================================================================
289
+
290
+ ❌ FAILED CHECKS:
291
+
292
+ ❌ npm audit [🔴 CRITICAL]
293
+ Found 3 vulnerabilities
294
+ - high: 2
295
+ - critical: 1
296
+ 💡 Suggestions:
297
+ • Run 'npm audit fix' to fix vulnerabilities
298
+
299
+ ⚠️ WARNINGS:
300
+
301
+ ⚠️ unused dependencies [🟡 WARNING]
302
+ Found 2 potentially unused dependencies
303
+ - lodash
304
+ - moment
305
+ 💡 Suggestions:
306
+ • Review and remove unused dependencies
307
+
308
+ ✅ PASSED CHECKS:
309
+
310
+ ✓ secrets scan: No hardcoded secrets found
311
+ ✓ env files: Environment files properly configured
312
+ ✓ peer dependencies: All peer dependencies satisfied
313
+
314
+ ======================================================================
315
+ SUMMARY:
316
+ Total Checks: 12
317
+ ✅ Passed: 8
318
+ ⚠️ Warnings: 3
319
+ ❌ Failed: 1
320
+ ⏭️ Skipped: 0
321
+ ======================================================================
322
+
323
+ Overall Status: ❌ FAIL
324
+ ```
325
+
326
+ ## 🎯 Use Cases
327
+
328
+ ### For Developers
329
+
330
+ Run before committing to catch issues early:
331
+
332
+ ```bash
333
+ # Add to pre-commit hook
334
+ npx repo-guardian --no-tests
335
+ ```
336
+
337
+ ### For Teams
338
+
339
+ Ensure consistent quality across all repos:
340
+
341
+ ```bash
342
+ # Same config in all projects
343
+ repo-guardian init
344
+ # Customize .securityrc.json once, copy everywhere
345
+ ```
346
+
347
+ ### For CI/CD
348
+
349
+ Automated validation on every push:
350
+
351
+ ```bash
352
+ repo-guardian --strict --format json
353
+ ```
354
+
355
+ ### For Managers
356
+
357
+ Get a quick overview of code quality:
358
+
359
+ ```bash
360
+ repo-guardian --format json | jq '.summary'
361
+ ```
362
+
363
+ ## 🔧 Advanced Configuration
364
+
365
+ ### Custom Audit Level
366
+
367
+ ```json
368
+ {
369
+ "security": {
370
+ "auditLevel": "critical" // Only fail on critical vulnerabilities
371
+ }
372
+ }
373
+ ```
374
+
375
+ ### Allow Specific Unused Packages
376
+
377
+ ```json
378
+ {
379
+ "quality": {
380
+ "allowUnused": [
381
+ "@types/*", // Type definitions
382
+ "husky", // Git hooks
383
+ "prettier" // Code formatter
384
+ ]
385
+ }
386
+ }
387
+ ```
388
+
389
+ ### Docker Security
390
+
391
+ ```json
392
+ {
393
+ "docker": {
394
+ "checkEnvInBuild": true,
395
+ "requiredEnvVars": ["NODE_ENV", "PORT", "DATABASE_URL"]
396
+ }
397
+ }
398
+ ```
399
+
400
+ ## 🤝 Contributing
401
+
402
+ Contributions welcome! Please open an issue or PR.
403
+
404
+ ## 📝 License
405
+
406
+ MIT © Erik Sturesson
407
+
408
+ ## 🔗 Links
409
+
410
+ - [GitHub Repository](https://github.com/eriksturesson/repo-guardian)
411
+ - [npm Package](https://www.npmjs.com/package/repo-guardian)
412
+ - [Issue Tracker](https://github.com/eriksturesson/repo-guardian/issues)
413
+
414
+ ## Reports and Secure Sharing
415
+
416
+ By default `security-reporter` writes generated artifacts to a local `reports/` directory in the project root. This folder is added to `.gitignore` by default to avoid accidentally committing potentially sensitive information (vulnerability details, file paths, or traces of secrets).
417
+
418
+ Recommended handling of `reports/`:
419
+
420
+ - Keep `reports/` in `.gitignore` (default behavior).
421
+ - If you need to share a report, publish it as a CI artifact (GitHub Actions / GitLab artifacts) or upload it to a secured storage (private S3/Blob storage) and share a link.
422
+ - Avoid committing reports to the repo history — use release artifacts or encrypted storage when long-term archiving is required.
423
+
424
+ Opt-in features and how to enable them (OWASP-aligned):
425
+
426
+ - `publishDryRun` (boolean) — run `npm pack --dry-run` to validate what would be published. Enable via `.securityrc.json` under `security.publishDryRun`.
427
+ - `generateSbom` (boolean) — generate a basic SBOM via `npm ls --all --json` and write it to `reports/sbom-npm-ls.json`. Enable via `security.generateSbom`.
428
+ - `checkRegistry` (boolean) — optionally query the npm registry for the package name to surface maintainer/download metadata. Enable via `security.checkRegistry`.
429
+
430
+ Example `.securityrc.json` snippet to opt-in:
431
+
432
+ ```json
433
+ {
434
+ "security": {
435
+ "auditLevel": "moderate",
436
+ "checkSecrets": true,
437
+ "publishDryRun": false,
438
+ "generateSbom": false,
439
+ "checkRegistry": false
440
+ }
441
+ }
442
+ ```
443
+
444
+ OWASP alignment
445
+
446
+ - This tool is designed to follow the OWASP NPM Security Cheat Sheet guidance: avoid pushing secrets, use lockfiles, run SCA scans, produce SBOMs, and validate publish contents before release. The checks implemented map to the condensed OWASP checklist (publish safety, lockfile, script safety, SCA/audit, SBOM guidance, registry checks).
447
+
448
+ If you want, I can also add a small GitHub Actions workflow template that runs the report on push and uploads `reports/security-report.json` as an artifact (recommended for secure sharing).
449
+
450
+ ## 💬 Feedback
451
+
452
+ Found a bug? Have a suggestion? [Open an issue](https://github.com/eriksturesson/repo-guardian/issues)!
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}