@kevinrabun/judges 3.42.0 → 3.44.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/CHANGELOG.md +25 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +112 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/assign-findings.d.ts +37 -0
- package/dist/commands/assign-findings.d.ts.map +1 -0
- package/dist/commands/assign-findings.js +178 -0
- package/dist/commands/assign-findings.js.map +1 -0
- package/dist/commands/burndown.d.ts +27 -0
- package/dist/commands/burndown.d.ts.map +1 -0
- package/dist/commands/burndown.js +180 -0
- package/dist/commands/burndown.js.map +1 -0
- package/dist/commands/ci-template.d.ts +15 -0
- package/dist/commands/ci-template.d.ts.map +1 -0
- package/dist/commands/ci-template.js +212 -0
- package/dist/commands/ci-template.js.map +1 -0
- package/dist/commands/false-negatives.d.ts +35 -0
- package/dist/commands/false-negatives.d.ts.map +1 -0
- package/dist/commands/false-negatives.js +166 -0
- package/dist/commands/false-negatives.js.map +1 -0
- package/dist/commands/hook-install.d.ts +22 -0
- package/dist/commands/hook-install.d.ts.map +1 -0
- package/dist/commands/hook-install.js +143 -0
- package/dist/commands/hook-install.js.map +1 -0
- package/dist/commands/kb.d.ts +41 -0
- package/dist/commands/kb.d.ts.map +1 -0
- package/dist/commands/kb.js +231 -0
- package/dist/commands/kb.js.map +1 -0
- package/dist/commands/noise-advisor.d.ts +30 -0
- package/dist/commands/noise-advisor.d.ts.map +1 -0
- package/dist/commands/noise-advisor.js +171 -0
- package/dist/commands/noise-advisor.js.map +1 -0
- package/dist/commands/policy-audit.d.ts +53 -0
- package/dist/commands/policy-audit.d.ts.map +1 -0
- package/dist/commands/policy-audit.js +161 -0
- package/dist/commands/policy-audit.js.map +1 -0
- package/dist/commands/recommend.d.ts +21 -0
- package/dist/commands/recommend.d.ts.map +1 -0
- package/dist/commands/recommend.js +283 -0
- package/dist/commands/recommend.js.map +1 -0
- package/dist/commands/regression-alert.d.ts +32 -0
- package/dist/commands/regression-alert.d.ts.map +1 -0
- package/dist/commands/regression-alert.js +216 -0
- package/dist/commands/regression-alert.js.map +1 -0
- package/dist/commands/remediation.d.ts +21 -0
- package/dist/commands/remediation.d.ts.map +1 -0
- package/dist/commands/remediation.js +257 -0
- package/dist/commands/remediation.js.map +1 -0
- package/dist/commands/report-template.d.ts +17 -0
- package/dist/commands/report-template.d.ts.map +1 -0
- package/dist/commands/report-template.js +291 -0
- package/dist/commands/report-template.js.map +1 -0
- package/dist/commands/review-queue.d.ts +34 -0
- package/dist/commands/review-queue.d.ts.map +1 -0
- package/dist/commands/review-queue.js +226 -0
- package/dist/commands/review-queue.js.map +1 -0
- package/dist/commands/rule-owner.d.ts +31 -0
- package/dist/commands/rule-owner.d.ts.map +1 -0
- package/dist/commands/rule-owner.js +182 -0
- package/dist/commands/rule-owner.js.map +1 -0
- package/dist/commands/sla-track.d.ts +57 -0
- package/dist/commands/sla-track.d.ts.map +1 -0
- package/dist/commands/sla-track.js +269 -0
- package/dist/commands/sla-track.js.map +1 -0
- package/dist/commands/suppress.d.ts +40 -0
- package/dist/commands/suppress.d.ts.map +1 -0
- package/dist/commands/suppress.js +209 -0
- package/dist/commands/suppress.js.map +1 -0
- package/dist/commands/ticket-sync.d.ts +26 -0
- package/dist/commands/ticket-sync.d.ts.map +1 -0
- package/dist/commands/ticket-sync.js +236 -0
- package/dist/commands/ticket-sync.js.map +1 -0
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression alerting — compare current scan results against a saved
|
|
3
|
+
* baseline snapshot to detect quality regressions.
|
|
4
|
+
*
|
|
5
|
+
* Snapshots are stored locally in .judges-baseline.json.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
8
|
+
const BASELINE_FILE = ".judges-baseline.json";
|
|
9
|
+
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
10
|
+
function makeFindingId(f) {
|
|
11
|
+
return `${f.ruleId}::${f.title}`;
|
|
12
|
+
}
|
|
13
|
+
function getGitInfo() {
|
|
14
|
+
try {
|
|
15
|
+
const { execSync } = require("child_process");
|
|
16
|
+
const commit = execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim();
|
|
17
|
+
const branch = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf-8" }).trim();
|
|
18
|
+
return { commit, branch };
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function buildSnapshot(findings) {
|
|
25
|
+
const git = getGitInfo();
|
|
26
|
+
const bySeverity = {};
|
|
27
|
+
const byRule = {};
|
|
28
|
+
const findingIds = [];
|
|
29
|
+
for (const f of findings) {
|
|
30
|
+
bySeverity[f.severity] = (bySeverity[f.severity] || 0) + 1;
|
|
31
|
+
byRule[f.ruleId] = (byRule[f.ruleId] || 0) + 1;
|
|
32
|
+
findingIds.push(makeFindingId(f));
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
timestamp: new Date().toISOString(),
|
|
36
|
+
gitCommit: git.commit,
|
|
37
|
+
gitBranch: git.branch,
|
|
38
|
+
totalFindings: findings.length,
|
|
39
|
+
bySeverity,
|
|
40
|
+
byRule,
|
|
41
|
+
findingIds,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function saveBaseline(snapshot, file = BASELINE_FILE) {
|
|
45
|
+
writeFileSync(file, JSON.stringify(snapshot, null, 2));
|
|
46
|
+
}
|
|
47
|
+
export function loadBaseline(file = BASELINE_FILE) {
|
|
48
|
+
if (!existsSync(file))
|
|
49
|
+
return null;
|
|
50
|
+
return JSON.parse(readFileSync(file, "utf-8"));
|
|
51
|
+
}
|
|
52
|
+
export function compareSnapshots(baseline, current) {
|
|
53
|
+
const baseSet = new Set(baseline.findingIds);
|
|
54
|
+
const currSet = new Set(current.findingIds);
|
|
55
|
+
const newFindings = current.findingIds.filter((id) => !baseSet.has(id));
|
|
56
|
+
const fixedFindings = baseline.findingIds.filter((id) => !currSet.has(id));
|
|
57
|
+
const delta = current.totalFindings - baseline.totalFindings;
|
|
58
|
+
const severityDelta = {};
|
|
59
|
+
const allSeverities = new Set([...Object.keys(baseline.bySeverity), ...Object.keys(current.bySeverity)]);
|
|
60
|
+
for (const sev of allSeverities) {
|
|
61
|
+
severityDelta[sev] = (current.bySeverity[sev] || 0) - (baseline.bySeverity[sev] || 0);
|
|
62
|
+
}
|
|
63
|
+
const ruleDelta = {};
|
|
64
|
+
const allRules = new Set([...Object.keys(baseline.byRule), ...Object.keys(current.byRule)]);
|
|
65
|
+
for (const rule of allRules) {
|
|
66
|
+
const d = (current.byRule[rule] || 0) - (baseline.byRule[rule] || 0);
|
|
67
|
+
if (d !== 0)
|
|
68
|
+
ruleDelta[rule] = d;
|
|
69
|
+
}
|
|
70
|
+
let status = "stable";
|
|
71
|
+
if (delta > 0 || newFindings.length > 0)
|
|
72
|
+
status = "regressed";
|
|
73
|
+
else if (delta < 0 || fixedFindings.length > 0)
|
|
74
|
+
status = "improved";
|
|
75
|
+
return {
|
|
76
|
+
status,
|
|
77
|
+
newFindings,
|
|
78
|
+
fixedFindings,
|
|
79
|
+
delta,
|
|
80
|
+
severityDelta,
|
|
81
|
+
ruleDelta,
|
|
82
|
+
baseline,
|
|
83
|
+
current,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// ─── CLI ────────────────────────────────────────────────────────────────────
|
|
87
|
+
export async function runRegressionAlert(argv) {
|
|
88
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
89
|
+
console.log(`
|
|
90
|
+
judges regression-alert — Detect quality regressions between scans
|
|
91
|
+
|
|
92
|
+
Usage:
|
|
93
|
+
judges regression-alert --save --input results.json Save current results as baseline
|
|
94
|
+
judges regression-alert --check --input results.json Compare current results against baseline
|
|
95
|
+
judges regression-alert --show Show current baseline
|
|
96
|
+
|
|
97
|
+
Options:
|
|
98
|
+
--save Save current results as the baseline
|
|
99
|
+
--check Compare against saved baseline
|
|
100
|
+
--show Display stored baseline info
|
|
101
|
+
--input <path> Results JSON file
|
|
102
|
+
--fail-on-regression Exit with code 1 if regressions detected (CI mode)
|
|
103
|
+
--threshold <n> Only alert if >= n new findings (default: 1)
|
|
104
|
+
--format json JSON output
|
|
105
|
+
--help, -h Show this help
|
|
106
|
+
`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const format = argv.find((_a, i) => argv[i - 1] === "--format") || "text";
|
|
110
|
+
const inputPath = argv.find((_a, i) => argv[i - 1] === "--input");
|
|
111
|
+
const failOnRegression = argv.includes("--fail-on-regression");
|
|
112
|
+
const thresholdStr = argv.find((_a, i) => argv[i - 1] === "--threshold");
|
|
113
|
+
const threshold = thresholdStr ? parseInt(thresholdStr, 10) : 1;
|
|
114
|
+
// Show baseline
|
|
115
|
+
if (argv.includes("--show")) {
|
|
116
|
+
const baseline = loadBaseline();
|
|
117
|
+
if (!baseline) {
|
|
118
|
+
console.log("\n No baseline saved. Run with --save first.\n");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (format === "json") {
|
|
122
|
+
console.log(JSON.stringify(baseline, null, 2));
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
console.log(`
|
|
126
|
+
Baseline Snapshot
|
|
127
|
+
─────────────────
|
|
128
|
+
Saved: ${baseline.timestamp}
|
|
129
|
+
Commit: ${baseline.gitCommit || "unknown"}
|
|
130
|
+
Branch: ${baseline.gitBranch || "unknown"}
|
|
131
|
+
Findings: ${baseline.totalFindings}
|
|
132
|
+
`);
|
|
133
|
+
for (const [sev, count] of Object.entries(baseline.bySeverity)) {
|
|
134
|
+
console.log(` ${sev.padEnd(10)} ${count}`);
|
|
135
|
+
}
|
|
136
|
+
console.log("");
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Both --save and --check need input
|
|
141
|
+
if (!inputPath) {
|
|
142
|
+
console.error("Error: --input <path> required");
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
if (!existsSync(inputPath)) {
|
|
146
|
+
console.error(`Error: file not found: ${inputPath}`);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
const data = JSON.parse(readFileSync(inputPath, "utf-8"));
|
|
150
|
+
const findings = data.evaluations
|
|
151
|
+
? data.evaluations.flatMap((e) => e.findings || [])
|
|
152
|
+
: data.findings || data;
|
|
153
|
+
const snapshot = buildSnapshot(findings);
|
|
154
|
+
// Save baseline
|
|
155
|
+
if (argv.includes("--save")) {
|
|
156
|
+
saveBaseline(snapshot);
|
|
157
|
+
if (format === "json") {
|
|
158
|
+
console.log(JSON.stringify(snapshot, null, 2));
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
console.log(`\n Baseline saved: ${snapshot.totalFindings} findings (${snapshot.gitCommit || "no git"})\n`);
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// Check against baseline
|
|
166
|
+
if (argv.includes("--check")) {
|
|
167
|
+
const baseline = loadBaseline();
|
|
168
|
+
if (!baseline) {
|
|
169
|
+
console.error("Error: No baseline saved. Run with --save first.");
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
const report = compareSnapshots(baseline, snapshot);
|
|
173
|
+
if (format === "json") {
|
|
174
|
+
console.log(JSON.stringify(report, null, 2));
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const icon = report.status === "improved" ? "✅" : report.status === "regressed" ? "🚨" : "➖";
|
|
178
|
+
console.log(`\n ${icon} Status: ${report.status.toUpperCase()} (delta: ${report.delta >= 0 ? "+" : ""}${report.delta})`);
|
|
179
|
+
console.log(` Baseline: ${baseline.totalFindings} findings (${baseline.gitCommit || "?"})`);
|
|
180
|
+
console.log(` Current: ${snapshot.totalFindings} findings (${snapshot.gitCommit || "?"})\n`);
|
|
181
|
+
if (report.newFindings.length > 0) {
|
|
182
|
+
console.log(` New findings (${report.newFindings.length}):`);
|
|
183
|
+
for (const id of report.newFindings.slice(0, 20)) {
|
|
184
|
+
console.log(` + ${id}`);
|
|
185
|
+
}
|
|
186
|
+
if (report.newFindings.length > 20) {
|
|
187
|
+
console.log(` ... and ${report.newFindings.length - 20} more`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (report.fixedFindings.length > 0) {
|
|
191
|
+
console.log(`\n Fixed findings (${report.fixedFindings.length}):`);
|
|
192
|
+
for (const id of report.fixedFindings.slice(0, 20)) {
|
|
193
|
+
console.log(` - ${id}`);
|
|
194
|
+
}
|
|
195
|
+
if (report.fixedFindings.length > 20) {
|
|
196
|
+
console.log(` ... and ${report.fixedFindings.length - 20} more`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (Object.keys(report.severityDelta).length > 0) {
|
|
200
|
+
console.log("\n By severity:");
|
|
201
|
+
for (const [sev, d] of Object.entries(report.severityDelta)) {
|
|
202
|
+
if (d !== 0)
|
|
203
|
+
console.log(` ${sev.padEnd(10)} ${d >= 0 ? "+" : ""}${d}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
console.log("");
|
|
207
|
+
}
|
|
208
|
+
if (failOnRegression && report.newFindings.length >= threshold) {
|
|
209
|
+
console.error(` ❌ Regression detected: ${report.newFindings.length} new finding(s) (threshold: ${threshold})`);
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
console.log("Use --save, --check, or --show. See --help for details.");
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=regression-alert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regression-alert.js","sourceRoot":"","sources":["../../src/commands/regression-alert.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAA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+
* Each guide includes: description, risk level, fix steps,
|
|
6
|
+
* code examples (before/after), and references.
|
|
7
|
+
*/
|
|
8
|
+
export interface RemediationGuide {
|
|
9
|
+
rulePrefix: string;
|
|
10
|
+
title: string;
|
|
11
|
+
category: string;
|
|
12
|
+
risk: string;
|
|
13
|
+
steps: string[];
|
|
14
|
+
beforeCode?: string;
|
|
15
|
+
afterCode?: string;
|
|
16
|
+
references: string[];
|
|
17
|
+
}
|
|
18
|
+
export declare function findGuide(ruleId: string): RemediationGuide | undefined;
|
|
19
|
+
export declare function listGuides(): RemediationGuide[];
|
|
20
|
+
export declare function runRemediationGuide(argv: string[]): void;
|
|
21
|
+
//# sourceMappingURL=remediation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remediation.d.ts","sourceRoot":"","sources":["../../src/commands/remediation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AA6KD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAGtE;AAED,wBAAgB,UAAU,IAAI,gBAAgB,EAAE,CAE/C;AAID,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAmFxD"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remediation guides — provide step-by-step fix guidance for common
|
|
3
|
+
* finding categories, linked from finding output.
|
|
4
|
+
*
|
|
5
|
+
* Each guide includes: description, risk level, fix steps,
|
|
6
|
+
* code examples (before/after), and references.
|
|
7
|
+
*/
|
|
8
|
+
// ─── Guides ─────────────────────────────────────────────────────────────────
|
|
9
|
+
const GUIDES = [
|
|
10
|
+
{
|
|
11
|
+
rulePrefix: "SEC-001",
|
|
12
|
+
title: "SQL Injection Prevention",
|
|
13
|
+
category: "Security",
|
|
14
|
+
risk: "Critical — allows attackers to read/modify/delete database data",
|
|
15
|
+
steps: [
|
|
16
|
+
"Replace string concatenation in SQL queries with parameterized queries",
|
|
17
|
+
"Use your ORM's built-in query builder instead of raw SQL",
|
|
18
|
+
"If raw SQL is required, use prepared statements with placeholders",
|
|
19
|
+
"Validate and sanitize all user input before using in queries",
|
|
20
|
+
"Apply principle of least privilege to database accounts",
|
|
21
|
+
],
|
|
22
|
+
beforeCode: `// VULNERABLE\nconst result = await db.query(\`SELECT * FROM users WHERE id = '\${userId}'\`);`,
|
|
23
|
+
afterCode: `// SECURE\nconst result = await db.query('SELECT * FROM users WHERE id = $1', [userId]);`,
|
|
24
|
+
references: [
|
|
25
|
+
"https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html",
|
|
26
|
+
"https://cwe.mitre.org/data/definitions/89.html",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
rulePrefix: "SEC-002",
|
|
31
|
+
title: "Cross-Site Scripting (XSS) Prevention",
|
|
32
|
+
category: "Security",
|
|
33
|
+
risk: "High — allows attackers to execute scripts in users' browsers",
|
|
34
|
+
steps: [
|
|
35
|
+
"Use context-aware output encoding (HTML, JavaScript, URL, CSS)",
|
|
36
|
+
"Use framework auto-escaping (React JSX, Angular templates, etc.)",
|
|
37
|
+
"Avoid dangerouslySetInnerHTML / v-html / innerHTML",
|
|
38
|
+
"Implement Content-Security-Policy headers",
|
|
39
|
+
"Validate and sanitize user input on the server side",
|
|
40
|
+
],
|
|
41
|
+
beforeCode: `// VULNERABLE\nelement.innerHTML = userInput;`,
|
|
42
|
+
afterCode: `// SECURE\nelement.textContent = userInput;`,
|
|
43
|
+
references: [
|
|
44
|
+
"https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html",
|
|
45
|
+
"https://cwe.mitre.org/data/definitions/79.html",
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
rulePrefix: "SEC-003",
|
|
50
|
+
title: "Command Injection Prevention",
|
|
51
|
+
category: "Security",
|
|
52
|
+
risk: "Critical — allows attackers to execute arbitrary OS commands",
|
|
53
|
+
steps: [
|
|
54
|
+
"Avoid shell command execution with user-controlled input",
|
|
55
|
+
"Use language-native APIs instead of shell commands (e.g., fs.readdir instead of ls)",
|
|
56
|
+
"If shell execution is required, use allowlists for permitted commands",
|
|
57
|
+
"Use execFile/spawn with explicit argument arrays instead of exec with string concatenation",
|
|
58
|
+
"Never pass user input directly to child_process.exec()",
|
|
59
|
+
],
|
|
60
|
+
beforeCode: `// VULNERABLE\nexec(\`ls \${userDir}\`);`,
|
|
61
|
+
afterCode: `// SECURE\nexecFile('ls', [userDir]);`,
|
|
62
|
+
references: [
|
|
63
|
+
"https://cheatsheetseries.owasp.org/cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.html",
|
|
64
|
+
"https://cwe.mitre.org/data/definitions/78.html",
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
rulePrefix: "AUTH-",
|
|
69
|
+
title: "Authentication Best Practices",
|
|
70
|
+
category: "Security",
|
|
71
|
+
risk: "High — weak authentication allows unauthorized access",
|
|
72
|
+
steps: [
|
|
73
|
+
"Use bcrypt, argon2, or scrypt for password hashing (never MD5/SHA1)",
|
|
74
|
+
"Implement rate limiting on login endpoints",
|
|
75
|
+
"Use secure session management with HttpOnly, Secure, SameSite cookies",
|
|
76
|
+
"Implement multi-factor authentication for sensitive operations",
|
|
77
|
+
"Validate JWT tokens on every request (check signature, expiry, issuer)",
|
|
78
|
+
],
|
|
79
|
+
references: [
|
|
80
|
+
"https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html",
|
|
81
|
+
"https://cwe.mitre.org/data/definitions/287.html",
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
rulePrefix: "CRYPTO-",
|
|
86
|
+
title: "Cryptographic Best Practices",
|
|
87
|
+
category: "Security",
|
|
88
|
+
risk: "High — weak cryptography exposes sensitive data",
|
|
89
|
+
steps: [
|
|
90
|
+
"Use AES-256-GCM for symmetric encryption (not DES, 3DES, or ECB mode)",
|
|
91
|
+
"Use RSA-2048+ or ECDSA P-256+ for asymmetric encryption",
|
|
92
|
+
"Use SHA-256+ for hashing (not MD5 or SHA-1)",
|
|
93
|
+
"Never hardcode encryption keys or secrets in source code",
|
|
94
|
+
"Use platform-provided key management (AWS KMS, Azure Key Vault, etc.)",
|
|
95
|
+
],
|
|
96
|
+
references: [
|
|
97
|
+
"https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html",
|
|
98
|
+
"https://cwe.mitre.org/data/definitions/327.html",
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
rulePrefix: "SSRF-",
|
|
103
|
+
title: "Server-Side Request Forgery Prevention",
|
|
104
|
+
category: "Security",
|
|
105
|
+
risk: "High — allows attackers to make requests from your server to internal resources",
|
|
106
|
+
steps: [
|
|
107
|
+
"Validate and sanitize all URLs before making server-side requests",
|
|
108
|
+
"Use an allowlist of permitted domains/IPs",
|
|
109
|
+
"Block requests to private IP ranges (10.x, 172.16-31.x, 192.168.x, 127.x, ::1)",
|
|
110
|
+
"Disable HTTP redirects or validate redirect targets",
|
|
111
|
+
"Use a URL parser to validate the scheme (allow only https://)",
|
|
112
|
+
],
|
|
113
|
+
references: [
|
|
114
|
+
"https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html",
|
|
115
|
+
"https://cwe.mitre.org/data/definitions/918.html",
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
rulePrefix: "PERF-",
|
|
120
|
+
title: "Performance Optimization",
|
|
121
|
+
category: "Performance",
|
|
122
|
+
risk: "Medium — poor performance degrades user experience and increases costs",
|
|
123
|
+
steps: [
|
|
124
|
+
"Identify the bottleneck: CPU, memory, I/O, or network",
|
|
125
|
+
"Use profiling tools (Node.js --prof, py-spy, Go pprof)",
|
|
126
|
+
"Avoid N+1 queries — batch database operations",
|
|
127
|
+
"Use caching for expensive computations (Redis, in-memory LRU)",
|
|
128
|
+
"Implement pagination for large result sets",
|
|
129
|
+
],
|
|
130
|
+
references: ["https://web.dev/performance/"],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
rulePrefix: "ERR-",
|
|
134
|
+
title: "Error Handling Best Practices",
|
|
135
|
+
category: "Reliability",
|
|
136
|
+
risk: "Medium — poor error handling causes crashes and data corruption",
|
|
137
|
+
steps: [
|
|
138
|
+
"Catch and handle errors at appropriate boundaries",
|
|
139
|
+
"Never swallow exceptions silently — at minimum log them",
|
|
140
|
+
"Use structured error types with error codes",
|
|
141
|
+
"Implement graceful degradation for non-critical failures",
|
|
142
|
+
"Never expose stack traces or internal error details to users",
|
|
143
|
+
],
|
|
144
|
+
references: ["https://cheatsheetseries.owasp.org/cheatsheets/Error_Handling_Cheat_Sheet.html"],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
rulePrefix: "CONCUR-",
|
|
148
|
+
title: "Concurrency Safety",
|
|
149
|
+
category: "Reliability",
|
|
150
|
+
risk: "High — race conditions cause data corruption and security vulnerabilities",
|
|
151
|
+
steps: [
|
|
152
|
+
"Identify shared mutable state and protect it with locks/mutexes",
|
|
153
|
+
"Prefer immutable data structures",
|
|
154
|
+
"Use atomic operations for simple shared counters",
|
|
155
|
+
"Avoid holding multiple locks simultaneously (prevents deadlocks)",
|
|
156
|
+
"Use channels/message-passing instead of shared memory where possible",
|
|
157
|
+
],
|
|
158
|
+
references: ["https://cwe.mitre.org/data/definitions/362.html"],
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
rulePrefix: "IAC-",
|
|
162
|
+
title: "Infrastructure as Code Security",
|
|
163
|
+
category: "Infrastructure",
|
|
164
|
+
risk: "High — IaC misconfigurations expose cloud resources to attack",
|
|
165
|
+
steps: [
|
|
166
|
+
"Enable encryption at rest and in transit for all storage resources",
|
|
167
|
+
"Apply principle of least privilege to IAM roles and policies",
|
|
168
|
+
"Enable logging and monitoring (CloudTrail, Azure Monitor, etc.)",
|
|
169
|
+
"Use private subnets for databases and internal services",
|
|
170
|
+
"Never hardcode secrets in Terraform/Bicep/CloudFormation templates",
|
|
171
|
+
],
|
|
172
|
+
references: ["https://cheatsheetseries.owasp.org/cheatsheets/Infrastructure_as_Code_Security_Cheat_Sheet.html"],
|
|
173
|
+
},
|
|
174
|
+
];
|
|
175
|
+
// ─── Lookup API ─────────────────────────────────────────────────────────────
|
|
176
|
+
export function findGuide(ruleId) {
|
|
177
|
+
// Exact match first, then prefix match
|
|
178
|
+
return GUIDES.find((g) => ruleId.startsWith(g.rulePrefix));
|
|
179
|
+
}
|
|
180
|
+
export function listGuides() {
|
|
181
|
+
return GUIDES;
|
|
182
|
+
}
|
|
183
|
+
// ─── CLI ────────────────────────────────────────────────────────────────────
|
|
184
|
+
export function runRemediationGuide(argv) {
|
|
185
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
186
|
+
console.log(`
|
|
187
|
+
judges remediation — Step-by-step fix guidance for findings
|
|
188
|
+
|
|
189
|
+
Usage:
|
|
190
|
+
judges remediation SEC-001 Show guide for a specific rule
|
|
191
|
+
judges remediation --list List all available guides
|
|
192
|
+
judges remediation --category Security Filter by category
|
|
193
|
+
|
|
194
|
+
Options:
|
|
195
|
+
--list List all guides
|
|
196
|
+
--category <cat> Filter by category
|
|
197
|
+
--format json JSON output
|
|
198
|
+
--help, -h Show this help
|
|
199
|
+
`);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const format = argv.find((_a, i) => argv[i - 1] === "--format") || "text";
|
|
203
|
+
const categoryFilter = argv.find((_a, i) => argv[i - 1] === "--category");
|
|
204
|
+
if (argv.includes("--list")) {
|
|
205
|
+
let guides = GUIDES;
|
|
206
|
+
if (categoryFilter)
|
|
207
|
+
guides = guides.filter((g) => g.category.toLowerCase() === categoryFilter.toLowerCase());
|
|
208
|
+
if (format === "json") {
|
|
209
|
+
console.log(JSON.stringify(guides, null, 2));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
console.log("\n Available Remediation Guides:\n");
|
|
213
|
+
for (const g of guides) {
|
|
214
|
+
console.log(` ${g.rulePrefix.padEnd(12)} ${g.title.padEnd(40)} [${g.category}]`);
|
|
215
|
+
}
|
|
216
|
+
console.log("");
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
// Find guide by rule ID
|
|
220
|
+
const ruleId = argv.find((a, i) => i > 1 && !a.startsWith("-") && argv[i - 1] !== "--format" && argv[i - 1] !== "--category");
|
|
221
|
+
if (!ruleId) {
|
|
222
|
+
console.error("Error: provide a rule ID or use --list");
|
|
223
|
+
process.exit(1);
|
|
224
|
+
}
|
|
225
|
+
const guide = findGuide(ruleId);
|
|
226
|
+
if (!guide) {
|
|
227
|
+
console.log(` No guide found for "${ruleId}". Use --list to see available guides.`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (format === "json") {
|
|
231
|
+
console.log(JSON.stringify(guide, null, 2));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
console.log(`\n 📖 ${guide.title}\n`);
|
|
235
|
+
console.log(` Category: ${guide.category}`);
|
|
236
|
+
console.log(` Risk: ${guide.risk}\n`);
|
|
237
|
+
console.log(" Steps:");
|
|
238
|
+
for (let i = 0; i < guide.steps.length; i++) {
|
|
239
|
+
console.log(` ${i + 1}. ${guide.steps[i]}`);
|
|
240
|
+
}
|
|
241
|
+
if (guide.beforeCode) {
|
|
242
|
+
console.log("\n Before (vulnerable):");
|
|
243
|
+
console.log(` ${guide.beforeCode.split("\n").join("\n ")}`);
|
|
244
|
+
}
|
|
245
|
+
if (guide.afterCode) {
|
|
246
|
+
console.log("\n After (secure):");
|
|
247
|
+
console.log(` ${guide.afterCode.split("\n").join("\n ")}`);
|
|
248
|
+
}
|
|
249
|
+
if (guide.references.length > 0) {
|
|
250
|
+
console.log("\n References:");
|
|
251
|
+
for (const ref of guide.references) {
|
|
252
|
+
console.log(` • ${ref}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
console.log("");
|
|
256
|
+
}
|
|
257
|
+
//# sourceMappingURL=remediation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remediation.js","sourceRoot":"","sources":["../../src/commands/remediation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH,+EAA+E;AAE/E,MAAM,MAAM,GAAuB;IACjC;QACE,UAAU,EAAE,SAAS;QACrB,KAAK,EAAE,0BAA0B;QACjC,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,iEAAiE;QACvE,KAAK,EAAE;YACL,wEAAwE;YACxE,0DAA0D;YAC1D,mEAAmE;YACnE,8DAA8D;YAC9D,yDAAyD;SAC1D;QACD,UAAU,EAAE,gGAAgG;QAC5G,SAAS,EAAE,0FAA0F;QACrG,UAAU,EAAE;YACV,0FAA0F;YAC1F,gDAAgD;SACjD;KACF;IACD;QACE,UAAU,EAAE,SAAS;QACrB,KAAK,EAAE,uCAAuC;QAC9C,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,+DAA+D;QACrE,KAAK,EAAE;YACL,gEAAgE;YAChE,kEAAkE;YAClE,oDAAoD;YACpD,2CAA2C;YAC3C,qDAAqD;SACtD;QACD,UAAU,EAAE,+CAA+C;QAC3D,SAAS,EAAE,6CAA6C;QACxD,UAAU,EAAE;YACV,iGAAiG;YACjG,gDAAgD;SACjD;KACF;IACD;QACE,UAAU,EAAE,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AK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;QACpB,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC/B,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACnC,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Report templates — generate reports from different predefined
|
|
3
|
+
* templates targeting different audiences (exec, dev, compliance).
|
|
4
|
+
*
|
|
5
|
+
* Pure local generation — no external services.
|
|
6
|
+
*/
|
|
7
|
+
import type { TribunalVerdict } from "../types.js";
|
|
8
|
+
export interface ReportTemplate {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
audience: string;
|
|
12
|
+
description: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function listTemplates(): ReportTemplate[];
|
|
15
|
+
export declare function generateReport(templateId: string, verdict: TribunalVerdict): string;
|
|
16
|
+
export declare function runReportTemplate(argv: string[]): void;
|
|
17
|
+
//# sourceMappingURL=report-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"report-template.d.ts","sourceRoot":"","sources":["../../src/commands/report-template.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAW,eAAe,EAAE,MAAM,aAAa,CAAC;AAI5D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AA8PD,wBAAgB,aAAa,IAAI,cAAc,EAAE,CAEhD;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAiBnF;AAID,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CA6DtD"}
|