@cclabsnz/sf-audit 1.21.1 → 1.22.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 +18 -0
- package/lib/commands/audit/security.js +1 -1
- package/lib/renderers/ClientReportRenderer.d.ts +21 -11
- package/lib/renderers/ClientReportRenderer.js +701 -182
- package/lib/renderers/deckFonts.d.ts +7 -0
- package/lib/renderers/deckFonts.js +29 -0
- package/lib/report/ActionPlan.d.ts +42 -0
- package/lib/report/ActionPlan.js +99 -0
- package/lib/report/AttackJourney.d.ts +18 -0
- package/lib/report/AttackJourney.js +31 -0
- package/package.json +3 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source Serif 4 (headlines) and Source Sans 3 (text) for the executive deck, embedded as data URIs
|
|
3
|
+
* so the report never fetches a font. Read from the pinned @fontsource-variable packages, like the
|
|
4
|
+
* Chart.js bundle, so the versions stay visible to `pnpm audit` and Dependabot.
|
|
5
|
+
*/
|
|
6
|
+
export declare function deckFontFaceCss(): string;
|
|
7
|
+
//# sourceMappingURL=deckFonts.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
const requireFrom = createRequire(import.meta.url);
|
|
4
|
+
let cached = null;
|
|
5
|
+
// Latin plus latin-ext, so macron vowels in NZ names (ā, ē, ī, ō, ū) stay in the face.
|
|
6
|
+
const LATIN = 'U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD';
|
|
7
|
+
const LATIN_EXT = 'U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF';
|
|
8
|
+
function face(family, file, descriptors, range) {
|
|
9
|
+
const data = readFileSync(requireFrom.resolve(file)).toString('base64');
|
|
10
|
+
return `@font-face{font-family:'${family}';font-style:normal;${descriptors}font-display:swap;src:url(data:font/woff2;base64,${data}) format('woff2');unicode-range:${range};}`;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Source Serif 4 (headlines) and Source Sans 3 (text) for the executive deck, embedded as data URIs
|
|
14
|
+
* so the report never fetches a font. Read from the pinned @fontsource-variable packages, like the
|
|
15
|
+
* Chart.js bundle, so the versions stay visible to `pnpm audit` and Dependabot.
|
|
16
|
+
*/
|
|
17
|
+
export function deckFontFaceCss() {
|
|
18
|
+
if (cached !== null)
|
|
19
|
+
return cached;
|
|
20
|
+
cached = ['latin', 'latin-ext'].flatMap((sub) => {
|
|
21
|
+
const range = sub === 'latin' ? LATIN : LATIN_EXT;
|
|
22
|
+
return [
|
|
23
|
+
face('Source Serif 4', `@fontsource-variable/source-serif-4/files/source-serif-4-${sub}-wght-normal.woff2`, 'font-weight:200 900;', range),
|
|
24
|
+
face('Source Sans 3', `@fontsource-variable/source-sans-3/files/source-sans-3-${sub}-wght-normal.woff2`, 'font-weight:200 900;', range),
|
|
25
|
+
];
|
|
26
|
+
}).join('\n');
|
|
27
|
+
return cached;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=deckFonts.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { RiskLevel } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { Finding } from '../findings/Finding.js';
|
|
3
|
+
import type { AttackChain } from '../chains/AttackChain.js';
|
|
4
|
+
import { type CheckMeta } from '../findings/CheckMeta.js';
|
|
5
|
+
type Effort = CheckMeta['effort'];
|
|
6
|
+
/** One thing to do, with everything it fixes. The executive report's plan is a list of these. */
|
|
7
|
+
export interface PlannedAction {
|
|
8
|
+
/** What to do, as an instruction. */
|
|
9
|
+
title: string;
|
|
10
|
+
/** The specifics, when the instruction names them after a colon ("Close X: A, B and C"). */
|
|
11
|
+
detail?: string;
|
|
12
|
+
/** Why it matters, in one sentence. */
|
|
13
|
+
why: string;
|
|
14
|
+
/** The open findings this action closes. */
|
|
15
|
+
fixes: Finding[];
|
|
16
|
+
/** Indexes into the chains passed in, of the named chains this action breaks: it closes every finding of their break point. */
|
|
17
|
+
breaks: number[];
|
|
18
|
+
/**
|
|
19
|
+
* Named chains whose break point this action works on but cannot finish, because part of the break
|
|
20
|
+
* point is waived or already passed: fixing the open part leaves the chain standing.
|
|
21
|
+
*/
|
|
22
|
+
weakens: number[];
|
|
23
|
+
/** Indexes of chains its findings take part in without being the break point. */
|
|
24
|
+
inChains: number[];
|
|
25
|
+
severity: RiskLevel;
|
|
26
|
+
effort: Effort;
|
|
27
|
+
/** 1 = start this week, 2 = this month, 3 = this quarter. */
|
|
28
|
+
wave: 1 | 2 | 3;
|
|
29
|
+
/** Relative weight of the exposure it removes; used to rank and to place it on the matrix. */
|
|
30
|
+
risk: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Turn findings and attack chains into a ranked plan. Each named chain's break point becomes one
|
|
34
|
+
* action (chains sharing a break point share the action); every other open CRITICAL or HIGH finding
|
|
35
|
+
* becomes an action per check. MEDIUM and LOW fixes stay in the roadmap.
|
|
36
|
+
*
|
|
37
|
+
* Wave 1 is anything that breaks a CRITICAL chain or closes a CRITICAL finding; otherwise weeks of
|
|
38
|
+
* work is wave 3 and the rest wave 2. Within a wave, the most risk removed comes first.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildActionPlan(findings: Finding[], chains: AttackChain[]): PlannedAction[];
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=ActionPlan.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getCheckMeta } from '../findings/CheckMeta.js';
|
|
2
|
+
const RANK = { CRITICAL: 0, HIGH: 1, MEDIUM: 2, LOW: 3, INFO: 4 };
|
|
3
|
+
const WEIGHT = { CRITICAL: 10, HIGH: 7, MEDIUM: 4, LOW: 1, INFO: 0 };
|
|
4
|
+
const EFFORT_RANK = { quick: 0, moderate: 1, project: 2 };
|
|
5
|
+
const isOpen = (f) => !f.passed && !f.inconclusive && !f.notAssessed && !f.waived;
|
|
6
|
+
const worst = (levels) => levels.reduce((a, b) => (RANK[b] < RANK[a] ? b : a), 'INFO');
|
|
7
|
+
const effortOf = (f) => (f.checkId && getCheckMeta(f.checkId)?.effort) || 'moderate';
|
|
8
|
+
/** The first sentence of a remediation, which the checks write as an instruction. Abbreviations do not end it. */
|
|
9
|
+
function firstSentence(text) {
|
|
10
|
+
const m = /^(.+?(?<!\b(?:e\.g|i\.e|etc|vs))[.!?])(\s+(?=[A-Z"(])|$)/s.exec(text.trim());
|
|
11
|
+
return (m ? m[1] : text.trim()).replace(/\s+/g, ' ');
|
|
12
|
+
}
|
|
13
|
+
/** "Do X: the specifics" splits into a short instruction and its specifics. */
|
|
14
|
+
function splitInstruction(text) {
|
|
15
|
+
const i = text.indexOf(': ');
|
|
16
|
+
// A navigation path ("Setup → X: do Y") or a URL before the colon is not an instruction to lead with.
|
|
17
|
+
if (i < 12 || i > 90 || /→|:\/\//.test(text.slice(0, i)))
|
|
18
|
+
return { title: text };
|
|
19
|
+
const detail = text.slice(i + 2).trim();
|
|
20
|
+
return { title: text.slice(0, i).trim(), detail: detail.charAt(0).toUpperCase() + detail.slice(1) };
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Turn findings and attack chains into a ranked plan. Each named chain's break point becomes one
|
|
24
|
+
* action (chains sharing a break point share the action); every other open CRITICAL or HIGH finding
|
|
25
|
+
* becomes an action per check. MEDIUM and LOW fixes stay in the roadmap.
|
|
26
|
+
*
|
|
27
|
+
* Wave 1 is anything that breaks a CRITICAL chain or closes a CRITICAL finding; otherwise weeks of
|
|
28
|
+
* work is wave 3 and the rest wave 2. Within a wave, the most risk removed comes first.
|
|
29
|
+
*/
|
|
30
|
+
export function buildActionPlan(findings, chains) {
|
|
31
|
+
const open = findings.filter(isOpen);
|
|
32
|
+
const openById = new Map();
|
|
33
|
+
for (const f of open)
|
|
34
|
+
if (!openById.has(f.id))
|
|
35
|
+
openById.set(f.id, f);
|
|
36
|
+
const chainsOf = new Map();
|
|
37
|
+
chains.forEach((c, i) => {
|
|
38
|
+
for (const s of c.steps)
|
|
39
|
+
chainsOf.set(s.findingId, [...new Set([...(chainsOf.get(s.findingId) ?? []), i])]);
|
|
40
|
+
});
|
|
41
|
+
const actions = [];
|
|
42
|
+
const byBreakPoint = new Map();
|
|
43
|
+
chains.forEach((c, i) => {
|
|
44
|
+
if (!c.abuseCase)
|
|
45
|
+
return;
|
|
46
|
+
const breakIds = [...new Set(c.steps.filter((s) => s.breaksChain).map((s) => s.findingId))];
|
|
47
|
+
const fixes = breakIds.map((id) => openById.get(id)).filter((f) => !!f);
|
|
48
|
+
if (fixes.length === 0)
|
|
49
|
+
return;
|
|
50
|
+
// The chain breaks only when every break-point finding is fixed; a waived or passed one stays.
|
|
51
|
+
const complete = fixes.length === breakIds.length;
|
|
52
|
+
const existing = byBreakPoint.get(c.abuseCase.breakPoint);
|
|
53
|
+
if (existing) {
|
|
54
|
+
(complete ? existing.breaks : existing.weakens).push(i);
|
|
55
|
+
for (const f of fixes)
|
|
56
|
+
if (!existing.fixes.includes(f))
|
|
57
|
+
existing.fixes.push(f);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const action = {
|
|
61
|
+
...splitInstruction(c.abuseCase.breakPoint),
|
|
62
|
+
why: `Stops ${c.abuseCase.actor} who wants to ${c.abuseCase.goal}.`,
|
|
63
|
+
fixes, breaks: complete ? [i] : [], weakens: complete ? [] : [i], inChains: [], severity: 'INFO', effort: 'quick', wave: 2, risk: 0,
|
|
64
|
+
};
|
|
65
|
+
byBreakPoint.set(c.abuseCase.breakPoint, action);
|
|
66
|
+
actions.push(action);
|
|
67
|
+
});
|
|
68
|
+
const covered = new Set(actions.flatMap((a) => a.fixes));
|
|
69
|
+
const byCheck = new Map();
|
|
70
|
+
for (const f of open) {
|
|
71
|
+
if (covered.has(f) || (f.riskLevel !== 'CRITICAL' && f.riskLevel !== 'HIGH'))
|
|
72
|
+
continue;
|
|
73
|
+
const key = f.checkId ?? f.id;
|
|
74
|
+
byCheck.set(key, [...(byCheck.get(key) ?? []), f]);
|
|
75
|
+
}
|
|
76
|
+
for (const fixes of byCheck.values()) {
|
|
77
|
+
fixes.sort((a, b) => RANK[a.riskLevel] - RANK[b.riskLevel]);
|
|
78
|
+
const lead = fixes[0];
|
|
79
|
+
actions.push({
|
|
80
|
+
...splitInstruction(firstSentence(lead.remediation)),
|
|
81
|
+
why: (lead.checkId && getCheckMeta(lead.checkId)?.impact) || lead.title,
|
|
82
|
+
fixes, breaks: [], weakens: [], inChains: [], severity: 'INFO', effort: 'quick', wave: 2, risk: 0,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
for (const a of actions) {
|
|
86
|
+
a.title = a.title.replace(/\.$/, '');
|
|
87
|
+
a.why = a.why.charAt(0).toUpperCase() + a.why.slice(1);
|
|
88
|
+
const broken = a.breaks.map((i) => chains[i]);
|
|
89
|
+
a.inChains = [...new Set(a.fixes.flatMap((f) => chainsOf.get(f.id) ?? []))]
|
|
90
|
+
.filter((i) => !a.breaks.includes(i) && !a.weakens.includes(i)).sort((x, y) => x - y);
|
|
91
|
+
a.severity = worst([...a.fixes.map((f) => f.riskLevel), ...[...a.breaks, ...a.weakens].map((i) => chains[i].severity)]);
|
|
92
|
+
a.effort = a.fixes.map(effortOf).reduce((x, y) => (EFFORT_RANK[y] > EFFORT_RANK[x] ? y : x), 'quick');
|
|
93
|
+
// A broken chain counts double: it removes a whole path, not one weakness.
|
|
94
|
+
a.risk = a.fixes.reduce((n, f) => n + WEIGHT[f.riskLevel], 0) + broken.reduce((n, c) => n + 2 * WEIGHT[c.severity], 0);
|
|
95
|
+
a.wave = a.severity === 'CRITICAL' ? 1 : a.effort === 'project' ? 3 : 2;
|
|
96
|
+
}
|
|
97
|
+
return actions.sort((a, b) => a.wave - b.wave || b.risk - a.risk || a.title.localeCompare(b.title));
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=ActionPlan.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Finding } from '../findings/Finding.js';
|
|
2
|
+
import type { AttackChain } from '../chains/AttackChain.js';
|
|
3
|
+
export interface AttackJourney {
|
|
4
|
+
/** Every tactic of the pinned release, in matrix order, with the open findings that enable it. */
|
|
5
|
+
tactics: Array<{
|
|
6
|
+
tactic: string;
|
|
7
|
+
findings: Finding[];
|
|
8
|
+
}>;
|
|
9
|
+
/** Per chain (same order as passed in), the tactic positions its shown techniques reach, ascending. */
|
|
10
|
+
chains: number[][];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Where findings and chains sit on the ATT&CK matrix. A finding counts under every tactic of every
|
|
14
|
+
* technique it carries; a chain step under the earliest tactic of the techniques it shows. Only
|
|
15
|
+
* verified techniques count (RULE-107), and a step showing none adds nothing.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildAttackJourney(findings: readonly Finding[], chains: readonly AttackChain[]): AttackJourney;
|
|
18
|
+
//# sourceMappingURL=AttackJourney.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ATTACK_TACTIC_ORDER, ATTACK_TECHNIQUES, tacticRank } from '../threats/attack.js';
|
|
2
|
+
const isOpen = (f) => !f.passed && !f.inconclusive && !f.notAssessed && !f.waived;
|
|
3
|
+
/**
|
|
4
|
+
* Where findings and chains sit on the ATT&CK matrix. A finding counts under every tactic of every
|
|
5
|
+
* technique it carries; a chain step under the earliest tactic of the techniques it shows. Only
|
|
6
|
+
* verified techniques count (RULE-107), and a step showing none adds nothing.
|
|
7
|
+
*/
|
|
8
|
+
export function buildAttackJourney(findings, chains) {
|
|
9
|
+
const tactics = ATTACK_TACTIC_ORDER.map((tactic) => ({ tactic, findings: [] }));
|
|
10
|
+
for (const f of findings.filter(isOpen)) {
|
|
11
|
+
const hit = new Set();
|
|
12
|
+
for (const id of f.threats?.attack ?? []) {
|
|
13
|
+
for (const t of ATTACK_TECHNIQUES[id]?.tactics ?? [])
|
|
14
|
+
hit.add(ATTACK_TACTIC_ORDER.indexOf(t));
|
|
15
|
+
}
|
|
16
|
+
for (const i of hit)
|
|
17
|
+
if (i >= 0)
|
|
18
|
+
tactics[i].findings.push(f);
|
|
19
|
+
}
|
|
20
|
+
const journeys = chains.map((c) => {
|
|
21
|
+
const reached = new Set();
|
|
22
|
+
for (const s of c.steps) {
|
|
23
|
+
const r = tacticRank(s.techniques);
|
|
24
|
+
if (r !== undefined)
|
|
25
|
+
reached.add(r);
|
|
26
|
+
}
|
|
27
|
+
return [...reached].sort((a, b) => a - b);
|
|
28
|
+
});
|
|
29
|
+
return { tactics, chains: journeys };
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=AttackJourney.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cclabsnz/sf-audit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Read-only Salesforce security audit for the sf CLI: 109 checks, attack-chain correlation, A-F risk grading, compliance mapping, free EventLogFile capture, and Guest User Anomaly investigation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"salesforce",
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@cclabsnz/sf-core": "^0.12.0",
|
|
50
|
+
"@fontsource-variable/source-sans-3": "^5.3.1",
|
|
51
|
+
"@fontsource-variable/source-serif-4": "^5.3.1",
|
|
50
52
|
"@oclif/core": "^5",
|
|
51
53
|
"@salesforce/core": "^9.3.0",
|
|
52
54
|
"@salesforce/sf-plugins-core": "^13",
|