@abdulr7man/pensieve 0.0.0-stage → 1.2.2
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/LICENSE +684 -0
- package/README.md +180 -2
- package/VERSION +1 -0
- package/agents/README.md +16 -0
- package/agents/pensieve-code-auditor.md +58 -0
- package/agents/pensieve-mapper.md +46 -0
- package/agents/pensieve-planner.md +67 -0
- package/agents/pensieve-reconner.md +76 -0
- package/agents/pensieve-reporter.md +61 -0
- package/agents/pensieve-roe-checker.md +46 -0
- package/agents/pensieve-scoper.md +77 -0
- package/agents/pensieve-tester.md +83 -0
- package/agents/pensieve-validator.md +62 -0
- package/bin/pensieve +452 -0
- package/bin/pensieve-installer.cjs +5 -0
- package/commands/pensieve-close.md +6 -0
- package/commands/pensieve-map.md +6 -0
- package/commands/pensieve-new-engagement.md +6 -0
- package/commands/pensieve-pause.md +15 -0
- package/commands/pensieve-plan.md +6 -0
- package/commands/pensieve-progress.md +34 -0
- package/commands/pensieve-quick.md +8 -0
- package/commands/pensieve-recon.md +6 -0
- package/commands/pensieve-report.md +6 -0
- package/commands/pensieve-resume.md +6 -0
- package/commands/pensieve-retest.md +10 -0
- package/commands/pensieve-scope.md +49 -0
- package/commands/pensieve-surface.md +8 -0
- package/commands/pensieve-test.md +6 -0
- package/commands/pensieve-validate.md +6 -0
- package/docker/Dockerfile.pensieve-toolbox +75 -0
- package/docker/compose.pensieve-net.yml +37 -0
- package/docker/squid.conf.template +21 -0
- package/package.json +39 -4
- package/packs/ad/ad-killchain/checklist.md +64 -0
- package/packs/ad/ad-killchain/pack.yaml +19 -0
- package/packs/cloud/cloud-cis/checklist.md +66 -0
- package/packs/cloud/cloud-cis/pack.yaml +20 -0
- package/packs/fintech/practice-core/checklist.md +33 -0
- package/packs/fintech/practice-core/learnings.md +5 -0
- package/packs/fintech/practice-core/pack.yaml +18 -0
- package/packs/infra/ptes-infra/checklist.md +22 -0
- package/packs/infra/ptes-infra/pack.yaml +19 -0
- package/packs/mobile/owasp-masvs/checklist.md +80 -0
- package/packs/mobile/owasp-masvs/pack.yaml +20 -0
- package/packs/owasp-api-v4/checklist.md +85 -0
- package/packs/owasp-api-v4/learnings.md +6 -0
- package/packs/owasp-api-v4/pack.yaml +23 -0
- package/packs/owasp-api-v4/runbooks/API1/SKILL.md +66 -0
- package/packs/owasp-api-v4/runbooks/API10/SKILL.md +67 -0
- package/packs/owasp-api-v4/runbooks/API2/SKILL.md +129 -0
- package/packs/owasp-api-v4/runbooks/API3/SKILL.md +55 -0
- package/packs/owasp-api-v4/runbooks/API4/SKILL.md +59 -0
- package/packs/owasp-api-v4/runbooks/API5/SKILL.md +60 -0
- package/packs/owasp-api-v4/runbooks/API6/SKILL.md +63 -0
- package/packs/owasp-api-v4/runbooks/API7/SKILL.md +70 -0
- package/packs/owasp-api-v4/runbooks/API8/SKILL.md +72 -0
- package/packs/owasp-api-v4/runbooks/API9/SKILL.md +66 -0
- package/packs/thickclient/thickclient-core/checklist.md +60 -0
- package/packs/thickclient/thickclient-core/pack.yaml +24 -0
- package/packs/web/asvs-l2/checklist.md +50 -0
- package/packs/web/asvs-l2/learnings.md +6 -0
- package/packs/web/asvs-l2/pack.yaml +19 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-ENUM/SKILL.md +75 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-LIVE/SKILL.md +78 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-MFA/SKILL.md +76 -0
- package/packs/web/asvs-l2/runbooks/V2-AUTH-RATE/SKILL.md +72 -0
- package/packs/web/owasp-testing-checklist/checklist.md +52 -0
- package/packs/web/owasp-testing-checklist/learnings.md +47 -0
- package/packs/web/owasp-testing-checklist/pack.yaml +21 -0
- package/packs/web/unauth-perimeter/checklist.md +72 -0
- package/packs/web/unauth-perimeter/pack.yaml +18 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-01/SKILL.md +60 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-02/SKILL.md +63 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-03/SKILL.md +62 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-04/SKILL.md +75 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-05/SKILL.md +66 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-06/SKILL.md +59 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-07/SKILL.md +56 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-08/SKILL.md +57 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-09/SKILL.md +62 -0
- package/packs/web/unauth-perimeter/runbooks/PERIM-10/SKILL.md +60 -0
- package/packs/whitebox/code-audit-core/checklist.md +36 -0
- package/packs/whitebox/code-audit-core/learnings.md +6 -0
- package/packs/whitebox/code-audit-core/pack.yaml +14 -0
- package/prompts/orchestrator-core.md +52 -0
- package/reference/attack-playbooks.md +57 -0
- package/reference/otp-relay.md +98 -0
- package/reference/param-profiles.md +48 -0
- package/reference/templates/FINDING.md +97 -0
- package/reference/tool-selection.md +64 -0
- package/reference/vulnerability-finding-standard.md +80 -0
- package/runtimes/hermes/hooks/injection-scan.py +290 -0
- package/runtimes/hermes/hooks/scope-guard.py +136 -0
- package/skills/pensieve/SKILL.md +134 -0
- package/skills/pensieve-close/SKILL.md +31 -0
- package/skills/pensieve-map/SKILL.md +25 -0
- package/skills/pensieve-new-engagement/SKILL.md +28 -0
- package/skills/pensieve-pause/SKILL.md +22 -0
- package/skills/pensieve-plan/SKILL.md +39 -0
- package/skills/pensieve-progress/SKILL.md +35 -0
- package/skills/pensieve-quick/SKILL.md +47 -0
- package/skills/pensieve-recon/SKILL.md +30 -0
- package/skills/pensieve-report/SKILL.md +46 -0
- package/skills/pensieve-resume/SKILL.md +33 -0
- package/skills/pensieve-retest/SKILL.md +35 -0
- package/skills/pensieve-scope/SKILL.md +35 -0
- package/skills/pensieve-surface/SKILL.md +36 -0
- package/skills/pensieve-test/SKILL.md +35 -0
- package/skills/pensieve-validate/SKILL.md +28 -0
- package/skills/pensieve-wiki/SKILL.md +39 -0
- package/src/installer/cli.cjs +209 -0
- package/src/installer/home.cjs +155 -0
- package/src/installer/runtimes.cjs +276 -0
- package/src/installer/uninstall.cjs +342 -0
- package/src/pensieve-sdk/bin/pensieve-sdk.cjs +1045 -0
- package/src/pensieve-sdk/lib/agent-translate.cjs +50 -0
- package/src/pensieve-sdk/lib/approvals.cjs +408 -0
- package/src/pensieve-sdk/lib/audit.cjs +290 -0
- package/src/pensieve-sdk/lib/checklist.cjs +337 -0
- package/src/pensieve-sdk/lib/clientlist.cjs +814 -0
- package/src/pensieve-sdk/lib/close.cjs +133 -0
- package/src/pensieve-sdk/lib/config.cjs +156 -0
- package/src/pensieve-sdk/lib/cvss.cjs +91 -0
- package/src/pensieve-sdk/lib/env.cjs +272 -0
- package/src/pensieve-sdk/lib/evidence.cjs +217 -0
- package/src/pensieve-sdk/lib/findings.cjs +1096 -0
- package/src/pensieve-sdk/lib/frontmatter.cjs +178 -0
- package/src/pensieve-sdk/lib/graph.cjs +607 -0
- package/src/pensieve-sdk/lib/ids.cjs +63 -0
- package/src/pensieve-sdk/lib/init.cjs +79 -0
- package/src/pensieve-sdk/lib/liveness.cjs +176 -0
- package/src/pensieve-sdk/lib/loop.cjs +619 -0
- package/src/pensieve-sdk/lib/migrate.cjs +57 -0
- package/src/pensieve-sdk/lib/monitor.cjs +69 -0
- package/src/pensieve-sdk/lib/pack.cjs +607 -0
- package/src/pensieve-sdk/lib/paths.cjs +73 -0
- package/src/pensieve-sdk/lib/pdf.cjs +291 -0
- package/src/pensieve-sdk/lib/recon.cjs +296 -0
- package/src/pensieve-sdk/lib/renderers/__pycache__/formal_report.cpython-314.pyc +0 -0
- package/src/pensieve-sdk/lib/renderers/formal_report.py +608 -0
- package/src/pensieve-sdk/lib/report.cjs +1135 -0
- package/src/pensieve-sdk/lib/runbook.cjs +124 -0
- package/src/pensieve-sdk/lib/sarif.cjs +154 -0
- package/src/pensieve-sdk/lib/scope.cjs +621 -0
- package/src/pensieve-sdk/lib/security.cjs +61 -0
- package/src/pensieve-sdk/lib/skills.cjs +193 -0
- package/src/pensieve-sdk/lib/state.cjs +610 -0
- package/src/pensieve-sdk/lib/subagent.cjs +658 -0
- package/src/pensieve-sdk/lib/target.cjs +149 -0
- package/src/pensieve-sdk/lib/tools.cjs +66 -0
- package/src/pensieve-sdk/lib/vault.cjs +122 -0
- package/src/pensieve-sdk/lib/vendor/cvss40.LICENSE +22 -0
- package/src/pensieve-sdk/lib/vendor/cvss40.js +1208 -0
- package/src/pensieve-sdk/package.json +11 -0
- package/templates/ACCOUNTS.md +35 -0
- package/templates/ATTACK-SURFACE.md +30 -0
- package/templates/FINDING.md +43 -0
- package/templates/PLAN.md +33 -0
- package/templates/PROJECT.md +29 -0
- package/templates/ROE.md +50 -0
- package/templates/RUN-LOG.md +19 -0
- package/templates/SCOPE.md +32 -0
- package/templates/VALIDATION.md +62 -0
- package/templates/report/REPORT.md +49 -0
- package/workflows/close.md +34 -0
- package/workflows/map.md +39 -0
- package/workflows/new-engagement.md +37 -0
- package/workflows/plan.md +45 -0
- package/workflows/progress.md +28 -0
- package/workflows/quick.md +67 -0
- package/workflows/recon.md +87 -0
- package/workflows/report.md +51 -0
- package/workflows/resume.md +26 -0
- package/workflows/retest.md +53 -0
- package/workflows/scope.md +47 -0
- package/workflows/surface.md +29 -0
- package/workflows/test.md +95 -0
- package/workflows/validate.md +34 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* runbook.cjs — deterministic presence validator for RUNBOOK-01 SKILL.md files.
|
|
4
|
+
*
|
|
5
|
+
* Checks that a runbook carries every required frontmatter key and body section
|
|
6
|
+
* (the three mandated parts: exact tool calls, expected evidence, pass/fail).
|
|
7
|
+
* Ceiling: PRESENCE only, not semantic quality of the commands — see
|
|
8
|
+
* docs/RUNBOOK-FORMAT.md. Zero new dependency: node builtins + ./frontmatter.cjs
|
|
9
|
+
* + ./skills.cjs (resolveWithinBase, for slug/path confinement).
|
|
10
|
+
*/
|
|
11
|
+
const fs = require('node:fs');
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
const fm = require('./frontmatter.cjs');
|
|
14
|
+
const pack = require('./pack.cjs');
|
|
15
|
+
const { resolveWithinBase } = require('./skills.cjs');
|
|
16
|
+
|
|
17
|
+
const REQUIRED_KEYS = ['name', 'item', 'description', 'agents', 'pack'];
|
|
18
|
+
const REQUIRED_SECTIONS = ['## Tools', '## Steps', '## Expected Evidence', '## Pass/Fail'];
|
|
19
|
+
|
|
20
|
+
// absent, null, empty string, or empty array all count as missing (T-09-03:
|
|
21
|
+
// an empty-string/empty-array key is NOT "present").
|
|
22
|
+
function isMissing(v) {
|
|
23
|
+
if (v === undefined || v === null || v === '') return true;
|
|
24
|
+
if (Array.isArray(v)) return v.length === 0;
|
|
25
|
+
// a bare `key:` with no value parses to an empty object -> no real content
|
|
26
|
+
if (typeof v === 'object') return Object.keys(v).length === 0;
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function hasSection(body, heading) {
|
|
31
|
+
return String(body).split('\n').some((line) => line.trim() === heading);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function lint(text) {
|
|
35
|
+
let data = {};
|
|
36
|
+
let body = String(text);
|
|
37
|
+
try {
|
|
38
|
+
const parsed = fm.parse(text);
|
|
39
|
+
data = parsed.data || {};
|
|
40
|
+
body = parsed.body || '';
|
|
41
|
+
} catch {
|
|
42
|
+
// malformed frontmatter -> treat as absent; sections checked against raw text
|
|
43
|
+
}
|
|
44
|
+
const missing = [];
|
|
45
|
+
for (const key of REQUIRED_KEYS) {
|
|
46
|
+
if (isMissing(data[key])) missing.push(`frontmatter:${key}`);
|
|
47
|
+
}
|
|
48
|
+
for (const section of REQUIRED_SECTIONS) {
|
|
49
|
+
if (!hasSection(body, section)) missing.push(`section:${section}`);
|
|
50
|
+
}
|
|
51
|
+
return missing;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function lintFile(absPath) {
|
|
55
|
+
const missing = lint(fs.readFileSync(absPath, 'utf8'));
|
|
56
|
+
return { path: absPath, missing };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// target is either a path to a SKILL.md OR a pack slug (resolved to
|
|
60
|
+
// <pack-dir>/runbooks/*/SKILL.md through pack's ONE multi-root resolver —
|
|
61
|
+
// 31-01: a USER-root pack lints identically; a slug colliding across roots
|
|
62
|
+
// refuses with both paths named, never lints a silently-shadowed tree).
|
|
63
|
+
function collect(target, { packsRoot } = {}) {
|
|
64
|
+
const results = [];
|
|
65
|
+
|
|
66
|
+
if (typeof target === 'string' && fs.existsSync(target) && fs.statSync(target).isFile()) {
|
|
67
|
+
results.push(lintFile(path.resolve(target)));
|
|
68
|
+
} else {
|
|
69
|
+
if (!packsRoot) throw new Error(`cannot resolve runbook target without packsRoot: ${target}`);
|
|
70
|
+
const dirs = pack.resolveDirs(packsRoot, String(target));
|
|
71
|
+
if (dirs.length > 1) throw pack.collisionError(String(target), dirs);
|
|
72
|
+
if (dirs.length === 0) throw new Error(`no runbooks found for: ${target}`);
|
|
73
|
+
for (const dir of dirs) {
|
|
74
|
+
const runbooksDir = resolveWithinBase(path.join(dir, 'runbooks'), dir);
|
|
75
|
+
if (!runbooksDir || !fs.existsSync(runbooksDir)) {
|
|
76
|
+
throw new Error(`no runbooks found for: ${target}`);
|
|
77
|
+
}
|
|
78
|
+
for (const entry of fs.readdirSync(runbooksDir, { withFileTypes: true })) {
|
|
79
|
+
if (!entry.isDirectory()) continue;
|
|
80
|
+
const confined = resolveWithinBase(path.join(runbooksDir, entry.name, 'SKILL.md'), dir);
|
|
81
|
+
if (confined && fs.existsSync(confined)) results.push(lintFile(confined));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const ok = results.every((r) => r.missing.length === 0);
|
|
87
|
+
return { ok, results };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// find(itemId) -> the runbook for itemId in the FIRST enabled pack that carries
|
|
91
|
+
// it, or null. READ-ONLY by construction: no writes, no scope decisions — an
|
|
92
|
+
// unknown ID resolves to nothing and changes nothing (SC4). Every candidate is
|
|
93
|
+
// resolved through pack's multi-root resolver (31-01: user-root packs work;
|
|
94
|
+
// collision -> refuse naming both paths) and confined to the pack's own dir via
|
|
95
|
+
// resolveWithinBase (T-11-01: a traversal ID -> null), item frontmatter must
|
|
96
|
+
// match (defensive mismatch -> skip), and a clean hit is lint-gated (T-11-02:
|
|
97
|
+
// a missing-part runbook throws, never half-runs).
|
|
98
|
+
function find(itemId, { engagementDir, packsRoot } = {}) {
|
|
99
|
+
for (const slug of pack.enabled(engagementDir)) {
|
|
100
|
+
let dirs = [];
|
|
101
|
+
try {
|
|
102
|
+
dirs = pack.resolveDirs(packsRoot, slug);
|
|
103
|
+
} catch {
|
|
104
|
+
continue; // unreadable root -> this pack contributes nothing (fail-closed)
|
|
105
|
+
}
|
|
106
|
+
if (dirs.length > 1) throw pack.collisionError(slug, dirs);
|
|
107
|
+
for (const dir of dirs) {
|
|
108
|
+
const candidate = path.join(dir, 'runbooks', String(itemId), 'SKILL.md');
|
|
109
|
+
const confined = resolveWithinBase(candidate, dir);
|
|
110
|
+
if (!confined || !fs.existsSync(confined)) continue;
|
|
111
|
+
let data = {};
|
|
112
|
+
try { data = fm.parse(fs.readFileSync(confined, 'utf8')).data || {}; } catch { data = {}; }
|
|
113
|
+
if (data.item !== itemId) continue; // defensive: dir name vs declared item mismatch
|
|
114
|
+
const { missing } = lintFile(confined);
|
|
115
|
+
if (missing.length) {
|
|
116
|
+
throw new Error(`runbook for ${itemId} is incomplete — ${confined}: missing ${missing.join(', ')}`);
|
|
117
|
+
}
|
|
118
|
+
return { path: confined, pack: slug, item: itemId };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { REQUIRED_KEYS, REQUIRED_SECTIONS, lint, lintFile, collect, find };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* sarif.cjs — SARIF 2.1.0 export of the findings register (ADR-013).
|
|
4
|
+
* One direction here: PENSIEVE -> SARIF (pipelines: GitHub code scanning,
|
|
5
|
+
* GitLab, DefectDojo…). The reverse (tool-native SARIF -> draft findings)
|
|
6
|
+
* is the M1 ingest lane.
|
|
7
|
+
*
|
|
8
|
+
* Mapping:
|
|
9
|
+
* finding.id -> rule.id + result.ruleId
|
|
10
|
+
* severity -> level: Critical/High=error, Medium=warning, Low=note, None=none
|
|
11
|
+
* cwe -> rule relationships (CWE taxonomy reference)
|
|
12
|
+
* cvss vector+score -> rule properties + result fingerprint
|
|
13
|
+
* evidence hashes -> partialFingerprints (integrity anchor)
|
|
14
|
+
* Only validated findings are exported by default (the register gate holds).
|
|
15
|
+
*
|
|
16
|
+
* Ingest (parseSarif): tool-native SARIF -> DRAFT finding inputs. Ingest is
|
|
17
|
+
* NOT a verdict: imported rows land as drafts and face the same independent
|
|
18
|
+
* replay gate as everything else (ADR-013). Provenance (tool name) is kept
|
|
19
|
+
* in the summary; rows without a CVSS vector get an unscored placeholder so
|
|
20
|
+
* the register stays well-formed — the validator assigns the real vector.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const UNSCORED_VECTOR = 'CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:N'; // 0.0 None
|
|
24
|
+
|
|
25
|
+
/** rule map id -> {title, cwe, cvss_vector} for one run */
|
|
26
|
+
function ruleIndex(run) {
|
|
27
|
+
const rules = run?.tool?.driver?.rules || [];
|
|
28
|
+
const idx = new Map();
|
|
29
|
+
for (const r of rules) {
|
|
30
|
+
const rel = (r.relationships || [])
|
|
31
|
+
.map((x) => /CWE-(\d+)/.exec(x?.target?.id || '')?.[0])
|
|
32
|
+
.find(Boolean);
|
|
33
|
+
idx.set(r.id, {
|
|
34
|
+
title: r.shortDescription?.text || r.name || null,
|
|
35
|
+
cwe: r.properties?.cwe || rel || null,
|
|
36
|
+
cvss_vector: r.properties?.cvss_vector || null,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return idx;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const SKIP_KINDS = new Set(['pass', 'notApplicable', 'informational']);
|
|
43
|
+
|
|
44
|
+
function parseSarif(log) {
|
|
45
|
+
if (!log || typeof log !== 'object' || !Array.isArray(log.runs)) {
|
|
46
|
+
throw new Error('not a SARIF log (missing runs[])');
|
|
47
|
+
}
|
|
48
|
+
const out = [];
|
|
49
|
+
for (const run of log.runs) {
|
|
50
|
+
const tool = run?.tool?.driver?.name || 'unknown-tool';
|
|
51
|
+
const idx = ruleIndex(run);
|
|
52
|
+
for (const res of run.results || []) {
|
|
53
|
+
const kind = res.kind || 'fail'; // spec default
|
|
54
|
+
if (SKIP_KINDS.has(kind)) continue;
|
|
55
|
+
const rule = res.ruleId ? idx.get(res.ruleId) : null;
|
|
56
|
+
const message = res.message?.text || '';
|
|
57
|
+
const title = (rule?.title || message || res.ruleId || 'untitled').slice(0, 200);
|
|
58
|
+
out.push({
|
|
59
|
+
title,
|
|
60
|
+
cwe: rule?.cwe || null,
|
|
61
|
+
cvss_vector: rule?.cvss_vector || UNSCORED_VECTOR,
|
|
62
|
+
summary: `${message}${res.ruleId ? ` [${res.ruleId}]` : ''} — imported from ${tool} via SARIF; replay required (ingest is not a verdict)`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = { buildSarif, levelFor, parseSarif, UNSCORED_VECTOR };
|
|
70
|
+
|
|
71
|
+
function levelFor(severity) {
|
|
72
|
+
switch (severity) {
|
|
73
|
+
case 'Critical':
|
|
74
|
+
case 'High': return 'error';
|
|
75
|
+
case 'Medium': return 'warning';
|
|
76
|
+
case 'Low': return 'note';
|
|
77
|
+
default: return 'none';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function cweNumber(cwe) {
|
|
82
|
+
const m = /CWE-(\d+)/.exec(cwe || '');
|
|
83
|
+
return m ? parseInt(m[1], 10) : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function ruleFor(f) {
|
|
87
|
+
const n = cweNumber(f.cwe);
|
|
88
|
+
return {
|
|
89
|
+
id: f.id,
|
|
90
|
+
name: String(f.title || f.id).replace(/[^A-Za-z0-9]+/g, ' ').trim().slice(0, 120),
|
|
91
|
+
shortDescription: { text: String(f.title || '').slice(0, 200) },
|
|
92
|
+
fullDescription: { text: `${f.cwe || 'no-cwe'} — CVSS ${f.cvss_score} (${f.severity})` },
|
|
93
|
+
properties: {
|
|
94
|
+
cwe: f.cwe || null,
|
|
95
|
+
cvss_vector: f.cvss_vector,
|
|
96
|
+
cvss_score: f.cvss_score,
|
|
97
|
+
severity: f.severity,
|
|
98
|
+
'problem.severity': levelFor(f.severity) === 'error' ? 'error' : 'warning',
|
|
99
|
+
...(n ? { tags: [`CWE-${n}`, 'security'] } : { tags: ['security'] }),
|
|
100
|
+
},
|
|
101
|
+
...(n ? {
|
|
102
|
+
relationships: [{
|
|
103
|
+
target: {
|
|
104
|
+
id: `CWE-${n}`,
|
|
105
|
+
toolComponent: { name: 'CWE', version: '4.12' },
|
|
106
|
+
},
|
|
107
|
+
kinds: ['superset'],
|
|
108
|
+
}],
|
|
109
|
+
} : {}),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function resultFor(f) {
|
|
114
|
+
return {
|
|
115
|
+
ruleId: f.id,
|
|
116
|
+
level: levelFor(f.severity),
|
|
117
|
+
kind: 'fail',
|
|
118
|
+
message: { text: `${f.title}${f.assets?.length ? ` (assets: ${f.assets.join(', ')})` : ''}` },
|
|
119
|
+
properties: {
|
|
120
|
+
status: f.status,
|
|
121
|
+
assets: f.assets || [],
|
|
122
|
+
evidence: f.evidence || [],
|
|
123
|
+
},
|
|
124
|
+
partialFingerprints: {
|
|
125
|
+
'pensieve/cvss': `${f.cvss_vector}=${f.cvss_score}`,
|
|
126
|
+
'pensieve/finding': String(f.id),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function buildSarif(findingsList, opts = {}) {
|
|
132
|
+
const rows = findingsList.filter((f) => f.status && f.status !== 'draft');
|
|
133
|
+
return {
|
|
134
|
+
version: '2.1.0',
|
|
135
|
+
$schema: 'https://json.schemastore.org/sarif-2.1.0.json',
|
|
136
|
+
runs: [{
|
|
137
|
+
tool: {
|
|
138
|
+
driver: {
|
|
139
|
+
name: 'PENSIEVE',
|
|
140
|
+
version: opts.version || '0.1.0',
|
|
141
|
+
informationUri: 'https://github.com/abdulr7mann/pensieve',
|
|
142
|
+
rules: rows.map(ruleFor),
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
results: rows.map(resultFor),
|
|
146
|
+
properties: {
|
|
147
|
+
engagement: opts.engagement || null,
|
|
148
|
+
generated: new Date().toISOString(),
|
|
149
|
+
note: 'validated findings only; drafts never leave the register',
|
|
150
|
+
},
|
|
151
|
+
}],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|