@cclabsnz/sf-audit 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.
- package/README.md +145 -0
- package/config/queries/soql.json +24 -0
- package/config/queries/tooling.json +28 -0
- package/config/scoring.json +9 -0
- package/lib/api/ApiError.d.ts +6 -0
- package/lib/api/ApiError.js +6 -0
- package/lib/api/RestClient.d.ts +4 -0
- package/lib/api/RestClient.js +2 -0
- package/lib/api/RestClientImpl.d.ts +8 -0
- package/lib/api/RestClientImpl.js +12 -0
- package/lib/api/SoqlClient.d.ts +10 -0
- package/lib/api/SoqlClient.js +2 -0
- package/lib/api/SoqlClientImpl.d.ts +9 -0
- package/lib/api/SoqlClientImpl.js +19 -0
- package/lib/api/ToolingClient.d.ts +5 -0
- package/lib/api/ToolingClient.js +2 -0
- package/lib/api/ToolingClientImpl.d.ts +10 -0
- package/lib/api/ToolingClientImpl.js +26 -0
- package/lib/api/index.d.ts +9 -0
- package/lib/api/index.js +5 -0
- package/lib/checks/CheckEngine.d.ts +11 -0
- package/lib/checks/CheckEngine.js +56 -0
- package/lib/checks/SecurityCheck.d.ts +18 -0
- package/lib/checks/SecurityCheck.js +2 -0
- package/lib/checks/impl/ApexSharingCheck.d.ts +11 -0
- package/lib/checks/impl/ApexSharingCheck.js +108 -0
- package/lib/checks/impl/ApiLimitsCheck.d.ts +10 -0
- package/lib/checks/impl/ApiLimitsCheck.js +65 -0
- package/lib/checks/impl/AuditTrailCheck.d.ts +10 -0
- package/lib/checks/impl/AuditTrailCheck.js +69 -0
- package/lib/checks/impl/CodeSecurityCheck.d.ts +10 -0
- package/lib/checks/impl/CodeSecurityCheck.js +53 -0
- package/lib/checks/impl/ConnectedAppsCheck.d.ts +10 -0
- package/lib/checks/impl/ConnectedAppsCheck.js +48 -0
- package/lib/checks/impl/CustomSettingsCheck.d.ts +10 -0
- package/lib/checks/impl/CustomSettingsCheck.js +59 -0
- package/lib/checks/impl/FieldLevelSecurityCheck.d.ts +10 -0
- package/lib/checks/impl/FieldLevelSecurityCheck.js +149 -0
- package/lib/checks/impl/FlowsWithoutSharingCheck.d.ts +10 -0
- package/lib/checks/impl/FlowsWithoutSharingCheck.js +60 -0
- package/lib/checks/impl/GuestUserAccessCheck.d.ts +11 -0
- package/lib/checks/impl/GuestUserAccessCheck.js +158 -0
- package/lib/checks/impl/HardcodedCredentialsCheck.d.ts +12 -0
- package/lib/checks/impl/HardcodedCredentialsCheck.js +146 -0
- package/lib/checks/impl/HealthCheckCheck.d.ts +11 -0
- package/lib/checks/impl/HealthCheckCheck.js +70 -0
- package/lib/checks/impl/InactiveUsersCheck.d.ts +10 -0
- package/lib/checks/impl/InactiveUsersCheck.js +47 -0
- package/lib/checks/impl/IpRestrictionsCheck.d.ts +10 -0
- package/lib/checks/impl/IpRestrictionsCheck.js +94 -0
- package/lib/checks/impl/LoginSessionCheck.d.ts +10 -0
- package/lib/checks/impl/LoginSessionCheck.js +54 -0
- package/lib/checks/impl/NamedCredentialsCheck.d.ts +11 -0
- package/lib/checks/impl/NamedCredentialsCheck.js +100 -0
- package/lib/checks/impl/PasswordSessionPolicyCheck.d.ts +12 -0
- package/lib/checks/impl/PasswordSessionPolicyCheck.js +100 -0
- package/lib/checks/impl/PermissionsCheck.d.ts +10 -0
- package/lib/checks/impl/PermissionsCheck.js +91 -0
- package/lib/checks/impl/PublicGroupSharingCheck.d.ts +11 -0
- package/lib/checks/impl/PublicGroupSharingCheck.js +68 -0
- package/lib/checks/impl/RemoteSitesCheck.d.ts +11 -0
- package/lib/checks/impl/RemoteSitesCheck.js +69 -0
- package/lib/checks/impl/ScheduledApexCheck.d.ts +10 -0
- package/lib/checks/impl/ScheduledApexCheck.js +72 -0
- package/lib/checks/impl/SharingModelCheck.d.ts +10 -0
- package/lib/checks/impl/SharingModelCheck.js +61 -0
- package/lib/checks/impl/UsersAndAdminsCheck.d.ts +10 -0
- package/lib/checks/impl/UsersAndAdminsCheck.js +85 -0
- package/lib/checks/registry.d.ts +3 -0
- package/lib/checks/registry.js +49 -0
- package/lib/commands/audit/list.d.ts +15 -0
- package/lib/commands/audit/list.js +35 -0
- package/lib/commands/audit/security.d.ts +18 -0
- package/lib/commands/audit/security.js +117 -0
- package/lib/context/AuditCache.d.ts +18 -0
- package/lib/context/AuditCache.js +2 -0
- package/lib/context/AuditContext.d.ts +15 -0
- package/lib/context/AuditContext.js +2 -0
- package/lib/context/OrgInfo.d.ts +9 -0
- package/lib/context/OrgInfo.js +2 -0
- package/lib/context/OrgMetrics.d.ts +20 -0
- package/lib/context/OrgMetrics.js +20 -0
- package/lib/findings/AuditResult.d.ts +15 -0
- package/lib/findings/AuditResult.js +2 -0
- package/lib/findings/Finding.d.ts +16 -0
- package/lib/findings/Finding.js +2 -0
- package/lib/findings/RiskLevel.d.ts +3 -0
- package/lib/findings/RiskLevel.js +2 -0
- package/lib/findings/scoring.d.ts +6 -0
- package/lib/findings/scoring.js +61 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/lib/wire.d.ts +15 -0
- package/lib/lib/wire.js +36 -0
- package/lib/queries/QueryDefinition.d.ts +48 -0
- package/lib/queries/QueryDefinition.js +11 -0
- package/lib/queries/QueryRegistry.d.ts +13 -0
- package/lib/queries/QueryRegistry.js +93 -0
- package/lib/renderers/AuditRenderer.d.ts +7 -0
- package/lib/renderers/AuditRenderer.js +2 -0
- package/lib/renderers/HtmlRenderer.d.ts +8 -0
- package/lib/renderers/HtmlRenderer.js +270 -0
- package/lib/renderers/JsonRenderer.d.ts +8 -0
- package/lib/renderers/JsonRenderer.js +8 -0
- package/lib/renderers/MarkdownRenderer.d.ts +8 -0
- package/lib/renderers/MarkdownRenderer.js +54 -0
- package/messages/audit.security.md +22 -0
- package/package.json +54 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const QueryDefinitionSchema: z.ZodObject<{
|
|
3
|
+
api: z.ZodEnum<["soql", "tooling", "rest"]>;
|
|
4
|
+
soql: z.ZodOptional<z.ZodString>;
|
|
5
|
+
path: z.ZodOptional<z.ZodString>;
|
|
6
|
+
description: z.ZodString;
|
|
7
|
+
fallbackOnError: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
minApiVersion: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
api: "soql" | "tooling" | "rest";
|
|
11
|
+
description: string;
|
|
12
|
+
fallbackOnError: boolean;
|
|
13
|
+
path?: string | undefined;
|
|
14
|
+
soql?: string | undefined;
|
|
15
|
+
minApiVersion?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
api: "soql" | "tooling" | "rest";
|
|
18
|
+
description: string;
|
|
19
|
+
path?: string | undefined;
|
|
20
|
+
soql?: string | undefined;
|
|
21
|
+
fallbackOnError?: boolean | undefined;
|
|
22
|
+
minApiVersion?: string | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
export type QueryDefinition = z.infer<typeof QueryDefinitionSchema>;
|
|
25
|
+
export declare const QueryFileSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
26
|
+
api: z.ZodEnum<["soql", "tooling", "rest"]>;
|
|
27
|
+
soql: z.ZodOptional<z.ZodString>;
|
|
28
|
+
path: z.ZodOptional<z.ZodString>;
|
|
29
|
+
description: z.ZodString;
|
|
30
|
+
fallbackOnError: z.ZodDefault<z.ZodBoolean>;
|
|
31
|
+
minApiVersion: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
api: "soql" | "tooling" | "rest";
|
|
34
|
+
description: string;
|
|
35
|
+
fallbackOnError: boolean;
|
|
36
|
+
path?: string | undefined;
|
|
37
|
+
soql?: string | undefined;
|
|
38
|
+
minApiVersion?: string | undefined;
|
|
39
|
+
}, {
|
|
40
|
+
api: "soql" | "tooling" | "rest";
|
|
41
|
+
description: string;
|
|
42
|
+
path?: string | undefined;
|
|
43
|
+
soql?: string | undefined;
|
|
44
|
+
fallbackOnError?: boolean | undefined;
|
|
45
|
+
minApiVersion?: string | undefined;
|
|
46
|
+
}>>;
|
|
47
|
+
export type QueryFile = z.infer<typeof QueryFileSchema>;
|
|
48
|
+
//# sourceMappingURL=QueryDefinition.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const QueryDefinitionSchema = z.object({
|
|
3
|
+
api: z.enum(['soql', 'tooling', 'rest']),
|
|
4
|
+
soql: z.string().optional(),
|
|
5
|
+
path: z.string().optional(),
|
|
6
|
+
description: z.string(),
|
|
7
|
+
fallbackOnError: z.boolean().default(false),
|
|
8
|
+
minApiVersion: z.string().optional(),
|
|
9
|
+
});
|
|
10
|
+
export const QueryFileSchema = z.record(z.string(), QueryDefinitionSchema);
|
|
11
|
+
//# sourceMappingURL=QueryDefinition.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type QueryDefinition } from './QueryDefinition.js';
|
|
2
|
+
import type { QueryResult } from '../api/SoqlClient.js';
|
|
3
|
+
import type { AuditContext } from '../context/AuditContext.js';
|
|
4
|
+
export declare class QueryRegistry {
|
|
5
|
+
private readonly map;
|
|
6
|
+
private constructor();
|
|
7
|
+
static load(configDir: string): QueryRegistry;
|
|
8
|
+
get(id: string): QueryDefinition;
|
|
9
|
+
execute<T>(id: string, ctx: AuditContext): Promise<T[] | null>;
|
|
10
|
+
executeQuery<T>(id: string, ctx: AuditContext): Promise<QueryResult<T> | null>;
|
|
11
|
+
getAll(): ReadonlyMap<string, QueryDefinition>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=QueryRegistry.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { QueryFileSchema } from './QueryDefinition.js';
|
|
4
|
+
function warnFallback(id, err) {
|
|
5
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
6
|
+
process.stderr.write(`[QueryRegistry] Query '${id}' failed (fallbackOnError): ${msg}\n`);
|
|
7
|
+
}
|
|
8
|
+
export class QueryRegistry {
|
|
9
|
+
map;
|
|
10
|
+
constructor(entries) {
|
|
11
|
+
this.map = entries;
|
|
12
|
+
}
|
|
13
|
+
static load(configDir) {
|
|
14
|
+
const queryDir = path.join(configDir, 'config', 'queries');
|
|
15
|
+
const files = ['soql.json', 'tooling.json'];
|
|
16
|
+
const entries = new Map();
|
|
17
|
+
for (const file of files) {
|
|
18
|
+
const filePath = path.join(queryDir, file);
|
|
19
|
+
let raw;
|
|
20
|
+
try {
|
|
21
|
+
raw = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
throw new Error(`QueryRegistry: failed to read ${filePath}: ${err.message}`);
|
|
25
|
+
}
|
|
26
|
+
const parsed = QueryFileSchema.safeParse(raw);
|
|
27
|
+
if (!parsed.success) {
|
|
28
|
+
throw new Error(`QueryRegistry: invalid schema in ${file}:\n${parsed.error.message}`);
|
|
29
|
+
}
|
|
30
|
+
for (const [key, def] of Object.entries(parsed.data)) {
|
|
31
|
+
if (entries.has(key)) {
|
|
32
|
+
throw new Error(`QueryRegistry: duplicate key '${key}' found in ${file}`);
|
|
33
|
+
}
|
|
34
|
+
entries.set(key, def);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return new QueryRegistry(entries);
|
|
38
|
+
}
|
|
39
|
+
get(id) {
|
|
40
|
+
const def = this.map.get(id);
|
|
41
|
+
if (!def) {
|
|
42
|
+
throw new Error(`QueryRegistry: unknown query key '${id}'`);
|
|
43
|
+
}
|
|
44
|
+
return def;
|
|
45
|
+
}
|
|
46
|
+
async execute(id, ctx) {
|
|
47
|
+
const def = this.get(id);
|
|
48
|
+
try {
|
|
49
|
+
if (def.api === 'soql') {
|
|
50
|
+
if (!def.soql)
|
|
51
|
+
throw new Error(`Query '${id}' has api='soql' but no soql field`);
|
|
52
|
+
return await ctx.soql.queryAll(def.soql);
|
|
53
|
+
}
|
|
54
|
+
if (def.api === 'tooling') {
|
|
55
|
+
if (!def.soql)
|
|
56
|
+
throw new Error(`Query '${id}' has api='tooling' but no soql field`);
|
|
57
|
+
return await ctx.tooling.query(def.soql);
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`QueryRegistry.execute: api='rest' entries cannot be executed here. ` +
|
|
60
|
+
`Use ctx.rest.get() or ctx.tooling.getRecord() directly. Key: '${id}'`);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
if (def.fallbackOnError) {
|
|
64
|
+
warnFallback(id, err);
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async executeQuery(id, ctx) {
|
|
71
|
+
const def = this.get(id);
|
|
72
|
+
if (def.api !== 'soql') {
|
|
73
|
+
throw new Error(`QueryRegistry.executeQuery: query '${id}' must have api='soql'`);
|
|
74
|
+
}
|
|
75
|
+
if (!def.soql) {
|
|
76
|
+
throw new Error(`Query '${id}' has api='soql' but no soql field`);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
return await ctx.soql.query(def.soql);
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
if (def.fallbackOnError) {
|
|
83
|
+
warnFallback(id, err);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
getAll() {
|
|
90
|
+
return this.map;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=QueryRegistry.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuditResult } from '../findings/AuditResult.js';
|
|
2
|
+
import type { AuditRenderer } from './AuditRenderer.js';
|
|
3
|
+
export declare class HtmlRenderer implements AuditRenderer {
|
|
4
|
+
readonly format = "html";
|
|
5
|
+
readonly fileExtension = ".html";
|
|
6
|
+
render(result: AuditResult): string;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=HtmlRenderer.d.ts.map
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
const RISK_COLORS = {
|
|
2
|
+
CRITICAL: '#dc2626',
|
|
3
|
+
HIGH: '#ea580c',
|
|
4
|
+
MEDIUM: '#d97706',
|
|
5
|
+
LOW: '#2563eb',
|
|
6
|
+
INFO: '#64748b',
|
|
7
|
+
};
|
|
8
|
+
const RISK_BG = {
|
|
9
|
+
CRITICAL: 'rgba(220,38,38,0.12)',
|
|
10
|
+
HIGH: 'rgba(234,88,12,0.12)',
|
|
11
|
+
MEDIUM: 'rgba(217,119,6,0.12)',
|
|
12
|
+
LOW: 'rgba(37,99,235,0.12)',
|
|
13
|
+
INFO: 'rgba(100,116,139,0.12)',
|
|
14
|
+
};
|
|
15
|
+
function esc(str) {
|
|
16
|
+
return str
|
|
17
|
+
.replace(/&/g, '&')
|
|
18
|
+
.replace(/</g, '<')
|
|
19
|
+
.replace(/>/g, '>')
|
|
20
|
+
.replace(/"/g, '"');
|
|
21
|
+
}
|
|
22
|
+
export class HtmlRenderer {
|
|
23
|
+
format = 'html';
|
|
24
|
+
fileExtension = '.html';
|
|
25
|
+
render(result) {
|
|
26
|
+
const levels = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'];
|
|
27
|
+
const counts = Object.fromEntries(levels.map((l) => [l, result.findings.filter((f) => f.riskLevel === l).length]));
|
|
28
|
+
const gradeColor = {
|
|
29
|
+
A: '#22c55e', B: '#84cc16', C: '#eab308', D: '#f97316', F: '#ef4444',
|
|
30
|
+
};
|
|
31
|
+
const summaryBadges = levels
|
|
32
|
+
.map((l) => `<span class="badge" style="background:${RISK_COLORS[l]}">${counts[l]} ${l}</span>`)
|
|
33
|
+
.join('');
|
|
34
|
+
const filterButtons = [
|
|
35
|
+
`<button class="filter-btn active" data-filter="all">All (${result.findings.length})</button>`,
|
|
36
|
+
...levels.map((l) => `<button class="filter-btn" data-filter="${l}" style="--accent:${RISK_COLORS[l]}">${l} (${counts[l]})</button>`),
|
|
37
|
+
].join('\n ');
|
|
38
|
+
const findingsHtml = result.findings.length === 0
|
|
39
|
+
? '<p style="color:#64748b;text-align:center;padding:2rem 0">No findings.</p>'
|
|
40
|
+
: result.findings.map((f) => `
|
|
41
|
+
<details class="finding-card" data-risk="${esc(f.riskLevel)}" style="--card-accent:${RISK_COLORS[f.riskLevel]};--card-bg:${RISK_BG[f.riskLevel] ?? 'rgba(100,116,139,0.12)'}">
|
|
42
|
+
<summary class="finding-summary">
|
|
43
|
+
<span class="risk-badge" style="background:${RISK_COLORS[f.riskLevel]}">${esc(f.riskLevel)}</span>
|
|
44
|
+
<span class="finding-title">${esc(f.title)}</span>
|
|
45
|
+
<span class="finding-category">${esc(f.category)}</span>
|
|
46
|
+
<span class="chevron">›</span>
|
|
47
|
+
</summary>
|
|
48
|
+
<div class="finding-body">
|
|
49
|
+
<p class="finding-detail">${esc(f.detail)}</p>
|
|
50
|
+
<div class="remediation-box">
|
|
51
|
+
<strong>Remediation</strong>
|
|
52
|
+
<p>${esc(f.remediation)}</p>
|
|
53
|
+
</div>
|
|
54
|
+
${f.affectedItems?.length ? (() => {
|
|
55
|
+
const hasUrls = f.affectedItems.some((i) => i.url);
|
|
56
|
+
const hasNotes = f.affectedItems.some((i) => i.note);
|
|
57
|
+
const headers = ['Item', ...(hasUrls ? ['Setup Link'] : []), ...(hasNotes ? ['Notes'] : [])];
|
|
58
|
+
const thead = `<tr>${headers.map((h) => `<th>${esc(h)}</th>`).join('')}</tr>`;
|
|
59
|
+
const tbody = f.affectedItems.map((item) => {
|
|
60
|
+
const cells = [
|
|
61
|
+
`<td>${esc(item.label)}</td>`,
|
|
62
|
+
...(hasUrls ? [`<td>${item.url ? `<a href="${esc(item.url)}" target="_blank" rel="noopener">Open ↗</a>` : '—'}</td>`] : []),
|
|
63
|
+
...(hasNotes ? [`<td>${esc(item.note ?? '')}</td>`] : []),
|
|
64
|
+
];
|
|
65
|
+
return `<tr>${cells.join('')}</tr>`;
|
|
66
|
+
}).join('');
|
|
67
|
+
return `<div class="affected-items"><strong>Affected items (${f.affectedItems.length})</strong><table class="affected-table"><thead>${thead}</thead><tbody>${tbody}</tbody></table></div>`;
|
|
68
|
+
})() : ''}
|
|
69
|
+
</div>
|
|
70
|
+
</details>`).join('\n');
|
|
71
|
+
return `<!DOCTYPE html>
|
|
72
|
+
<html lang="en">
|
|
73
|
+
<head>
|
|
74
|
+
<meta charset="UTF-8">
|
|
75
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
76
|
+
<title>SF Security Audit — ${esc(result.orgName)}</title>
|
|
77
|
+
<style>
|
|
78
|
+
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
79
|
+
body {
|
|
80
|
+
font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
|
|
81
|
+
background: #0d1117;
|
|
82
|
+
color: #c9d1d9;
|
|
83
|
+
max-width: 1000px;
|
|
84
|
+
margin: 2rem auto;
|
|
85
|
+
padding: 0 1.25rem 4rem;
|
|
86
|
+
line-height: 1.6;
|
|
87
|
+
}
|
|
88
|
+
/* Header */
|
|
89
|
+
.header { margin-bottom: 2rem; }
|
|
90
|
+
.header h1 { color: #f0f6fc; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.4rem; }
|
|
91
|
+
.meta { font-size: 0.8rem; color: #8b949e; display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
|
|
92
|
+
/* Score card */
|
|
93
|
+
.scorecard {
|
|
94
|
+
background: #161b22;
|
|
95
|
+
border: 1px solid #30363d;
|
|
96
|
+
border-radius: 12px;
|
|
97
|
+
padding: 1.5rem 2rem;
|
|
98
|
+
display: flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
gap: 2rem;
|
|
101
|
+
margin-bottom: 1.5rem;
|
|
102
|
+
flex-wrap: wrap;
|
|
103
|
+
}
|
|
104
|
+
.score-number {
|
|
105
|
+
font-size: 3.5rem;
|
|
106
|
+
font-weight: 800;
|
|
107
|
+
color: #f0f6fc;
|
|
108
|
+
line-height: 1;
|
|
109
|
+
}
|
|
110
|
+
.score-number span { font-size: 1.25rem; color: #8b949e; font-weight: 400; }
|
|
111
|
+
.grade-badge {
|
|
112
|
+
width: 3rem; height: 3rem;
|
|
113
|
+
border-radius: 50%;
|
|
114
|
+
display: flex; align-items: center; justify-content: center;
|
|
115
|
+
font-size: 1.5rem; font-weight: 800;
|
|
116
|
+
color: #fff;
|
|
117
|
+
background: ${gradeColor[result.grade] ?? '#64748b'};
|
|
118
|
+
}
|
|
119
|
+
.summary-badges { display: flex; flex-wrap: wrap; gap: 0.5rem; }
|
|
120
|
+
.badge {
|
|
121
|
+
padding: 0.2rem 0.65rem;
|
|
122
|
+
border-radius: 20px;
|
|
123
|
+
font-size: 0.75rem;
|
|
124
|
+
font-weight: 700;
|
|
125
|
+
color: #fff;
|
|
126
|
+
}
|
|
127
|
+
/* Filters */
|
|
128
|
+
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
|
|
129
|
+
.filter-btn {
|
|
130
|
+
padding: 0.35rem 0.9rem;
|
|
131
|
+
border-radius: 20px;
|
|
132
|
+
border: 1px solid #30363d;
|
|
133
|
+
background: #161b22;
|
|
134
|
+
color: #8b949e;
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
font-size: 0.8rem;
|
|
137
|
+
font-weight: 600;
|
|
138
|
+
transition: all 0.15s;
|
|
139
|
+
}
|
|
140
|
+
.filter-btn:hover { border-color: #58a6ff; color: #58a6ff; }
|
|
141
|
+
.filter-btn.active {
|
|
142
|
+
background: var(--accent, #238636);
|
|
143
|
+
border-color: var(--accent, #238636);
|
|
144
|
+
color: #fff;
|
|
145
|
+
}
|
|
146
|
+
/* Finding cards */
|
|
147
|
+
.finding-card {
|
|
148
|
+
background: var(--card-bg);
|
|
149
|
+
border: 1px solid #30363d;
|
|
150
|
+
border-left: 3px solid var(--card-accent);
|
|
151
|
+
border-radius: 8px;
|
|
152
|
+
margin-bottom: 0.6rem;
|
|
153
|
+
overflow: hidden;
|
|
154
|
+
}
|
|
155
|
+
.finding-card[open] { border-color: var(--card-accent); }
|
|
156
|
+
.finding-summary {
|
|
157
|
+
display: flex;
|
|
158
|
+
align-items: center;
|
|
159
|
+
gap: 0.75rem;
|
|
160
|
+
padding: 0.75rem 1rem;
|
|
161
|
+
cursor: pointer;
|
|
162
|
+
list-style: none;
|
|
163
|
+
user-select: none;
|
|
164
|
+
}
|
|
165
|
+
.finding-summary::-webkit-details-marker { display: none; }
|
|
166
|
+
.finding-summary:hover { background: rgba(255,255,255,0.03); }
|
|
167
|
+
.risk-badge {
|
|
168
|
+
flex-shrink: 0;
|
|
169
|
+
padding: 0.15rem 0.6rem;
|
|
170
|
+
border-radius: 4px;
|
|
171
|
+
font-size: 0.7rem;
|
|
172
|
+
font-weight: 800;
|
|
173
|
+
color: #fff;
|
|
174
|
+
letter-spacing: 0.04em;
|
|
175
|
+
}
|
|
176
|
+
.finding-title { flex: 1; font-weight: 600; color: #e6edf3; font-size: 0.9rem; }
|
|
177
|
+
.finding-category { font-size: 0.75rem; color: #8b949e; white-space: nowrap; }
|
|
178
|
+
.chevron { color: #8b949e; font-size: 1.2rem; transition: transform 0.2s; }
|
|
179
|
+
.finding-card[open] .chevron { transform: rotate(90deg); }
|
|
180
|
+
.finding-body { padding: 0 1rem 1rem 1rem; border-top: 1px solid #30363d; }
|
|
181
|
+
.finding-detail { color: #c9d1d9; font-size: 0.875rem; padding: 0.75rem 0 0.5rem; }
|
|
182
|
+
.remediation-box {
|
|
183
|
+
background: rgba(35,134,54,0.1);
|
|
184
|
+
border: 1px solid rgba(35,134,54,0.3);
|
|
185
|
+
border-radius: 6px;
|
|
186
|
+
padding: 0.75rem;
|
|
187
|
+
margin-top: 0.5rem;
|
|
188
|
+
font-size: 0.85rem;
|
|
189
|
+
}
|
|
190
|
+
.remediation-box strong { color: #3fb950; display: block; margin-bottom: 0.25rem; }
|
|
191
|
+
.affected-items {
|
|
192
|
+
margin-top: 0.75rem;
|
|
193
|
+
font-size: 0.82rem;
|
|
194
|
+
}
|
|
195
|
+
.affected-items strong { color: #c9d1d9; display: block; margin-bottom: 0.5rem; }
|
|
196
|
+
.affected-table {
|
|
197
|
+
width: 100%;
|
|
198
|
+
border-collapse: collapse;
|
|
199
|
+
font-size: 0.8rem;
|
|
200
|
+
font-family: 'Menlo', 'Consolas', monospace;
|
|
201
|
+
}
|
|
202
|
+
.affected-table th {
|
|
203
|
+
background: #1c2128;
|
|
204
|
+
color: #8b949e;
|
|
205
|
+
text-align: left;
|
|
206
|
+
padding: 0.4rem 0.6rem;
|
|
207
|
+
border-bottom: 1px solid #30363d;
|
|
208
|
+
font-weight: 600;
|
|
209
|
+
white-space: nowrap;
|
|
210
|
+
}
|
|
211
|
+
.affected-table td {
|
|
212
|
+
padding: 0.35rem 0.6rem;
|
|
213
|
+
border-bottom: 1px solid #21262d;
|
|
214
|
+
color: #c9d1d9;
|
|
215
|
+
vertical-align: top;
|
|
216
|
+
word-break: break-word;
|
|
217
|
+
}
|
|
218
|
+
.affected-table tr:last-child td { border-bottom: none; }
|
|
219
|
+
.affected-table a { color: #58a6ff; text-decoration: none; white-space: nowrap; }
|
|
220
|
+
.affected-table a:hover { text-decoration: underline; }
|
|
221
|
+
/* Empty state */
|
|
222
|
+
.no-findings { color: #8b949e; text-align: center; padding: 3rem 0; }
|
|
223
|
+
</style>
|
|
224
|
+
</head>
|
|
225
|
+
<body>
|
|
226
|
+
<div class="header">
|
|
227
|
+
<h1>Salesforce Security Audit</h1>
|
|
228
|
+
<div class="meta">
|
|
229
|
+
<span>Org: <strong style="color:#c9d1d9">${esc(result.orgName)}</strong></span>
|
|
230
|
+
<span>ID: ${esc(result.orgId)}</span>
|
|
231
|
+
<span>Instance: ${esc(result.instance)}</span>
|
|
232
|
+
<span>Type: ${esc(result.orgType)}${result.isSandbox ? ' (Sandbox)' : ''}</span>
|
|
233
|
+
<span>Generated: ${result.generatedAt.toISOString()}</span>
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<div class="scorecard">
|
|
238
|
+
<div class="score-number">${result.healthScore}<span>/100</span></div>
|
|
239
|
+
<div class="grade-badge" title="Grade">${esc(result.grade)}</div>
|
|
240
|
+
<div class="summary-badges">${summaryBadges}</div>
|
|
241
|
+
</div>
|
|
242
|
+
|
|
243
|
+
<div class="filters">
|
|
244
|
+
${filterButtons}
|
|
245
|
+
</div>
|
|
246
|
+
|
|
247
|
+
<div id="findings-list">
|
|
248
|
+
${findingsHtml}
|
|
249
|
+
</div>
|
|
250
|
+
|
|
251
|
+
<script>
|
|
252
|
+
const buttons = document.querySelectorAll('.filter-btn');
|
|
253
|
+
const cards = document.querySelectorAll('.finding-card');
|
|
254
|
+
|
|
255
|
+
buttons.forEach(btn => {
|
|
256
|
+
btn.addEventListener('click', () => {
|
|
257
|
+
buttons.forEach(b => b.classList.remove('active'));
|
|
258
|
+
btn.classList.add('active');
|
|
259
|
+
const filter = btn.dataset.filter;
|
|
260
|
+
cards.forEach(card => {
|
|
261
|
+
card.style.display = (filter === 'all' || card.dataset.risk === filter) ? '' : 'none';
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
</script>
|
|
266
|
+
</body>
|
|
267
|
+
</html>`;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=HtmlRenderer.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuditResult } from '../findings/AuditResult.js';
|
|
2
|
+
import type { AuditRenderer } from './AuditRenderer.js';
|
|
3
|
+
export declare class JsonRenderer implements AuditRenderer {
|
|
4
|
+
readonly format = "json";
|
|
5
|
+
readonly fileExtension = ".json";
|
|
6
|
+
render(result: AuditResult): string;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=JsonRenderer.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuditResult } from '../findings/AuditResult.js';
|
|
2
|
+
import type { AuditRenderer } from './AuditRenderer.js';
|
|
3
|
+
export declare class MarkdownRenderer implements AuditRenderer {
|
|
4
|
+
readonly format = "md";
|
|
5
|
+
readonly fileExtension = ".md";
|
|
6
|
+
render(result: AuditResult): string;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=MarkdownRenderer.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function escapeMdCell(s) {
|
|
2
|
+
return s.replace(/\|/g, '\\|').replace(/\n/g, ' ');
|
|
3
|
+
}
|
|
4
|
+
export class MarkdownRenderer {
|
|
5
|
+
format = 'md';
|
|
6
|
+
fileExtension = '.md';
|
|
7
|
+
render(result) {
|
|
8
|
+
const lines = [];
|
|
9
|
+
lines.push(`# Salesforce Security Audit Report`);
|
|
10
|
+
lines.push(`**Org:** ${result.orgName} (${result.orgId})`);
|
|
11
|
+
lines.push(`**Generated:** ${result.generatedAt.toISOString()}`);
|
|
12
|
+
lines.push(`**Instance:** ${result.instance} | **Type:** ${result.orgType}${result.isSandbox ? ' (Sandbox)' : ''}`);
|
|
13
|
+
lines.push(`**Health Score:** ${result.healthScore}/100 | **Grade:** ${result.grade}`);
|
|
14
|
+
lines.push('');
|
|
15
|
+
lines.push(`## Findings (${result.findings.length})`);
|
|
16
|
+
lines.push('');
|
|
17
|
+
if (result.findings.length === 0) {
|
|
18
|
+
lines.push('_No findings._');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
for (const f of result.findings) {
|
|
22
|
+
lines.push(`### [${f.riskLevel}] ${f.title}`);
|
|
23
|
+
lines.push(`**Category:** ${f.category}`);
|
|
24
|
+
lines.push('');
|
|
25
|
+
lines.push(f.detail);
|
|
26
|
+
lines.push('');
|
|
27
|
+
lines.push(`**Remediation:** ${f.remediation}`);
|
|
28
|
+
if (f.affectedItems?.length) {
|
|
29
|
+
const hasUrls = f.affectedItems.some((i) => i.url);
|
|
30
|
+
const hasNotes = f.affectedItems.some((i) => i.note);
|
|
31
|
+
const headers = ['Item', ...(hasUrls ? ['Setup Link'] : []), ...(hasNotes ? ['Notes'] : [])];
|
|
32
|
+
lines.push('');
|
|
33
|
+
lines.push(`**Affected items (${f.affectedItems.length}):**`);
|
|
34
|
+
lines.push('');
|
|
35
|
+
lines.push(`| ${headers.join(' | ')} |`);
|
|
36
|
+
lines.push(`| ${headers.map(() => '---').join(' | ')} |`);
|
|
37
|
+
for (const item of f.affectedItems) {
|
|
38
|
+
const cells = [
|
|
39
|
+
escapeMdCell(item.label),
|
|
40
|
+
...(hasUrls ? [item.url ? `[Open ↗](${item.url})` : '—'] : []),
|
|
41
|
+
...(hasNotes ? [escapeMdCell(item.note ?? '')] : []),
|
|
42
|
+
];
|
|
43
|
+
lines.push(`| ${cells.join(' | ')} |`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
lines.push('');
|
|
47
|
+
lines.push('---');
|
|
48
|
+
lines.push('');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return lines.join('\n');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=MarkdownRenderer.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Summary
|
|
2
|
+
|
|
3
|
+
Run a comprehensive security audit against a Salesforce org.
|
|
4
|
+
|
|
5
|
+
# Flags
|
|
6
|
+
|
|
7
|
+
## target-org
|
|
8
|
+
|
|
9
|
+
The org to audit. Must be authenticated via `sf org login`.
|
|
10
|
+
|
|
11
|
+
## format
|
|
12
|
+
|
|
13
|
+
Output format: html (default), md, or json.
|
|
14
|
+
|
|
15
|
+
## output
|
|
16
|
+
|
|
17
|
+
Directory to write the report file. Defaults to the current directory.
|
|
18
|
+
|
|
19
|
+
## fail-on
|
|
20
|
+
|
|
21
|
+
Exit with code 1 if any finding is at or above this severity level.
|
|
22
|
+
Options: CRITICAL, HIGH, MEDIUM, LOW
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cclabsnz/sf-audit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CloudCounsel Salesforce Security Audit — native sf plugin",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc -p tsconfig.json",
|
|
9
|
+
"test": "node --experimental-vm-modules node_modules/.bin/jest --passWithNoTests",
|
|
10
|
+
"test:unit": "node --experimental-vm-modules node_modules/.bin/jest test/unit --passWithNoTests",
|
|
11
|
+
"prepack": "npm run build",
|
|
12
|
+
"clean": "rm -rf lib"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@oclif/core": "^4",
|
|
16
|
+
"@salesforce/core": "^8",
|
|
17
|
+
"@salesforce/sf-plugins-core": "^12",
|
|
18
|
+
"zod": "^3"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/jest": "^29",
|
|
22
|
+
"@types/node": "^22",
|
|
23
|
+
"jest": "^29",
|
|
24
|
+
"ts-jest": "^29",
|
|
25
|
+
"ts-node": "^10.9.2",
|
|
26
|
+
"typescript": "^5"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/cclabsnz/sf-audit-plugin.git"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18.0.0"
|
|
34
|
+
},
|
|
35
|
+
"oclif": {
|
|
36
|
+
"bin": "sf",
|
|
37
|
+
"dirname": "sf",
|
|
38
|
+
"commands": "./lib/commands",
|
|
39
|
+
"pluginType": "jit",
|
|
40
|
+
"flexibleTaxonomy": true,
|
|
41
|
+
"devPlugins": [],
|
|
42
|
+
"topics": {
|
|
43
|
+
"audit": {
|
|
44
|
+
"description": "Salesforce security audit commands"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"files": [
|
|
49
|
+
"/lib",
|
|
50
|
+
"/messages",
|
|
51
|
+
"/config",
|
|
52
|
+
"!/lib/**/*.map"
|
|
53
|
+
]
|
|
54
|
+
}
|