plumber-linter 1.3.0 → 1.4.1

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 (3) hide show
  1. package/README.md +46 -3
  2. package/bin/plumber.js +460 -7
  3. package/package.json +8 -3
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, plus SARIF output for GitHub code scanning.
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 and workflow YAML scanning for GitHub Actions.
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)
@@ -37,7 +37,7 @@ npx plumber-linter scan . --format md
37
37
  npx plumber-linter scan . --format json
38
38
  npx plumber-linter scan . --format sarif
39
39
 
40
- # View all 26 inspection rules
40
+ # View all 31 inspection rules
41
41
  npx plumber-linter rules
42
42
  ```
43
43
 
@@ -71,7 +71,7 @@ npx plumber-linter uninstall-hook
71
71
 
72
72
  ### SARIF output for GitHub code scanning
73
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.
74
+ `plumber scan . --format sarif` writes SARIF 2.1.0 JSON to stdout. The file contains one run for `plumber-linter` 1.4.1, 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
75
 
76
76
  ```bash
77
77
  npx plumber-linter scan . --format sarif > results.sarif
@@ -101,6 +101,43 @@ jobs:
101
101
  sarif_file: results.sarif
102
102
  ```
103
103
 
104
+ ### Workflow YAML scanning — scan .github/workflows/*.yml
105
+
106
+ Workflow YAML scanning checks GitHub Actions files under `.github/workflows` with the same `scan` command. Use it to scan GitHub Actions workflows for structural risks. A repository with no workflow files is unchanged: no new findings and no YAML errors.
107
+
108
+ ```bash
109
+ npx plumber-linter scan .
110
+ npx plumber-linter scan .github/workflows/review.yml
111
+ ```
112
+
113
+ - `sec/pull-request-target` — flags a `pull_request_target` workflow that checks out untrusted PR code or grants write permissions (`CRITICAL`).
114
+ - `sec/expression-injection` — flags `${{ github.event.* }}`, `${{ github.head_ref }}`, or another attacker-controlled context interpolated into a `run:` command (`CRITICAL`).
115
+ - `pipe/action-unpinned` — flags a `uses:` step that references a third-party action by branch or version tag instead of a full commit SHA (`MEDIUM`).
116
+ - `sec/job-permissions` — flags a job that pushes, releases, or deploys with no `permissions:` block, or with `contents: write` where a narrower scope would do (`HIGH`).
117
+ - `sec/secret-to-untrusted` — flags a secret in `env:` or an argument of a step that runs a third-party action (`HIGH`).
118
+
119
+ `.github/workflows/review.yml`:
120
+
121
+ ```yaml
122
+ name: review
123
+ on:
124
+ pull_request_target:
125
+ jobs:
126
+ build:
127
+ runs-on: ubuntu-latest
128
+ steps:
129
+ - uses: actions/checkout@v4
130
+ with:
131
+ ref: ${{ github.event.pull_request.head.sha }}
132
+ ```
133
+
134
+ ```text
135
+ [FILE] .github/workflows/review.yml
136
+ L10 [CRITICAL] Untrusted pull_request_target Checkout or Write Permission
137
+ Found: ref: ${{ github.event.pull_request.head.sha }}
138
+ Fix: Use pull_request, or check out the base ref read-only with no secrets.
139
+ ```
140
+
104
141
  ---
105
142
 
106
143
  ## What It Checks
@@ -185,6 +222,12 @@ Spots hallucinated library imports invented by LLMs or packages missing from pro
185
222
 
186
223
  ## Changelog
187
224
 
225
+ ## 1.4.1
226
+ `plumber scan` skips symlinks, including dangling links such as a `README.md` that points at a missing file, instead of crashing.
227
+
228
+ ## 1.4.0
229
+ Workflow YAML scanning (plumber scan on .github/workflows/*.yml) — 5 workflow rules (audit-gated, see Step 1).
230
+
188
231
  ## 1.3.0
189
232
  SARIF output (`--format sarif`) for GitHub code scanning.
190
233
 
package/bin/plumber.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /**
4
4
  * Plumber CLI & MCP Server (Node.js Thin Client)
5
5
  * Inspects repositories for leaked credentials, AI slop tells, broken pipes, and fragile joints.
6
- * Zero external dependencies.
6
+ * GitHub Actions workflow YAML is parsed with js-yaml.
7
7
  */
8
8
 
9
9
  const fs = require('fs');
@@ -11,6 +11,7 @@ const path = require('path');
11
11
  const https = require('https');
12
12
  const readline = require('readline');
13
13
  const { execFileSync } = require('child_process');
14
+ const yaml = require('js-yaml');
14
15
 
15
16
  const API_BASE = process.env.PLUMBER_API_URL || 'http://localhost:3100';
16
17
  const HOOK_MARKER = '# plumber-managed-hook';
@@ -70,12 +71,30 @@ const RULES = [
70
71
  { id: 'sec/curl-pipe-shell', cat: 'Leaks & Secrets', sev: 'CRITICAL', title: 'Remote Script Piped Directly to Shell (curl | bash)', fix: 'Download script first, verify its SHA256 checksum or signature, then execute it.' },
71
72
  { id: 'sec/permissions-write-all', cat: 'Leaks & Secrets', sev: 'HIGH', title: 'Overly Broad Workflow Write Permissions', fix: 'Use least-privilege permissions (e.g., permissions: { contents: read }).' },
72
73
  { id: 'leak/slack-webhook', cat: 'Leaks & Secrets', sev: 'CRITICAL', title: 'Hardcoded Slack or Tokenized Webhook URL', fix: 'Move webhook URL to CI/CD encrypted secrets (e.g., ${{ secrets.SLACK_WEBHOOK_URL }}).' },
73
- { id: 'pipe/npm-unpinned', cat: 'Pipes & Dependencies', sev: 'MEDIUM', title: 'Unpinned npm Install in CI Without Lockfile Enforcement', fix: 'Use npm ci to enforce lockfile versions or pass --save-exact when adding packages.' }
74
+ { id: 'pipe/npm-unpinned', cat: 'Pipes & Dependencies', sev: 'MEDIUM', title: 'Unpinned npm Install in CI Without Lockfile Enforcement', fix: 'Use npm ci to enforce lockfile versions or pass --save-exact when adding packages.' },
75
+ // v1.4.0 structural GitHub Actions checks. Same ids, severities, and fixes as the MCP engine.
76
+ { id: 'sec/pull-request-target', cat: 'Leaks & Secrets', sev: 'CRITICAL', title: 'Untrusted pull_request_target Checkout or Write Permission', fix: 'Use pull_request, or check out the base ref read-only with no secrets.' },
77
+ { id: 'sec/expression-injection', cat: 'Leaks & Secrets', sev: 'CRITICAL', title: 'Expression Injection in Workflow run Step', fix: 'Pass the value through an env: variable and reference that variable in the script.' },
78
+ { id: 'pipe/action-unpinned', cat: 'Pipes & Dependencies', sev: 'MEDIUM', title: 'Unpinned Third-Party Action', fix: 'Pin the action to a full commit SHA.' },
79
+ { id: 'sec/job-permissions', cat: 'Leaks & Secrets', sev: 'HIGH', title: 'Job Writes Without Least-Privilege Permissions', fix: 'Set least-privilege permissions on the job.' },
80
+ { id: 'sec/secret-to-untrusted', cat: 'Leaks & Secrets', sev: 'HIGH', title: 'Secret Passed to Untrusted Step', fix: 'Scope the secret to the trusted step that needs it.' }
74
81
  ];
75
82
 
76
83
  const SEV_WEIGHT = { CRITICAL: 4, HIGH: 3, MEDIUM: 2, LOW: 1, INFO: 0 };
77
84
  const SARIF_SCHEMA = 'https://json.schemastore.org/sarif-2.1.0.json';
78
85
  const INFORMATION_URI = 'https://github.com/parasraju/plumber';
86
+ const FULL_SHA = /^[0-9a-f]{40}$/i;
87
+ const FIRST_PARTY_OWNERS = new Set(['actions', 'github']);
88
+ const INJECTED_EXPR = /\$\{\{\s*(?:github\.event\.|github\.head_ref\b|inputs\.)/;
89
+ const SECRET_REF = /\$\{\{\s*secrets\.[A-Za-z0-9_]+\s*\}\}/;
90
+ const UNTRUSTED_CHECKOUT = /github\.event\.pull_request|github\.head_ref|refs\/pull\//;
91
+ const CONTENTS_WRITE_RUN = /\bgit\s+push\b|\bgh\s+release\b|\bgh\s+pr\s+merge\b/;
92
+ const DEPLOY_RUN = /\bnpm\s+publish\b|\bpnpm\s+publish\b|\byarn\s+npm\s+publish\b|\bdocker\s+push\b|\btwine\s+upload\b/;
93
+ const CONTENTS_ACTIONS = new Set([
94
+ 'softprops/action-gh-release',
95
+ 'peaceiris/actions-gh-pages',
96
+ 'ncipollo/release-action'
97
+ ]);
79
98
 
80
99
  // Main entry
81
100
  const args = process.argv.slice(2);
@@ -106,7 +125,7 @@ if (cmd === 'mcp') {
106
125
 
107
126
  function printHelp() {
108
127
  console.log(`
109
- Plumber — Code Leak, Clog, and AI Slop Inspector (v1.3.0)
128
+ Plumber — Code Leak, Clog, and AI Slop Inspector (v${readPackageVersion()})
110
129
 
111
130
  USAGE:
112
131
  npx plumber-linter scan [target] [options]
@@ -121,7 +140,7 @@ COMMANDS:
121
140
  install-hook Block git commits that contain secrets, .env files, or dead code
122
141
  uninstall-hook Remove the Plumber pre-commit hook
123
142
  clean [path] Remove unreachable dead code (dry run unless --write)
124
- rules Display catalogue of 26 inspection rules
143
+ rules Display catalogue of ${RULES.length} inspection rules
125
144
  mcp Run stdio Model Context Protocol (MCP) server for Claude / Cursor
126
145
 
127
146
  OPTIONS:
@@ -164,6 +183,17 @@ async function runScan(target, fmt, failOn) {
164
183
  renderReport(report, fmt, failOn);
165
184
  }
166
185
 
186
+ function readEntryStat(target) {
187
+ try {
188
+ return fs.lstatSync(target);
189
+ } catch (err) {
190
+ if (err && (err.code === 'ENOENT' || err.code === 'EACCES' || err.code === 'EPERM' || err.code === 'ELOOP' || err.code === 'ENOTDIR')) {
191
+ return null;
192
+ }
193
+ throw err;
194
+ }
195
+ }
196
+
167
197
  function scanLocalDirectory(dirPath) {
168
198
  const scannableExts = new Set(['.py', '.js', '.jsx', '.ts', '.tsx', '.html', '.htm', '.css', '.scss', '.env', '.yml', '.yaml', '.sh']);
169
199
  const skipDirs = new Set(['.git', 'node_modules', 'dist', 'build', '.next', '.nuxt', 'vendor', '.venv', 'venv', '__pycache__']);
@@ -174,7 +204,8 @@ function scanLocalDirectory(dirPath) {
174
204
  const fileReports = [];
175
205
 
176
206
  function walk(current) {
177
- const stat = fs.statSync(current);
207
+ const stat = readEntryStat(current);
208
+ if (!stat || stat.isSymbolicLink()) return;
178
209
  if (stat.isFile()) {
179
210
  const ext = path.extname(current).toLowerCase();
180
211
  const base = path.basename(current);
@@ -188,6 +219,8 @@ function scanLocalDirectory(dirPath) {
188
219
  totalLines += lines.length;
189
220
  const rel = (current === dirPath ? base : path.relative(dirPath, current)).replace(/\\/g, '/');
190
221
  const fileIssues = inspectFile(rel, content, lines, ext);
222
+ const workflowIssues = collectWorkflowIssues(current, rel, content, lines);
223
+ if (workflowIssues.length > 0) fileIssues.push(...workflowIssues);
191
224
  if (fileIssues.length > 0) {
192
225
  issues.push(...fileIssues);
193
226
  fileReports.push({ path: rel, issues: fileIssues });
@@ -418,6 +451,426 @@ function inspectFile(relPath, content, lines, ext) {
418
451
  return issues;
419
452
  }
420
453
 
454
+ function isGitHubWorkflowPath(filePath) {
455
+ return /(?:^|\/)\.github\/workflows\/[^/]+\.ya?ml$/i.test(String(filePath || '').replace(/\\/g, '/'));
456
+ }
457
+
458
+ function canonicalWorkflowPath(absPath, relPath) {
459
+ const rel = String(relPath || '').replace(/\\/g, '/');
460
+ if (isGitHubWorkflowPath(rel)) return rel;
461
+ const abs = String(absPath || '').replace(/\\/g, '/');
462
+ const marker = '.github/workflows/';
463
+ const idx = abs.toLowerCase().lastIndexOf(marker);
464
+ if (idx === -1) return rel;
465
+ const suffix = abs.slice(idx);
466
+ return isGitHubWorkflowPath(suffix) ? suffix : rel;
467
+ }
468
+
469
+ function collectWorkflowIssues(absPath, relPath, content, lines) {
470
+ const ext = path.extname(absPath).toLowerCase();
471
+ if (ext !== '.yml' && ext !== '.yaml') return [];
472
+ const workflowPath = canonicalWorkflowPath(absPath, relPath);
473
+ if (!isGitHubWorkflowPath(workflowPath)) return [];
474
+ try {
475
+ const doc = loadWorkflow(content, workflowPath);
476
+ if (!doc) return [];
477
+ return inspectWorkflow(doc, lines);
478
+ } catch (err) {
479
+ const detail = err && err.message ? err.message : String(err);
480
+ console.error(`[Error] Workflow scan failed for ${workflowPath}: ${detail}`);
481
+ return [];
482
+ }
483
+ }
484
+
485
+ function ruleById(id) {
486
+ for (let i = 0; i < RULES.length; i++) {
487
+ if (RULES[i].id === id) return RULES[i];
488
+ }
489
+ throw new Error('Unknown Plumber rule: ' + id);
490
+ }
491
+
492
+ function makeIssue(ruleId, line, evidence) {
493
+ const rule = ruleById(ruleId);
494
+ const text = evidence === undefined || evidence === null ? '' : String(evidence).trim();
495
+ return {
496
+ rule_id: rule.id,
497
+ title: rule.title,
498
+ severity: rule.sev,
499
+ line: line > 0 ? line : 1,
500
+ evidence: text.slice(0, 90),
501
+ fix: rule.fix
502
+ };
503
+ }
504
+
505
+ function loadWorkflow(content, workflowPath) {
506
+ let doc;
507
+ try {
508
+ // js-yaml 4 uses YAML 1.2, so the workflow key "on" stays a string.
509
+ doc = yaml.load(content, { schema: yaml.DEFAULT_SCHEMA });
510
+ } catch (err) {
511
+ const detail = err && err.message ? err.message : String(err);
512
+ console.error(`[Error] Failed to parse workflow YAML ${workflowPath}: ${detail}`);
513
+ return null;
514
+ }
515
+ if (!doc || typeof doc !== 'object' || Array.isArray(doc)) return null;
516
+ if (doc.on === undefined || doc.on === null) return null;
517
+ if (!doc.jobs || typeof doc.jobs !== 'object' || Array.isArray(doc.jobs)) return null;
518
+ return doc;
519
+ }
520
+
521
+ function inspectWorkflow(doc, lines) {
522
+ const found = [];
523
+ const seen = new Set();
524
+ function add(ruleId, line, evidence) {
525
+ const issue = makeIssue(ruleId, line, evidence);
526
+ const key = issue.rule_id + '\n' + issue.line + '\n' + issue.evidence;
527
+ if (seen.has(key)) return;
528
+ seen.add(key);
529
+ found.push(issue);
530
+ }
531
+ collectPullRequestTarget(doc, lines, add);
532
+ collectExpressionInjection(doc, lines, add);
533
+ collectUnpinnedActions(doc, lines, add);
534
+ collectJobPermissions(doc, lines, add);
535
+ collectSecrets(doc, lines, add);
536
+ return found;
537
+ }
538
+
539
+ function triggerNames(onValue) {
540
+ if (typeof onValue === 'string' || typeof onValue === 'number' || typeof onValue === 'boolean') {
541
+ return [String(onValue)];
542
+ }
543
+ if (Array.isArray(onValue)) {
544
+ const names = [];
545
+ for (let i = 0; i < onValue.length; i++) {
546
+ if (typeof onValue[i] === 'string') names.push(onValue[i]);
547
+ }
548
+ return names;
549
+ }
550
+ if (onValue && typeof onValue === 'object') return Object.keys(onValue);
551
+ return [];
552
+ }
553
+
554
+ function eachJob(doc, visit) {
555
+ const names = Object.keys(doc.jobs);
556
+ for (let i = 0; i < names.length; i++) {
557
+ const job = doc.jobs[names[i]];
558
+ if (!job || typeof job !== 'object' || Array.isArray(job)) continue;
559
+ visit(names[i], job);
560
+ }
561
+ }
562
+
563
+ function eachStep(job, visit) {
564
+ if (!Array.isArray(job.steps)) return;
565
+ for (let i = 0; i < job.steps.length; i++) {
566
+ const step = job.steps[i];
567
+ if (!step || typeof step !== 'object' || Array.isArray(step)) continue;
568
+ visit(step, i);
569
+ }
570
+ }
571
+
572
+ function scalarText(value) {
573
+ if (typeof value === 'string') return value;
574
+ if (typeof value === 'number' || typeof value === 'boolean') return String(value);
575
+ return '';
576
+ }
577
+
578
+ function parseActionRef(uses) {
579
+ if (typeof uses !== 'string') return null;
580
+ const spec = uses.trim();
581
+ if (!spec || spec.startsWith('./') || spec.startsWith('docker://')) return null;
582
+ const at = spec.lastIndexOf('@');
583
+ const name = (at === -1 ? spec : spec.slice(0, at)).trim();
584
+ const ref = at === -1 ? '' : spec.slice(at + 1).trim();
585
+ if (!name.includes('/')) return null;
586
+ const owner = name.split('/')[0];
587
+ if (!owner) return null;
588
+ return {
589
+ spec: spec,
590
+ name: name,
591
+ owner: owner,
592
+ ref: ref,
593
+ thirdParty: !FIRST_PARTY_OWNERS.has(owner),
594
+ pinned: FULL_SHA.test(ref)
595
+ };
596
+ }
597
+
598
+ function permissionsGrantWrite(perms) {
599
+ if (typeof perms === 'string') return perms.trim().toLowerCase() === 'write-all';
600
+ if (!perms || typeof perms !== 'object' || Array.isArray(perms)) return false;
601
+ const keys = Object.keys(perms);
602
+ for (let i = 0; i < keys.length; i++) {
603
+ if (String(perms[keys[i]]).trim().toLowerCase() === 'write') return true;
604
+ }
605
+ return false;
606
+ }
607
+
608
+ function jobEffectivePerms(doc, job) {
609
+ if (job && job.permissions !== undefined && job.permissions !== null) return job.permissions;
610
+ if (doc.permissions !== undefined && doc.permissions !== null) return doc.permissions;
611
+ return undefined;
612
+ }
613
+
614
+ function valueHasSecret(value, depth) {
615
+ if (depth > 8 || value === null || value === undefined) return false;
616
+ if (typeof value === 'string') return SECRET_REF.test(value);
617
+ if (typeof value !== 'object') return false;
618
+ if (Array.isArray(value)) {
619
+ for (let i = 0; i < value.length; i++) {
620
+ if (valueHasSecret(value[i], depth + 1)) return true;
621
+ }
622
+ return false;
623
+ }
624
+ const keys = Object.keys(value);
625
+ for (let i = 0; i < keys.length; i++) {
626
+ if (valueHasSecret(value[keys[i]], depth + 1)) return true;
627
+ }
628
+ return false;
629
+ }
630
+
631
+ function collectPullRequestTarget(doc, lines, add) {
632
+ if (triggerNames(doc.on).indexOf('pull_request_target') === -1) return;
633
+ let cursor = 0;
634
+ eachJob(doc, function (name, job) {
635
+ eachStep(job, function (step) {
636
+ if (!checkoutRefIsUntrusted(step)) return;
637
+ const ref = scalarText(step.with && step.with.ref);
638
+ const snippet = ref || scalarText(step.uses);
639
+ const line = lineContainingFrom(lines, snippet.slice(0, 80), cursor);
640
+ cursor = line;
641
+ add('sec/pull-request-target', line, lines[line - 1] || snippet);
642
+ });
643
+ if (permissionsGrantWrite(jobEffectivePerms(doc, job))) {
644
+ const line = lineOfAppliedPermissions(lines, name, jobEffectivePerms(doc, job));
645
+ add('sec/pull-request-target', line, lines[line - 1] || 'permissions');
646
+ }
647
+ });
648
+ }
649
+
650
+ function checkoutRefIsUntrusted(step) {
651
+ if (typeof step.uses !== 'string' || !/^actions\/checkout(?:@|\/|\s|$)/.test(step.uses.trim())) return false;
652
+ const withBlock = step.with;
653
+ if (!withBlock || typeof withBlock !== 'object' || Array.isArray(withBlock)) return false;
654
+ const ref = scalarText(withBlock.ref);
655
+ const repository = scalarText(withBlock.repository);
656
+ if (ref && UNTRUSTED_CHECKOUT.test(ref)) return true;
657
+ if (repository && /github\.event\.pull_request\.head/.test(repository)) return true;
658
+ return false;
659
+ }
660
+
661
+ function collectExpressionInjection(doc, lines, add) {
662
+ let cursor = 0;
663
+ eachJob(doc, function (name, job) {
664
+ eachStep(job, function (step) {
665
+ const run = scalarText(step.run);
666
+ if (!run) return;
667
+ const match = INJECTED_EXPR.exec(run);
668
+ if (!match) return;
669
+ const located = lineOfInjectedRun(lines, match[0], cursor);
670
+ cursor = located.next;
671
+ add('sec/expression-injection', located.line, lines[located.line - 1] || run);
672
+ });
673
+ });
674
+ }
675
+
676
+ function collectUnpinnedActions(doc, lines, add) {
677
+ let cursor = 0;
678
+ eachJob(doc, function (name, job) {
679
+ cursor = flagUnpinned(lines, job.uses, cursor, add);
680
+ eachStep(job, function (step) {
681
+ cursor = flagUnpinned(lines, step.uses, cursor, add);
682
+ });
683
+ });
684
+ }
685
+
686
+ function flagUnpinned(lines, uses, cursor, add) {
687
+ const action = parseActionRef(uses);
688
+ if (!action || !action.thirdParty || action.pinned) return cursor;
689
+ const line = lineOfUses(lines, action.spec, cursor);
690
+ add('pipe/action-unpinned', line, lines[line - 1] || action.spec);
691
+ return line;
692
+ }
693
+
694
+ function collectJobPermissions(doc, lines, add) {
695
+ eachJob(doc, function (name, job) {
696
+ const kinds = jobWriteKinds(job);
697
+ if (!kinds.contents && !kinds.deploy) return;
698
+ const hasJobPerms = job.permissions !== undefined && job.permissions !== null;
699
+ const hasWorkflowPerms = doc.permissions !== undefined && doc.permissions !== null;
700
+ const perms = hasJobPerms ? job.permissions : (hasWorkflowPerms ? doc.permissions : undefined);
701
+ const info = describePermissions(perms);
702
+ let reason = '';
703
+ if (!info) reason = 'missing';
704
+ else if (info.writeAll) reason = 'write-all';
705
+ else if (info.contentsWrite && kinds.deploy && !kinds.contents) reason = 'contents-write';
706
+ else return;
707
+ const line = lineForJobPermission(lines, name, reason);
708
+ add('sec/job-permissions', line, lines[line - 1] || name);
709
+ });
710
+ }
711
+
712
+ function jobWriteKinds(job) {
713
+ const kinds = { contents: false, deploy: false };
714
+ eachStep(job, function (step) {
715
+ const run = scalarText(step.run);
716
+ if (CONTENTS_WRITE_RUN.test(run)) kinds.contents = true;
717
+ if (DEPLOY_RUN.test(run)) kinds.deploy = true;
718
+ const action = parseActionRef(step.uses);
719
+ if (!action) return;
720
+ if (CONTENTS_ACTIONS.has(action.name)) kinds.contents = true;
721
+ if (action.name === 'actions/deploy-pages') kinds.deploy = true;
722
+ if (action.name === 'docker/build-push-action') {
723
+ const push = step.with && step.with.push;
724
+ if (push === true || String(push).toLowerCase() === 'true') kinds.deploy = true;
725
+ }
726
+ });
727
+ return kinds;
728
+ }
729
+
730
+ function describePermissions(perms) {
731
+ if (perms === undefined || perms === null) return null;
732
+ if (typeof perms === 'string') {
733
+ const value = perms.trim().toLowerCase();
734
+ return { writeAll: value === 'write-all', contentsWrite: value === 'write-all' };
735
+ }
736
+ if (typeof perms !== 'object' || Array.isArray(perms)) return null;
737
+ const contents = perms.contents === undefined || perms.contents === null ? '' : String(perms.contents).trim().toLowerCase();
738
+ return { writeAll: false, contentsWrite: contents === 'write' };
739
+ }
740
+
741
+ function collectSecrets(doc, lines, add) {
742
+ let cursor = 0;
743
+ eachJob(doc, function (name, job) {
744
+ const inherited = valueHasSecret(doc.env, 0) || valueHasSecret(job.env, 0);
745
+ const jobAction = parseActionRef(job.uses);
746
+ if (jobAction && jobAction.thirdParty && (job.secrets === 'inherit' || valueHasSecret(job.secrets, 0) || inherited)) {
747
+ const line = lineOfUses(lines, jobAction.spec, cursor);
748
+ cursor = line;
749
+ add('sec/secret-to-untrusted', line, lines[line - 1] || jobAction.spec);
750
+ }
751
+ eachStep(job, function (step) {
752
+ const action = parseActionRef(step.uses);
753
+ if (!action || !action.thirdParty) return;
754
+ const onStep = valueHasSecret(step.env, 0) || valueHasSecret(step.with, 0);
755
+ if (!onStep && !inherited) return;
756
+ const line = onStep
757
+ ? lineContainingFrom(lines, 'secrets.', cursor)
758
+ : lineOfUses(lines, action.spec, cursor);
759
+ cursor = line;
760
+ add('sec/secret-to-untrusted', line, lines[line - 1] || action.spec);
761
+ });
762
+ });
763
+ }
764
+
765
+ function lineContainingFrom(lines, snippet, start) {
766
+ const needle = String(snippet);
767
+ const from = start > 0 ? start : 0;
768
+ for (let i = from; i < lines.length; i++) {
769
+ if (lines[i].includes(needle)) return i + 1;
770
+ }
771
+ for (let i = 0; i < from; i++) {
772
+ if (lines[i].includes(needle)) return i + 1;
773
+ }
774
+ return 1;
775
+ }
776
+
777
+ function lineOfUses(lines, spec, cursor) {
778
+ const from = cursor > 0 ? cursor : 0;
779
+ for (let i = from; i < lines.length; i++) {
780
+ if (lines[i].includes(spec) && /uses\s*:/.test(lines[i])) return i + 1;
781
+ }
782
+ return lineContainingFrom(lines, spec, 0);
783
+ }
784
+
785
+ function lineOfInjectedRun(lines, snippet, cursor) {
786
+ const runKey = /^\s*(?:-\s+)?run\s*:/;
787
+ const start = cursor > 0 ? cursor : 0;
788
+ for (let i = start; i < lines.length; i++) {
789
+ if (!runKey.test(lines[i])) continue;
790
+ const indent = lines[i].search(/\S/);
791
+ if (lines[i].includes(snippet)) return { line: i + 1, next: i + 1 };
792
+ let found = 0;
793
+ let end = i + 1;
794
+ for (let j = i + 1; j < lines.length; j++) {
795
+ if (!lines[j].trim()) continue;
796
+ if (lines[j].search(/\S/) <= indent) break;
797
+ end = j + 1;
798
+ if (!found && lines[j].includes(snippet)) found = j + 1;
799
+ }
800
+ if (found) return { line: found, next: end };
801
+ if (/\*[A-Za-z0-9_-]+/.test(lines[i])) {
802
+ return { line: lineContainingFrom(lines, snippet, 0), next: i + 1 };
803
+ }
804
+ }
805
+ return { line: lineContainingFrom(lines, snippet, 0), next: lines.length };
806
+ }
807
+
808
+ function findJobLine(lines, jobName) {
809
+ const pattern = new RegExp('^ ' + escapeRegExp(jobName) + '\\s*:');
810
+ let seenJobs = false;
811
+ for (let i = 0; i < lines.length; i++) {
812
+ if (/^jobs\s*:/.test(lines[i])) {
813
+ seenJobs = true;
814
+ continue;
815
+ }
816
+ if (seenJobs && pattern.test(lines[i])) return i + 1;
817
+ }
818
+ return 1;
819
+ }
820
+
821
+ function nextJobBoundary(lines, jobLine) {
822
+ for (let i = jobLine; i < lines.length; i++) {
823
+ if (/^ [A-Za-z0-9_-]+\s*:/.test(lines[i])) return i;
824
+ }
825
+ return lines.length;
826
+ }
827
+
828
+ function findLineMatching(lines, pattern, start, end) {
829
+ const from = Math.max(0, start);
830
+ const to = Math.min(lines.length, end);
831
+ for (let i = from; i < to; i++) {
832
+ if (pattern.test(lines[i])) return i + 1;
833
+ }
834
+ return 0;
835
+ }
836
+
837
+ function lineOfAppliedPermissions(lines, jobName, perms) {
838
+ const jobAt = findJobLine(lines, jobName);
839
+ const regionEnd = nextJobBoundary(lines, jobAt);
840
+ if (typeof perms === 'string' && perms.trim().toLowerCase() === 'write-all') {
841
+ return findLineMatching(lines, /permissions\s*:\s*['"]?write-all['"]?/, jobAt - 1, regionEnd)
842
+ || findLineMatching(lines, /permissions\s*:\s*['"]?write-all['"]?/, 0, lines.length)
843
+ || jobAt;
844
+ }
845
+ return findLineMatching(lines, /^\s*.+:\s*['"]?write['"]?\s*(?:#.*)?$/, jobAt - 1, regionEnd)
846
+ || findLineMatching(lines, /^\s*permissions\s*:/, jobAt - 1, regionEnd)
847
+ || findLineMatching(lines, /^permissions\s*:/, 0, lines.length)
848
+ || jobAt;
849
+ }
850
+
851
+ function lineForJobPermission(lines, jobName, reason) {
852
+ const jobAt = findJobLine(lines, jobName);
853
+ const regionEnd = nextJobBoundary(lines, jobAt);
854
+ if (reason === 'write-all') {
855
+ return findLineMatching(lines, /permissions\s*:\s*['"]?write-all['"]?/, 0, lines.length) || jobAt;
856
+ }
857
+ if (reason === 'contents-write') {
858
+ return findLineMatching(lines, /contents\s*:\s*['"]?write['"]?/, jobAt - 1, regionEnd)
859
+ || findLineMatching(lines, /contents\s*:\s*['"]?write['"]?/, 0, lines.length)
860
+ || jobAt;
861
+ }
862
+ return findLineMatching(
863
+ lines,
864
+ /git\s+push|gh\s+release|gh\s+pr\s+merge|npm\s+publish|pnpm\s+publish|docker\s+push|twine\s+upload|action-gh-release|actions-gh-pages|release-action|deploy-pages|build-push-action/,
865
+ jobAt - 1,
866
+ regionEnd
867
+ ) || jobAt;
868
+ }
869
+
870
+ function escapeRegExp(value) {
871
+ return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
872
+ }
873
+
421
874
  function findDeadCode(content, ext) {
422
875
  if (!['.py', '.js', '.jsx', '.ts', '.tsx'].includes(ext)) return [];
423
876
  const lines = content.split('\n');
@@ -790,8 +1243,8 @@ function collectSourceFiles(target) {
790
1243
  const skipDirs = new Set(['.git', 'node_modules', 'dist', 'build', '.next', '.nuxt', 'vendor', '.venv', 'venv', '__pycache__']);
791
1244
 
792
1245
  function walk(current) {
793
- let stat;
794
- try { stat = fs.statSync(current); } catch (_) { return; }
1246
+ const stat = readEntryStat(current);
1247
+ if (!stat || stat.isSymbolicLink()) return;
795
1248
  if (stat.isFile()) { results.push(current); return; }
796
1249
  if (!stat.isDirectory()) return;
797
1250
  const base = path.basename(current);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "plumber-linter",
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.",
3
+ "version": "1.4.1",
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 and workflow YAML scanning for GitHub Actions.",
5
5
  "main": "bin/plumber.js",
6
6
  "bin": {
7
7
  "plumber": "bin/plumber.js",
@@ -24,7 +24,9 @@
24
24
  "supply-chain",
25
25
  "slack",
26
26
  "sarif",
27
- "github-code-scanning"
27
+ "github-code-scanning",
28
+ "yaml",
29
+ "workflow-scanning"
28
30
  ],
29
31
  "author": "Paras Raju",
30
32
  "license": "MIT",
@@ -39,6 +41,9 @@
39
41
  "engines": {
40
42
  "node": ">=18.0.0"
41
43
  },
44
+ "dependencies": {
45
+ "js-yaml": "^4.3.2"
46
+ },
42
47
  "files": [
43
48
  "bin",
44
49
  "README.md"