@patricio0312rev/skillset 0.1.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 (115) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +176 -0
  4. package/bin/cli.js +37 -0
  5. package/package.json +55 -0
  6. package/src/commands/init.js +301 -0
  7. package/src/index.js +168 -0
  8. package/src/lib/config.js +200 -0
  9. package/src/lib/generator.js +166 -0
  10. package/src/utils/display.js +95 -0
  11. package/src/utils/readme.js +196 -0
  12. package/src/utils/tool-specific.js +233 -0
  13. package/templates/ai-engineering/agent-orchestration-planner/ SKILL.md +266 -0
  14. package/templates/ai-engineering/cost-latency-optimizer/ SKILL.md +270 -0
  15. package/templates/ai-engineering/doc-to-vector-dataset-generator/ SKILL.md +239 -0
  16. package/templates/ai-engineering/evaluation-harness/ SKILL.md +219 -0
  17. package/templates/ai-engineering/guardrails-safety-filter-builder/ SKILL.md +226 -0
  18. package/templates/ai-engineering/llm-debugger/ SKILL.md +283 -0
  19. package/templates/ai-engineering/prompt-regression-tester/ SKILL.md +216 -0
  20. package/templates/ai-engineering/prompt-template-builder/ SKILL.md +393 -0
  21. package/templates/ai-engineering/rag-pipeline-builder/ SKILL.md +244 -0
  22. package/templates/ai-engineering/tool-function-schema-designer/ SKILL.md +219 -0
  23. package/templates/architecture/adr-writer/ SKILL.md +250 -0
  24. package/templates/architecture/api-versioning-deprecation-planner/ SKILL.md +331 -0
  25. package/templates/architecture/domain-model-boundaries-mapper/ SKILL.md +300 -0
  26. package/templates/architecture/migration-planner/ SKILL.md +376 -0
  27. package/templates/architecture/performance-budget-setter/ SKILL.md +318 -0
  28. package/templates/architecture/reliability-strategy-builder/ SKILL.md +286 -0
  29. package/templates/architecture/rfc-generator/ SKILL.md +362 -0
  30. package/templates/architecture/scalability-playbook/ SKILL.md +279 -0
  31. package/templates/architecture/system-design-generator/ SKILL.md +339 -0
  32. package/templates/architecture/tech-debt-prioritizer/ SKILL.md +329 -0
  33. package/templates/backend/api-contract-normalizer/ SKILL.md +487 -0
  34. package/templates/backend/api-endpoint-generator/ SKILL.md +415 -0
  35. package/templates/backend/auth-module-builder/ SKILL.md +99 -0
  36. package/templates/backend/background-jobs-designer/ SKILL.md +166 -0
  37. package/templates/backend/caching-strategist/ SKILL.md +190 -0
  38. package/templates/backend/error-handling-standardizer/ SKILL.md +174 -0
  39. package/templates/backend/rate-limiting-abuse-protection/ SKILL.md +147 -0
  40. package/templates/backend/rbac-permissions-builder/ SKILL.md +158 -0
  41. package/templates/backend/service-layer-extractor/ SKILL.md +269 -0
  42. package/templates/backend/webhook-receiver-hardener/ SKILL.md +211 -0
  43. package/templates/ci-cd/artifact-sbom-publisher/ SKILL.md +236 -0
  44. package/templates/ci-cd/caching-strategy-optimizer/ SKILL.md +195 -0
  45. package/templates/ci-cd/deployment-checklist-generator/ SKILL.md +381 -0
  46. package/templates/ci-cd/github-actions-pipeline-creator/ SKILL.md +348 -0
  47. package/templates/ci-cd/monorepo-ci-optimizer/ SKILL.md +298 -0
  48. package/templates/ci-cd/preview-environments-builder/ SKILL.md +187 -0
  49. package/templates/ci-cd/quality-gates-enforcer/ SKILL.md +342 -0
  50. package/templates/ci-cd/release-automation-builder/ SKILL.md +281 -0
  51. package/templates/ci-cd/rollback-workflow-builder/ SKILL.md +372 -0
  52. package/templates/ci-cd/secrets-env-manager/ SKILL.md +242 -0
  53. package/templates/db-management/backup-restore-runbook-generator/ SKILL.md +505 -0
  54. package/templates/db-management/data-integrity-auditor/ SKILL.md +505 -0
  55. package/templates/db-management/data-retention-archiving-planner/ SKILL.md +430 -0
  56. package/templates/db-management/data-seeding-fixtures-builder/ SKILL.md +375 -0
  57. package/templates/db-management/db-performance-watchlist/ SKILL.md +425 -0
  58. package/templates/db-management/etl-sync-job-builder/ SKILL.md +457 -0
  59. package/templates/db-management/multi-tenant-safety-checker/ SKILL.md +398 -0
  60. package/templates/db-management/prisma-migration-assistant/ SKILL.md +379 -0
  61. package/templates/db-management/schema-consistency-checker/ SKILL.md +440 -0
  62. package/templates/db-management/sql-query-optimizer/ SKILL.md +324 -0
  63. package/templates/foundation/changelog-writer/ SKILL.md +431 -0
  64. package/templates/foundation/code-formatter-installer/ SKILL.md +320 -0
  65. package/templates/foundation/codebase-summarizer/ SKILL.md +360 -0
  66. package/templates/foundation/dependency-doctor/ SKILL.md +163 -0
  67. package/templates/foundation/dev-environment-bootstrapper/ SKILL.md +259 -0
  68. package/templates/foundation/dev-onboarding-builder/ SKILL.md +556 -0
  69. package/templates/foundation/docs-starter-kit/ SKILL.md +574 -0
  70. package/templates/foundation/explaining-code/SKILL.md +13 -0
  71. package/templates/foundation/git-hygiene-enforcer/ SKILL.md +455 -0
  72. package/templates/foundation/project-scaffolder/ SKILL.md +65 -0
  73. package/templates/foundation/project-scaffolder/references/templates.md +126 -0
  74. package/templates/foundation/repo-structure-linter/ SKILL.md +0 -0
  75. package/templates/foundation/repo-structure-linter/references/conventions.md +98 -0
  76. package/templates/frontend/animation-micro-interaction-pack/ SKILL.md +41 -0
  77. package/templates/frontend/component-scaffold-generator/ SKILL.md +562 -0
  78. package/templates/frontend/design-to-component-translator/ SKILL.md +547 -0
  79. package/templates/frontend/form-wizard-builder/ SKILL.md +553 -0
  80. package/templates/frontend/frontend-refactor-planner/ SKILL.md +37 -0
  81. package/templates/frontend/i18n-frontend-implementer/ SKILL.md +44 -0
  82. package/templates/frontend/modal-drawer-system/ SKILL.md +377 -0
  83. package/templates/frontend/page-layout-builder/ SKILL.md +630 -0
  84. package/templates/frontend/state-ux-flow-builder/ SKILL.md +23 -0
  85. package/templates/frontend/table-builder/ SKILL.md +350 -0
  86. package/templates/performance/alerting-dashboard-builder/ SKILL.md +162 -0
  87. package/templates/performance/backend-latency-profiler-helper/ SKILL.md +108 -0
  88. package/templates/performance/caching-cdn-strategy-planner/ SKILL.md +150 -0
  89. package/templates/performance/capacity-planning-helper/ SKILL.md +242 -0
  90. package/templates/performance/core-web-vitals-tuner/ SKILL.md +126 -0
  91. package/templates/performance/incident-runbook-generator/ SKILL.md +162 -0
  92. package/templates/performance/load-test-scenario-builder/ SKILL.md +256 -0
  93. package/templates/performance/observability-setup/ SKILL.md +232 -0
  94. package/templates/performance/postmortem-writer/ SKILL.md +203 -0
  95. package/templates/performance/structured-logging-standardizer/ SKILL.md +122 -0
  96. package/templates/security/auth-security-reviewer/ SKILL.md +428 -0
  97. package/templates/security/dependency-vulnerability-triage/ SKILL.md +495 -0
  98. package/templates/security/input-validation-sanitization-auditor/ SKILL.md +76 -0
  99. package/templates/security/pii-redaction-logging-policy-builder/ SKILL.md +65 -0
  100. package/templates/security/rbac-policy-tester/ SKILL.md +80 -0
  101. package/templates/security/secrets-scanner/ SKILL.md +462 -0
  102. package/templates/security/secure-headers-csp-builder/ SKILL.md +404 -0
  103. package/templates/security/security-incident-playbook-generator/ SKILL.md +76 -0
  104. package/templates/security/security-pr-checklist-skill/ SKILL.md +62 -0
  105. package/templates/security/threat-model-generator/ SKILL.md +394 -0
  106. package/templates/testing/contract-testing-builder/ SKILL.md +492 -0
  107. package/templates/testing/coverage-strategist/ SKILL.md +436 -0
  108. package/templates/testing/e2e-test-builder/ SKILL.md +382 -0
  109. package/templates/testing/flaky-test-detective/ SKILL.md +416 -0
  110. package/templates/testing/integration-test-builder/ SKILL.md +525 -0
  111. package/templates/testing/mocking-assistant/ SKILL.md +383 -0
  112. package/templates/testing/snapshot-test-refactorer/ SKILL.md +375 -0
  113. package/templates/testing/test-data-factory-builder/ SKILL.md +449 -0
  114. package/templates/testing/test-reporting-triage-skill/ SKILL.md +469 -0
  115. package/templates/testing/unit-test-generator/ SKILL.md +548 -0
@@ -0,0 +1,495 @@
1
+ ---
2
+ name: dependency-vulnerability-triage
3
+ description: Turns npm audit/Snyk results into prioritized patch plans with severity assessment, safe upgrade paths, breaking change analysis, and rollback strategies. Use for "dependency security", "vulnerability patching", "npm audit", or "security updates".
4
+ ---
5
+
6
+ # Dependency Vulnerability Triage
7
+
8
+ Convert vulnerability reports into actionable patch plans.
9
+
10
+ ## Vulnerability Severity Matrix
11
+
12
+ ```typescript
13
+ // severity-matrix.ts
14
+ export interface Vulnerability {
15
+ id: string;
16
+ package: string;
17
+ currentVersion: string;
18
+ patchedVersion: string;
19
+ severity: "critical" | "high" | "medium" | "low";
20
+ cvss: number;
21
+ cwe: string[];
22
+ exploitability: "high" | "medium" | "low";
23
+ impact: string;
24
+ path: string[];
25
+ }
26
+
27
+ export interface PatchPriority {
28
+ vulnerability: Vulnerability;
29
+ priority: 1 | 2 | 3 | 4;
30
+ reasoning: string;
31
+ patchWindow: "24h" | "1week" | "1month" | "next-release";
32
+ breakingChange: boolean;
33
+ testingRequired: "minimal" | "moderate" | "extensive";
34
+ }
35
+
36
+ export function calculatePriority(vuln: Vulnerability): PatchPriority {
37
+ let priority: 1 | 2 | 3 | 4 = 4;
38
+ let patchWindow: "24h" | "1week" | "1month" | "next-release" = "next-release";
39
+ let testingRequired: "minimal" | "moderate" | "extensive" = "minimal";
40
+
41
+ // P1: Critical + High Exploitability + Production
42
+ if (
43
+ vuln.severity === "critical" &&
44
+ vuln.exploitability === "high" &&
45
+ isProductionDependency(vuln.package)
46
+ ) {
47
+ priority = 1;
48
+ patchWindow = "24h";
49
+ testingRequired = "moderate";
50
+ }
51
+ // P2: High + Medium/High Exploitability
52
+ else if (
53
+ vuln.severity === "high" &&
54
+ ["high", "medium"].includes(vuln.exploitability)
55
+ ) {
56
+ priority = 2;
57
+ patchWindow = "1week";
58
+ testingRequired = "moderate";
59
+ }
60
+ // P3: Medium or Low Exploitability High
61
+ else if (
62
+ vuln.severity === "medium" ||
63
+ (vuln.severity === "high" && vuln.exploitability === "low")
64
+ ) {
65
+ priority = 3;
66
+ patchWindow = "1month";
67
+ testingRequired = "minimal";
68
+ }
69
+
70
+ return {
71
+ vulnerability: vuln,
72
+ priority,
73
+ reasoning: `${vuln.severity} severity, ${vuln.exploitability} exploitability`,
74
+ patchWindow,
75
+ breakingChange: isBreakingChange(vuln.currentVersion, vuln.patchedVersion),
76
+ testingRequired,
77
+ };
78
+ }
79
+ ```
80
+
81
+ ## Audit Report Parser
82
+
83
+ ```typescript
84
+ // scripts/parse-audit.ts
85
+ import { execSync } from "child_process";
86
+
87
+ interface NpmAuditResult {
88
+ vulnerabilities: Record<string, any>;
89
+ metadata: {
90
+ vulnerabilities: {
91
+ critical: number;
92
+ high: number;
93
+ moderate: number;
94
+ low: number;
95
+ };
96
+ };
97
+ }
98
+
99
+ function parseNpmAudit(): Vulnerability[] {
100
+ const auditOutput = execSync("npm audit --json", { encoding: "utf-8" });
101
+ const audit: NpmAuditResult = JSON.parse(auditOutput);
102
+
103
+ const vulnerabilities: Vulnerability[] = [];
104
+
105
+ Object.entries(audit.vulnerabilities).forEach(([pkg, data]) => {
106
+ vulnerabilities.push({
107
+ id: data.via[0]?.url || `vuln-${pkg}`,
108
+ package: pkg,
109
+ currentVersion: data.range,
110
+ patchedVersion: data.fixAvailable?.version || "N/A",
111
+ severity: data.severity,
112
+ cvss: data.via[0]?.cvss?.score || 0,
113
+ cwe: data.via[0]?.cwe || [],
114
+ exploitability: determineExploitability(data),
115
+ impact: data.via[0]?.title || "Unknown",
116
+ path: data.via.map((v: any) => v.name),
117
+ });
118
+ });
119
+
120
+ return vulnerabilities;
121
+ }
122
+
123
+ function determineExploitability(data: any): "high" | "medium" | "low" {
124
+ // Check if actively exploited
125
+ if (
126
+ data.via[0]?.findings?.some((f: any) => f.exploit === "proof-of-concept")
127
+ ) {
128
+ return "high";
129
+ }
130
+
131
+ // Check CVSS exploitability subscore
132
+ const exploitScore = data.via[0]?.cvss?.exploitabilityScore;
133
+ if (exploitScore > 3.5) return "high";
134
+ if (exploitScore > 2.0) return "medium";
135
+ return "low";
136
+ }
137
+ ```
138
+
139
+ ## Patch Plan Generator
140
+
141
+ ```typescript
142
+ // scripts/generate-patch-plan.ts
143
+ interface PatchPlan {
144
+ immediate: PatchPriority[]; // P1 - 24h
145
+ shortTerm: PatchPriority[]; // P2 - 1 week
146
+ mediumTerm: PatchPriority[]; // P3 - 1 month
147
+ longTerm: PatchPriority[]; // P4 - next release
148
+ breakingChanges: PatchPriority[];
149
+ safeUpgrades: PatchPriority[];
150
+ }
151
+
152
+ function generatePatchPlan(vulnerabilities: Vulnerability[]): PatchPlan {
153
+ const prioritized = vulnerabilities.map(calculatePriority);
154
+
155
+ return {
156
+ immediate: prioritized.filter((p) => p.priority === 1),
157
+ shortTerm: prioritized.filter((p) => p.priority === 2),
158
+ mediumTerm: prioritized.filter((p) => p.priority === 3),
159
+ longTerm: prioritized.filter((p) => p.priority === 4),
160
+ breakingChanges: prioritized.filter((p) => p.breakingChange),
161
+ safeUpgrades: prioritized.filter((p) => !p.breakingChange),
162
+ };
163
+ }
164
+
165
+ function printPatchPlan(plan: PatchPlan) {
166
+ console.log("# Security Patch Plan\n");
167
+
168
+ console.log("## 🚨 Immediate (24 hours)\n");
169
+ plan.immediate.forEach((p) => {
170
+ console.log(
171
+ `- **${p.vulnerability.package}** ${p.vulnerability.currentVersion} → ${p.vulnerability.patchedVersion}`
172
+ );
173
+ console.log(` ${p.vulnerability.impact}`);
174
+ console.log(` Breaking: ${p.breakingChange ? "YES ⚠️" : "No"}`);
175
+ });
176
+
177
+ console.log("\n## ⚡ Short-term (1 week)\n");
178
+ plan.shortTerm.forEach((p) => {
179
+ console.log(
180
+ `- **${p.vulnerability.package}** ${p.vulnerability.currentVersion} → ${p.vulnerability.patchedVersion}`
181
+ );
182
+ });
183
+
184
+ console.log("\n## 📅 Medium-term (1 month)\n");
185
+ plan.mediumTerm.forEach((p) => {
186
+ console.log(
187
+ `- ${p.vulnerability.package} ${p.vulnerability.currentVersion} → ${p.vulnerability.patchedVersion}`
188
+ );
189
+ });
190
+
191
+ console.log("\n## ⚠️ Breaking Changes\n");
192
+ plan.breakingChanges.forEach((p) => {
193
+ console.log(`- ${p.vulnerability.package}: Review migration guide`);
194
+ });
195
+ }
196
+ ```
197
+
198
+ ## Safe Upgrade Order
199
+
200
+ ```typescript
201
+ // Dependency graph-based upgrade order
202
+ interface DependencyGraph {
203
+ [pkg: string]: string[];
204
+ }
205
+
206
+ function determineSafeUpgradeOrder(
207
+ patches: PatchPriority[]
208
+ ): PatchPriority[][] {
209
+ const graph = buildDependencyGraph();
210
+ const ordered: PatchPriority[][] = [];
211
+
212
+ // Level 0: No dependencies on other patches
213
+ const level0 = patches.filter(
214
+ (p) => !hasUpgradeDependencies(p.vulnerability.package, patches, graph)
215
+ );
216
+ ordered.push(level0);
217
+
218
+ // Level 1+: Depends on previous levels
219
+ let remaining = patches.filter((p) => !level0.includes(p));
220
+ let level = 1;
221
+
222
+ while (remaining.length > 0 && level < 10) {
223
+ const currentLevel = remaining.filter((p) =>
224
+ canUpgradeNow(p.vulnerability.package, ordered.flat(), graph)
225
+ );
226
+
227
+ if (currentLevel.length === 0) break; // Circular dependency
228
+
229
+ ordered.push(currentLevel);
230
+ remaining = remaining.filter((p) => !currentLevel.includes(p));
231
+ level++;
232
+ }
233
+
234
+ return ordered;
235
+ }
236
+
237
+ // Example output:
238
+ // Level 0: [lodash, axios] - No dependencies
239
+ // Level 1: [express] - Depends on lodash
240
+ // Level 2: [next] - Depends on express
241
+ ```
242
+
243
+ ## Risk Assessment
244
+
245
+ ```typescript
246
+ interface RiskAssessment {
247
+ package: string;
248
+ riskFactors: string[];
249
+ riskScore: number; // 1-10
250
+ mitigations: string[];
251
+ }
252
+
253
+ function assessUpgradeRisk(patch: PatchPriority): RiskAssessment {
254
+ const risks: string[] = [];
255
+ let score = 0;
256
+
257
+ // Check for breaking changes
258
+ if (patch.breakingChange) {
259
+ risks.push("Breaking changes detected");
260
+ score += 4;
261
+ }
262
+
263
+ // Check for major version bump
264
+ if (
265
+ isMajorVersionBump(
266
+ patch.vulnerability.currentVersion,
267
+ patch.vulnerability.patchedVersion
268
+ )
269
+ ) {
270
+ risks.push("Major version upgrade");
271
+ score += 3;
272
+ }
273
+
274
+ // Check usage patterns
275
+ const usage = analyzePackageUsage(patch.vulnerability.package);
276
+ if (usage.importCount > 50) {
277
+ risks.push("Heavily used in codebase");
278
+ score += 2;
279
+ }
280
+
281
+ // Check test coverage
282
+ if (usage.testCoverage < 0.7) {
283
+ risks.push("Low test coverage");
284
+ score += 2;
285
+ }
286
+
287
+ return {
288
+ package: patch.vulnerability.package,
289
+ riskFactors: risks,
290
+ riskScore: Math.min(score, 10),
291
+ mitigations: generateMitigations(risks),
292
+ };
293
+ }
294
+
295
+ function generateMitigations(risks: string[]): string[] {
296
+ const mitigations: string[] = [];
297
+
298
+ if (risks.includes("Breaking changes detected")) {
299
+ mitigations.push("Read CHANGELOG and migration guide");
300
+ mitigations.push("Test on feature branch first");
301
+ mitigations.push("Deploy to staging before production");
302
+ }
303
+
304
+ if (risks.includes("Heavily used in codebase")) {
305
+ mitigations.push("Run full test suite");
306
+ mitigations.push("Perform manual smoke tests");
307
+ mitigations.push("Monitor error rates after deploy");
308
+ }
309
+
310
+ if (risks.includes("Low test coverage")) {
311
+ mitigations.push("Add tests for critical paths");
312
+ mitigations.push("Extend monitoring");
313
+ }
314
+
315
+ return mitigations;
316
+ }
317
+ ```
318
+
319
+ ## Automated Patch Script
320
+
321
+ ```bash
322
+ #!/bin/bash
323
+ # scripts/apply-patches.sh
324
+
325
+ set -e
326
+
327
+ PRIORITY=$1 # immediate, short-term, medium-term
328
+
329
+ if [ -z "$PRIORITY" ]; then
330
+ echo "Usage: ./apply-patches.sh [immediate|short-term|medium-term]"
331
+ exit 1
332
+ fi
333
+
334
+ echo "🔧 Applying $PRIORITY patches..."
335
+
336
+ # Generate patch plan
337
+ npm audit --json > audit-report.json
338
+ node scripts/generate-patch-plan.js --priority=$PRIORITY > patch-plan.json
339
+
340
+ # Apply patches
341
+ while IFS= read -r package; do
342
+ echo "Updating $package..."
343
+
344
+ # Try to apply fix
345
+ npm audit fix --package-lock-only --package=$package
346
+
347
+ # Run tests
348
+ if npm test; then
349
+ echo "✅ Tests passed for $package"
350
+ git add package.json package-lock.json
351
+ git commit -m "security: patch $package vulnerability"
352
+ else
353
+ echo "❌ Tests failed for $package - reverting"
354
+ git checkout package.json package-lock.json
355
+ fi
356
+ done < <(jq -r '.packages[]' patch-plan.json)
357
+
358
+ echo "✅ Patches applied"
359
+ ```
360
+
361
+ ## CI Vulnerability Gating
362
+
363
+ ```yaml
364
+ # .github/workflows/security-audit.yml
365
+ name: Security Audit
366
+
367
+ on:
368
+ pull_request:
369
+ schedule:
370
+ - cron: "0 0 * * *" # Daily
371
+
372
+ jobs:
373
+ audit:
374
+ runs-on: ubuntu-latest
375
+ steps:
376
+ - uses: actions/checkout@v4
377
+
378
+ - uses: actions/setup-node@v4
379
+ with:
380
+ node-version: "20"
381
+
382
+ - name: Install dependencies
383
+ run: npm ci
384
+
385
+ - name: Run npm audit
386
+ run: npm audit --audit-level=moderate
387
+ continue-on-error: true
388
+
389
+ - name: Run Snyk test
390
+ uses: snyk/actions/node@master
391
+ env:
392
+ SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
393
+ with:
394
+ args: --severity-threshold=high
395
+
396
+ - name: Generate patch plan
397
+ if: failure()
398
+ run: npm run generate-patch-plan
399
+
400
+ - name: Comment PR
401
+ if: failure() && github.event_name == 'pull_request'
402
+ uses: actions/github-script@v7
403
+ with:
404
+ script: |
405
+ const fs = require('fs');
406
+ const plan = fs.readFileSync('patch-plan.md', 'utf8');
407
+ github.rest.issues.createComment({
408
+ owner: context.repo.owner,
409
+ repo: context.repo.repo,
410
+ issue_number: context.issue.number,
411
+ body: plan
412
+ });
413
+ ```
414
+
415
+ ## Patch Rollback Strategy
416
+
417
+ ````markdown
418
+ ## Vulnerability Patch Rollback Plan
419
+
420
+ ### Before Patching
421
+
422
+ 1. **Create rollback tag**
423
+ ```bash
424
+ git tag -a pre-security-patch-$(date +%Y%m%d) -m "Pre-patch checkpoint"
425
+ ```
426
+ ````
427
+
428
+ 2. **Document current versions**
429
+
430
+ ```bash
431
+ npm list --depth=0 > versions-before.txt
432
+ ```
433
+
434
+ 3. **Run baseline tests**
435
+ ```bash
436
+ npm test > test-results-before.txt
437
+ ```
438
+
439
+ ### Rollback Steps
440
+
441
+ If issues detected after patching:
442
+
443
+ 1. **Immediate revert**
444
+
445
+ ```bash
446
+ git revert HEAD
447
+ git push origin main
448
+ ```
449
+
450
+ 2. **Redeploy previous version**
451
+
452
+ ```bash
453
+ git checkout pre-security-patch-$(date +%Y%m%d)
454
+ npm ci
455
+ npm run build
456
+ npm run deploy
457
+ ```
458
+
459
+ 3. **Verify rollback**
460
+
461
+ ```bash
462
+ npm test
463
+ npm run smoke-tests
464
+ ```
465
+
466
+ 4. **Incident report**
467
+ - Document what failed
468
+ - Update patch plan with new risk factors
469
+ - Schedule retry with additional testing
470
+
471
+ ```
472
+
473
+ ## Best Practices
474
+
475
+ 1. **Triage weekly**: Review new vulnerabilities
476
+ 2. **Prioritize by impact**: Not just severity score
477
+ 3. **Test before merging**: Automated + manual testing
478
+ 4. **Stage deployments**: Dev → Staging → Production
479
+ 5. **Monitor after patch**: Watch error rates
480
+ 6. **Document breaking changes**: Migration guides
481
+ 7. **Keep dependencies updated**: Reduce vulnerability surface
482
+
483
+ ## Output Checklist
484
+
485
+ - [ ] Severity matrix defined
486
+ - [ ] Audit parser implemented
487
+ - [ ] Patch plan generated
488
+ - [ ] Safe upgrade order determined
489
+ - [ ] Risk assessment completed
490
+ - [ ] Breaking changes identified
491
+ - [ ] Automated patch script
492
+ - [ ] CI vulnerability gating
493
+ - [ ] Rollback strategy documented
494
+ - [ ] Team notified of critical patches
495
+ ```
@@ -0,0 +1,76 @@
1
+ ---
2
+ name: input-validation-sanitization-auditor
3
+ description: Identifies and fixes XSS, SQL injection, and command injection vulnerabilities with validation schemas, sanitization libraries, and safe coding patterns. Use for "input validation", "XSS prevention", "SQL injection", or "sanitization".
4
+ ---
5
+
6
+ # Input Validation & Sanitization Auditor
7
+
8
+ Prevent injection attacks through proper input handling.
9
+
10
+ ## XSS Prevention
11
+
12
+ ```typescript
13
+ // ❌ DANGEROUS: Direct HTML injection
14
+ app.get("/search", (req, res) => {
15
+ res.send(`<h1>Results for: ${req.query.q}</h1>`); // XSS!
16
+ });
17
+
18
+ // ✅ SAFE: Properly escaped
19
+ import { escape } from "html-escaper";
20
+
21
+ app.get("/search", (req, res) => {
22
+ res.send(`<h1>Results for: ${escape(req.query.q)}</h1>`);
23
+ });
24
+
25
+ // ✅ BETTER: Template engine with auto-escaping
26
+ res.render("search", { query: req.query.q }); // EJS/Pug escape by default
27
+ ```
28
+
29
+ ## SQL Injection Prevention
30
+
31
+ ```typescript
32
+ // ❌ DANGEROUS: String concatenation
33
+ const userId = req.params.id;
34
+ const query = `SELECT * FROM users WHERE id = '${userId}'`; // SQL Injection!
35
+ db.query(query);
36
+
37
+ // ✅ SAFE: Parameterized queries
38
+ db.query("SELECT * FROM users WHERE id = $1", [userId]);
39
+
40
+ // ✅ BEST: ORM (Prisma)
41
+ await prisma.user.findUnique({ where: { id: userId } });
42
+ ```
43
+
44
+ ## Input Validation Schema
45
+
46
+ ```typescript
47
+ import { z } from "zod";
48
+
49
+ const userSchema = z.object({
50
+ email: z.string().email().max(255),
51
+ password: z.string().min(12).max(128),
52
+ age: z.number().int().min(13).max(120),
53
+ website: z.string().url().optional(),
54
+ });
55
+
56
+ app.post("/register", async (req, res) => {
57
+ try {
58
+ const validated = userSchema.parse(req.body);
59
+ await createUser(validated);
60
+ res.json({ success: true });
61
+ } catch (error) {
62
+ res.status(400).json({ error: error.errors });
63
+ }
64
+ });
65
+ ```
66
+
67
+ ## Output Checklist
68
+
69
+ - [ ] XSS prevention (escaping, CSP)
70
+ - [ ] SQL injection prevention (parameterized queries)
71
+ - [ ] Command injection prevention
72
+ - [ ] Input validation schemas
73
+ - [ ] Output encoding
74
+ - [ ] Sanitization libraries
75
+ - [ ] Security tests
76
+ ENDFILE
@@ -0,0 +1,65 @@
1
+ ---
2
+ name: pii-redaction-logging-policy-builder
3
+ description: Prevents logging sensitive user data with redaction rules, logging policies, and safe log formatting. Use for "PII redaction", "log privacy", "GDPR logging", or "data privacy".
4
+ ---
5
+
6
+ # PII Redaction & Logging Policy Builder
7
+
8
+ Protect user privacy in application logs.
9
+
10
+ ## PII Redaction
11
+
12
+ ```typescript
13
+ const PII_PATTERNS = {
14
+ email: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g,
15
+ ssn: /\b\d{3}-\d{2}-\d{4}\b/g,
16
+ phone: /\b\d{3}[-.]?\d{3}[-.]?\d{4}\b/g,
17
+ creditCard: /\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b/g,
18
+ };
19
+
20
+ function redactPII(message: string): string {
21
+ let redacted = message;
22
+ Object.entries(PII_PATTERNS).forEach(([type, pattern]) => {
23
+ redacted = redacted.replace(pattern, `[REDACTED_${type.toUpperCase()}]`);
24
+ });
25
+ return redacted;
26
+ }
27
+
28
+ // Safe logging
29
+ logger.info(redactPII(\`User registered: \${email}\`));
30
+ // Output: "User registered: [REDACTED_EMAIL]"
31
+ ```
32
+
33
+ ## Logging Policy
34
+
35
+ ```markdown
36
+ # Logging Policy
37
+
38
+ ## ✅ DO Log
39
+
40
+ - Request IDs
41
+ - User IDs (hashed)
42
+ - HTTP status codes
43
+ - Response times
44
+ - Error types
45
+ - Feature flags
46
+
47
+ ## ❌ DON'T Log
48
+
49
+ - Passwords
50
+ - Credit card numbers
51
+ - SSNs
52
+ - API keys
53
+ - Full emails (hash first)
54
+ - Full names
55
+ - Addresses
56
+ ```
57
+
58
+ ## Output Checklist
59
+
60
+ - [ ] Redaction rules defined
61
+ - [ ] Logging policy documented
62
+ - [ ] Safe logger wrapper
63
+ - [ ] Team trained
64
+ - [ ] Log monitoring
65
+ ENDFILE
@@ -0,0 +1,80 @@
1
+ ---
2
+ name: rbac-policy-tester
3
+ description: Creates comprehensive permission tests ensuring RBAC doesn't regress with test matrices, CI gating, and authorization coverage. Use for "RBAC testing", "permission tests", "authorization testing", or "access control tests".
4
+ ---
5
+
6
+ # RBAC/Policy Tester
7
+
8
+ Comprehensive testing for role-based access control.
9
+
10
+ ## Permission Test Matrix
11
+
12
+ ```typescript
13
+ type Role = 'ADMIN' | 'MANAGER' | 'USER' | 'GUEST';
14
+ type Action = 'create' | 'read' | 'update' | 'delete';
15
+ type Resource = 'users' | 'orders' | 'reports';
16
+
17
+ const permissionMatrix: Record<Role, Record<Resource, Action[]>> = {
18
+ ADMIN: {
19
+ users: ['create', 'read', 'update', 'delete'],
20
+ orders: ['create', 'read', 'update', 'delete'],
21
+ reports: ['create', 'read', 'update', 'delete'],
22
+ },
23
+ MANAGER: {
24
+ users: ['read', 'update'],
25
+ orders: ['create', 'read', 'update'],
26
+ reports: ['read', 'update'],
27
+ },
28
+ USER: {
29
+ users: ['read'], // Only own profile
30
+ orders: ['create', 'read'], // Only own orders
31
+ reports: ['read'],
32
+ },
33
+ GUEST: {
34
+ users: [],
35
+ orders: [],
36
+ reports: ['read'],
37
+ },
38
+ };
39
+
40
+ describe('RBAC Tests', () => {
41
+ Object.entries(permissionMatrix).forEach(([role, resources]) => {
42
+ describe(\`Role: \${role}\`, () => {
43
+ Object.entries(resources).forEach(([resource, actions]) => {
44
+ actions.forEach(action => {
45
+ it(\`should allow \${action} on \${resource}\`, async () => {
46
+ const token = generateToken({ role });
47
+ await request(app)
48
+ .post(\`/api/\${resource}/\${action}\`)
49
+ .set('Authorization', \`Bearer \${token}\`)
50
+ .expect(200);
51
+ });
52
+ });
53
+
54
+ // Test forbidden actions
55
+ const allActions: Action[] = ['create', 'read', 'update', 'delete'];
56
+ const forbidden = allActions.filter(a => !actions.includes(a));
57
+
58
+ forbidden.forEach(action => {
59
+ it(\`should deny \${action} on \${resource}\`, async () => {
60
+ const token = generateToken({ role });
61
+ await request(app)
62
+ .post(\`/api/\${resource}/\${action}\`)
63
+ .set('Authorization', \`Bearer \${token}\`)
64
+ .expect(403);
65
+ });
66
+ });
67
+ });
68
+ });
69
+ });
70
+ });
71
+ ```
72
+
73
+ ## Output Checklist
74
+
75
+ - [ ] Permission matrix defined
76
+ - [ ] Test suite for all roles
77
+ - [ ] Positive and negative tests
78
+ - [ ] CI gating enabled
79
+ - [ ] Coverage monitoring
80
+ ENDFILE