plumber-linter 1.2.0 → 1.3.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
@@ -1,6 +1,6 @@
1
1
  # Plumber
2
2
 
3
- CI/CD pipeline linter that flags hardcoded secrets, leaked credentials, and dead code — with fixes in plain English.
3
+ CI/CD pipeline linter that flags hardcoded secrets, leaked credentials, and dead code — with fixes in plain English, plus SARIF output for GitHub code scanning.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/plumber-linter.svg)](https://www.npmjs.com/package/plumber-linter)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/parasraju/plumber/blob/main/LICENSE)
@@ -32,9 +32,10 @@ npx plumber-linter scan .
32
32
  # Enforce quality gate in CI (exit 1 on HIGH or CRITICAL issues)
33
33
  npx plumber-linter scan . --fail-on high
34
34
 
35
- # Export report as Markdown or JSON
35
+ # Export report as Markdown, JSON, or SARIF 2.1.0
36
36
  npx plumber-linter scan . --format md
37
37
  npx plumber-linter scan . --format json
38
+ npx plumber-linter scan . --format sarif
38
39
 
39
40
  # View all 26 inspection rules
40
41
  npx plumber-linter rules
@@ -68,6 +69,38 @@ npx plumber-linter install-hook --fail-on high
68
69
  npx plumber-linter uninstall-hook
69
70
  ```
70
71
 
72
+ ### SARIF output for GitHub code scanning
73
+
74
+ `plumber scan . --format sarif` writes SARIF 2.1.0 JSON to stdout. The file contains one run for `plumber-linter` 1.3.0, every inspection rule (id, name, description, and the plain-English fix in `help.text`), and one result per finding. Each result's `message.text` repeats that finding's explanation and fix. Paths are relative to the scanned directory, and the line is included when the engine recorded one.
75
+
76
+ ```bash
77
+ npx plumber-linter scan . --format sarif > results.sarif
78
+ ```
79
+
80
+ Upload `results.sarif` with GitHub's `upload-sarif` action. The action name, the `sarif_file` input, and the `security-events: write` permission below are taken from GitHub's [Uploading a SARIF file to GitHub](https://docs.github.com/en/code-security/how-tos/find-and-fix-code-vulnerabilities/integrate-with-existing-tools/upload-sarif-file) guide. `partialFingerprints` is left unset; that same action calculates it when the repository contains both the SARIF file and the scanned source.
81
+
82
+ ```yaml
83
+ name: Plumber code scanning
84
+ on:
85
+ push:
86
+ jobs:
87
+ plumber:
88
+ runs-on: ubuntu-latest
89
+ permissions:
90
+ security-events: write
91
+ actions: read
92
+ contents: read
93
+ steps:
94
+ - name: Checkout repository
95
+ uses: actions/checkout@v6
96
+ - name: Run Plumber
97
+ run: npx plumber-linter scan . --format sarif > results.sarif
98
+ - name: Upload SARIF file
99
+ uses: github/codeql-action/upload-sarif@v4
100
+ with:
101
+ sarif_file: results.sarif
102
+ ```
103
+
71
104
  ---
72
105
 
73
106
  ## What It Checks
@@ -152,6 +185,9 @@ Spots hallucinated library imports invented by LLMs or packages missing from pro
152
185
 
153
186
  ## Changelog
154
187
 
188
+ ## 1.3.0
189
+ SARIF output (`--format sarif`) for GitHub code scanning.
190
+
155
191
  ## 1.2.0
156
192
  - `pipe/docker-unpinned`: Flag unpinned Docker images (no tag or `:latest`) in CI jobs and Dockerfiles (`MEDIUM`).
157
193
  - `sec/curl-pipe-shell`: Flag `curl | bash` and `wget | sh` remote script execution in CI run steps (`CRITICAL`).
package/bin/plumber.js CHANGED
@@ -74,6 +74,8 @@ const RULES = [
74
74
  ];
75
75
 
76
76
  const SEV_WEIGHT = { CRITICAL: 4, HIGH: 3, MEDIUM: 2, LOW: 1, INFO: 0 };
77
+ const SARIF_SCHEMA = 'https://json.schemastore.org/sarif-2.1.0.json';
78
+ const INFORMATION_URI = 'https://github.com/parasraju/plumber';
77
79
 
78
80
  // Main entry
79
81
  const args = process.argv.slice(2);
@@ -104,7 +106,7 @@ if (cmd === 'mcp') {
104
106
 
105
107
  function printHelp() {
106
108
  console.log(`
107
- Plumber — Code Leak, Clog, and AI Slop Inspector (v1.0.0)
109
+ Plumber — Code Leak, Clog, and AI Slop Inspector (v1.3.0)
108
110
 
109
111
  USAGE:
110
112
  npx plumber-linter scan [target] [options]
@@ -123,7 +125,7 @@ COMMANDS:
123
125
  mcp Run stdio Model Context Protocol (MCP) server for Claude / Cursor
124
126
 
125
127
  OPTIONS:
126
- --format [pretty|json|md] Output format (default: pretty)
128
+ --format [pretty|json|md|sarif] Output format (default: pretty)
127
129
  --fail-on [critical|high|medium|low] Exit code 1 if issues >= severity exist
128
130
  `);
129
131
  }
@@ -248,7 +250,7 @@ function inspectFile(relPath, content, lines, ext) {
248
250
  lines.forEach((l, idx) => {
249
251
  const trim = l.trim();
250
252
  if (trim.startsWith('#') || trim.startsWith('//') || trim.startsWith('/*')) return;
251
- if (ext === '.py' && /^\s*except(?:\s+\w+)?:\s*(?:pass|\.\.\.)/.test(l)) {
253
+ if (ext === '.py' && /^\s*except(?:\s+(?:\(\s*)?(?:Exception|BaseException)(?:\s*\))?)?\s*:\s*(?:pass|\.\.\.)/.test(l)) {
252
254
  issues.push({ rule_id: 'clog/swallowed-error', title: 'Swallowed Exception (Silent Failure)', severity: 'HIGH', line: idx + 1, evidence: trim, fix: 'Log the error or properly re-raise/handle it.' });
253
255
  } else if (ext !== '.py' && /catch\s*\([^)]*\)\s*\{\s*\}/.test(l)) {
254
256
  issues.push({ rule_id: 'clog/swallowed-error', title: 'Swallowed Exception (Silent Failure)', severity: 'HIGH', line: idx + 1, evidence: trim, fix: 'Log the error or properly re-raise/handle it.' });
@@ -261,6 +263,7 @@ function inspectFile(relPath, content, lines, ext) {
261
263
  lines.forEach((l, idx) => {
262
264
  const trim = l.trim();
263
265
  if (trim.startsWith('#') || trim.startsWith('//')) return;
266
+ if (trim.includes('@openssh') || trim.includes('sk-ssh-') || trim.includes('sk-ecdsa-')) return;
264
267
  if (/\b(sk-(?:live|test|proj)?[a-zA-Z0-9_-]{24,})\b/.test(l)) {
265
268
  issues.push({ rule_id: 'leak/api-key', title: 'Leaked OpenAI / Model API Key', severity: 'CRITICAL', line: idx + 1, evidence: trim.slice(0, 70), fix: 'Extract secret to .env file immediately.' });
266
269
  }
@@ -479,6 +482,93 @@ function findUnreachable(lines, start, indent, skip, isPy) {
479
482
  return null;
480
483
  }
481
484
 
485
+ function sarifLevel(severity) {
486
+ const level = String(severity || '').toUpperCase();
487
+ if (level === 'CRITICAL' || level === 'HIGH') return 'error';
488
+ if (level === 'MEDIUM') return 'warning';
489
+ return 'note';
490
+ }
491
+
492
+ function readPackageVersion() {
493
+ const pkgPath = path.join(__dirname, '..', 'package.json');
494
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
495
+ if (typeof pkg.version !== 'string' || pkg.version.length === 0) {
496
+ throw new Error(`Missing version in ${pkgPath}`);
497
+ }
498
+ return pkg.version;
499
+ }
500
+
501
+ function sarifArtifactUri(filePath) {
502
+ return String(filePath).replace(/\\/g, '/').split('/').map((segment) => encodeURIComponent(segment)).join('/');
503
+ }
504
+
505
+ function sarifMessage(issue) {
506
+ const explanation = String(issue.title || issue.rule_id || 'Plumber finding').trim();
507
+ const sentence = /[.!?]$/.test(explanation) ? explanation : `${explanation}.`;
508
+ const fix = String(issue.fix || '').trim();
509
+ if (!fix) return sentence;
510
+ return `${sentence} Fix: ${fix}`;
511
+ }
512
+
513
+ function sarifResult(issue, filePath, ruleIndexById) {
514
+ const result = { ruleId: issue.rule_id };
515
+ const ruleIndex = ruleIndexById.get(issue.rule_id);
516
+ if (ruleIndex !== undefined) result.ruleIndex = ruleIndex;
517
+ result.level = sarifLevel(issue.severity);
518
+ result.message = { text: sarifMessage(issue) };
519
+ if (filePath) {
520
+ const physicalLocation = {
521
+ artifactLocation: { uri: sarifArtifactUri(filePath) }
522
+ };
523
+ // Region is omitted when the engine has no line. Line 1 is not invented.
524
+ if (Number.isInteger(issue.line) && issue.line >= 1) {
525
+ physicalLocation.region = { startLine: issue.line };
526
+ }
527
+ result.locations = [{ physicalLocation }];
528
+ }
529
+ return result;
530
+ }
531
+
532
+ function buildSarif(report) {
533
+ const ruleIndexById = new Map(RULES.map((rule, index) => [rule.id, index]));
534
+ const covered = new Set();
535
+ const results = [];
536
+ for (const file of report.file_reports || []) {
537
+ for (const issue of file.issues) {
538
+ covered.add(issue);
539
+ results.push(sarifResult(issue, file.path, ruleIndexById));
540
+ }
541
+ }
542
+ for (const issue of report.issues || []) {
543
+ if (!covered.has(issue)) results.push(sarifResult(issue, null, ruleIndexById));
544
+ }
545
+
546
+ return {
547
+ $schema: SARIF_SCHEMA,
548
+ version: '2.1.0',
549
+ runs: [
550
+ {
551
+ tool: {
552
+ driver: {
553
+ name: 'plumber-linter',
554
+ version: readPackageVersion(),
555
+ informationUri: INFORMATION_URI,
556
+ rules: RULES.map((rule) => ({
557
+ id: rule.id,
558
+ name: rule.title,
559
+ shortDescription: { text: rule.title },
560
+ fullDescription: { text: rule.title },
561
+ help: { text: rule.fix },
562
+ defaultConfiguration: { level: sarifLevel(rule.sev) }
563
+ }))
564
+ }
565
+ },
566
+ results
567
+ }
568
+ ]
569
+ };
570
+ }
571
+
482
572
  function renderReport(report, fmt, failOn) {
483
573
  if (fmt === 'json') {
484
574
  console.log(JSON.stringify(report, null, 2));
@@ -491,6 +581,8 @@ function renderReport(report, fmt, failOn) {
491
581
  console.log(`- **L${i.line} [${i.severity}] ${i.title}**: ${i.fix}`);
492
582
  }
493
583
  }
584
+ } else if (fmt === 'sarif') {
585
+ console.log(JSON.stringify(buildSarif(report), null, 2));
494
586
  } else {
495
587
  console.log('\n' + '='.repeat(64));
496
588
  console.log(` PLUMBER INSPECTION REPORT: ${report.repo_name}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "plumber-linter",
3
- "version": "1.2.0",
4
- "description": "CI/CD pipeline linter that flags hardcoded secrets, leaked credentials, and dead code — with fixes in plain English.",
3
+ "version": "1.3.0",
4
+ "description": "CI/CD pipeline linter that flags hardcoded secrets, leaked credentials, and dead code — with fixes in plain English, plus SARIF output for GitHub code scanning.",
5
5
  "main": "bin/plumber.js",
6
6
  "bin": {
7
7
  "plumber": "bin/plumber.js",
@@ -22,7 +22,9 @@
22
22
  "cli",
23
23
  "docker",
24
24
  "supply-chain",
25
- "slack"
25
+ "slack",
26
+ "sarif",
27
+ "github-code-scanning"
26
28
  ],
27
29
  "author": "Paras Raju",
28
30
  "license": "MIT",