@cclabsnz/sf-audit 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +75 -0
  2. package/lib/api/ToolingClientImpl.js +5 -2
  3. package/lib/chains/AttackChain.d.ts +20 -0
  4. package/lib/chains/AttackChain.js +2 -0
  5. package/lib/chains/Capability.d.ts +7 -0
  6. package/lib/chains/Capability.js +11 -0
  7. package/lib/chains/CapabilityRegistry.d.ts +18 -0
  8. package/lib/chains/CapabilityRegistry.js +53 -0
  9. package/lib/chains/ChainEngine.d.ts +13 -0
  10. package/lib/chains/ChainEngine.js +137 -0
  11. package/lib/chains/namedChains.d.ts +14 -0
  12. package/lib/chains/namedChains.js +99 -0
  13. package/lib/checks/CheckEngine.js +33 -5
  14. package/lib/checks/impl/AnonymousApexAuditCheck.d.ts +10 -0
  15. package/lib/checks/impl/AnonymousApexAuditCheck.js +106 -0
  16. package/lib/checks/impl/ApexCrudFLSCheck.d.ts +11 -0
  17. package/lib/checks/impl/ApexCrudFLSCheck.js +98 -0
  18. package/lib/checks/impl/ApexLoggingCheck.d.ts +11 -0
  19. package/lib/checks/impl/ApexLoggingCheck.js +124 -0
  20. package/lib/checks/impl/ApexRestEndpointCheck.d.ts +11 -0
  21. package/lib/checks/impl/ApexRestEndpointCheck.js +94 -0
  22. package/lib/checks/impl/ApexSharingCheck.js +29 -0
  23. package/lib/checks/impl/ApiClientPermissionCheck.d.ts +10 -0
  24. package/lib/checks/impl/ApiClientPermissionCheck.js +59 -0
  25. package/lib/checks/impl/AuditTrailCheck.js +29 -0
  26. package/lib/checks/impl/CertificateExpiryCheck.d.ts +10 -0
  27. package/lib/checks/impl/CertificateExpiryCheck.js +123 -0
  28. package/lib/checks/impl/CodeSecurityCheck.d.ts +2 -1
  29. package/lib/checks/impl/CodeSecurityCheck.js +46 -6
  30. package/lib/checks/impl/ConnectedAppInactivityCheck.d.ts +11 -0
  31. package/lib/checks/impl/ConnectedAppInactivityCheck.js +86 -0
  32. package/lib/checks/impl/ConnectedAppScopeCheck.d.ts +10 -0
  33. package/lib/checks/impl/ConnectedAppScopeCheck.js +125 -0
  34. package/lib/checks/impl/ConnectedAppsCheck.d.ts +1 -0
  35. package/lib/checks/impl/ConnectedAppsCheck.js +37 -2
  36. package/lib/checks/impl/ContentLinksCheck.d.ts +10 -0
  37. package/lib/checks/impl/ContentLinksCheck.js +115 -0
  38. package/lib/checks/impl/CorsAllowlistCheck.d.ts +10 -0
  39. package/lib/checks/impl/CorsAllowlistCheck.js +80 -0
  40. package/lib/checks/impl/CspTrustedSitesCheck.d.ts +10 -0
  41. package/lib/checks/impl/CspTrustedSitesCheck.js +55 -0
  42. package/lib/checks/impl/CustomLabelsCredentialCheck.d.ts +10 -0
  43. package/lib/checks/impl/CustomLabelsCredentialCheck.js +97 -0
  44. package/lib/checks/impl/DataClassificationCheck.d.ts +10 -0
  45. package/lib/checks/impl/DataClassificationCheck.js +112 -0
  46. package/lib/checks/impl/DebugLogAccessCheck.d.ts +10 -0
  47. package/lib/checks/impl/DebugLogAccessCheck.js +81 -0
  48. package/lib/checks/impl/DeploymentIdentityCheck.d.ts +11 -0
  49. package/lib/checks/impl/DeploymentIdentityCheck.js +144 -0
  50. package/lib/checks/impl/EnhancedDomainsCheck.d.ts +10 -0
  51. package/lib/checks/impl/EnhancedDomainsCheck.js +84 -0
  52. package/lib/checks/impl/EscalationPermsCheck.d.ts +10 -0
  53. package/lib/checks/impl/EscalationPermsCheck.js +77 -0
  54. package/lib/checks/impl/EventMonitoringCheck.d.ts +11 -0
  55. package/lib/checks/impl/EventMonitoringCheck.js +84 -0
  56. package/lib/checks/impl/ExperienceCloudSiteCheck.d.ts +10 -0
  57. package/lib/checks/impl/ExperienceCloudSiteCheck.js +91 -0
  58. package/lib/checks/impl/FailedLoginCheck.d.ts +10 -0
  59. package/lib/checks/impl/FailedLoginCheck.js +122 -0
  60. package/lib/checks/impl/FieldHistoryTrackingCheck.d.ts +10 -0
  61. package/lib/checks/impl/FieldHistoryTrackingCheck.js +70 -0
  62. package/lib/checks/impl/FieldLevelSecurityCheck.js +28 -18
  63. package/lib/checks/impl/GuestExecutableApexCheck.d.ts +11 -0
  64. package/lib/checks/impl/GuestExecutableApexCheck.js +93 -0
  65. package/lib/checks/impl/GuestUserAccessCheck.js +74 -66
  66. package/lib/checks/impl/HardcodedCredentialsCheck.js +2 -2
  67. package/lib/checks/impl/HighAssuranceSessionCheck.d.ts +10 -0
  68. package/lib/checks/impl/HighAssuranceSessionCheck.js +103 -0
  69. package/lib/checks/impl/InactiveUsersCheck.js +38 -19
  70. package/lib/checks/impl/InstalledPackagesCheck.d.ts +10 -0
  71. package/lib/checks/impl/InstalledPackagesCheck.js +94 -0
  72. package/lib/checks/impl/IntegrationUsersCheck.d.ts +10 -0
  73. package/lib/checks/impl/IntegrationUsersCheck.js +108 -0
  74. package/lib/checks/impl/InternalUserMfaCheck.d.ts +10 -0
  75. package/lib/checks/impl/InternalUserMfaCheck.js +81 -0
  76. package/lib/checks/impl/IpRestrictionsCheck.js +86 -23
  77. package/lib/checks/impl/LegacyApiVersionCheck.d.ts +10 -0
  78. package/lib/checks/impl/LegacyApiVersionCheck.js +91 -0
  79. package/lib/checks/impl/MfaEnforcementCheck.d.ts +10 -0
  80. package/lib/checks/impl/MfaEnforcementCheck.js +76 -0
  81. package/lib/checks/impl/MfaMethodStrengthCheck.d.ts +11 -0
  82. package/lib/checks/impl/MfaMethodStrengthCheck.js +116 -0
  83. package/lib/checks/impl/MfaRegistrationCheck.d.ts +11 -0
  84. package/lib/checks/impl/MfaRegistrationCheck.js +95 -0
  85. package/lib/checks/impl/MyDomainLoginPolicyCheck.d.ts +10 -0
  86. package/lib/checks/impl/MyDomainLoginPolicyCheck.js +105 -0
  87. package/lib/checks/impl/NamedCredentialsCheck.js +37 -2
  88. package/lib/checks/impl/PermissionsCheck.js +67 -14
  89. package/lib/checks/impl/PublicGroupSharingCheck.js +20 -9
  90. package/lib/checks/impl/ReleaseUpdatesCheck.d.ts +10 -0
  91. package/lib/checks/impl/ReleaseUpdatesCheck.js +106 -0
  92. package/lib/checks/impl/ReportFolderAccessCheck.d.ts +10 -0
  93. package/lib/checks/impl/ReportFolderAccessCheck.js +54 -0
  94. package/lib/checks/impl/ScheduledApexCheck.d.ts +1 -0
  95. package/lib/checks/impl/ScheduledApexCheck.js +3 -0
  96. package/lib/checks/impl/SharingModelCheck.d.ts +1 -1
  97. package/lib/checks/impl/SharingModelCheck.js +103 -32
  98. package/lib/checks/impl/SiemIntegrationCheck.d.ts +11 -0
  99. package/lib/checks/impl/SiemIntegrationCheck.js +102 -0
  100. package/lib/checks/impl/SsoEnforcementCheck.d.ts +10 -0
  101. package/lib/checks/impl/SsoEnforcementCheck.js +90 -0
  102. package/lib/checks/impl/StandardProfilesCheck.d.ts +10 -0
  103. package/lib/checks/impl/StandardProfilesCheck.js +68 -0
  104. package/lib/checks/impl/TransactionSecurityPolicyCheck.d.ts +10 -0
  105. package/lib/checks/impl/TransactionSecurityPolicyCheck.js +62 -0
  106. package/lib/checks/impl/TrustedIPRangesCheck.d.ts +10 -0
  107. package/lib/checks/impl/TrustedIPRangesCheck.js +106 -0
  108. package/lib/checks/impl/UsersAndAdminsCheck.js +50 -20
  109. package/lib/checks/impl/VisualforceXssCheck.d.ts +11 -0
  110. package/lib/checks/impl/VisualforceXssCheck.js +150 -0
  111. package/lib/checks/registry.js +97 -12
  112. package/lib/commands/audit/diff.d.ts +17 -0
  113. package/lib/commands/audit/diff.js +76 -0
  114. package/lib/commands/audit/history.d.ts +15 -0
  115. package/lib/commands/audit/history.js +59 -0
  116. package/lib/commands/audit/security.js +6 -6
  117. package/lib/context/AuditCache.d.ts +20 -0
  118. package/lib/context/AuditContext.d.ts +0 -2
  119. package/lib/findings/AuditResult.d.ts +3 -0
  120. package/lib/findings/ComplianceMapping.d.ts +3 -0
  121. package/lib/findings/ComplianceMapping.js +75 -0
  122. package/lib/findings/Finding.d.ts +20 -0
  123. package/lib/findings/loadScoringConfig.js +9 -2
  124. package/lib/findings/scoring.d.ts +2 -1
  125. package/lib/findings/scoring.js +20 -7
  126. package/lib/history/AuditDiff.d.ts +26 -0
  127. package/lib/history/AuditDiff.js +2 -0
  128. package/lib/history/DiffEngine.d.ts +4 -0
  129. package/lib/history/DiffEngine.js +61 -0
  130. package/lib/history/HistoryStore.d.ts +11 -0
  131. package/lib/history/HistoryStore.js +56 -0
  132. package/lib/history/metricMeta.d.ts +9 -0
  133. package/lib/history/metricMeta.js +28 -0
  134. package/lib/index.d.ts +7 -1
  135. package/lib/index.js +2 -1
  136. package/lib/lib/wire.d.ts +1 -2
  137. package/lib/lib/wire.js +1 -2
  138. package/lib/renderers/DiffHtmlRenderer.d.ts +8 -0
  139. package/lib/renderers/DiffHtmlRenderer.js +164 -0
  140. package/lib/renderers/DiffJsonRenderer.d.ts +8 -0
  141. package/lib/renderers/DiffJsonRenderer.js +8 -0
  142. package/lib/renderers/DiffRenderer.d.ts +7 -0
  143. package/lib/renderers/DiffRenderer.js +2 -0
  144. package/lib/renderers/HistoryRenderer.d.ts +6 -0
  145. package/lib/renderers/HistoryRenderer.js +140 -0
  146. package/lib/renderers/HtmlRenderer.d.ts +1 -0
  147. package/lib/renderers/HtmlRenderer.js +354 -54
  148. package/lib/renderers/MarkdownRenderer.js +35 -2
  149. package/package.json +12 -3
@@ -14,6 +14,9 @@ const RISK_BG = {
14
14
  };
15
15
  const PASS_COLOR = '#22c55e';
16
16
  const PASS_BG = 'rgba(34,197,94,0.10)';
17
+ const GRADE_COLOR = {
18
+ A: '#22c55e', B: '#84cc16', C: '#eab308', D: '#f97316', F: '#ef4444',
19
+ };
17
20
  function esc(str) {
18
21
  return str
19
22
  .replace(/&/g, '&')
@@ -21,33 +24,195 @@ function esc(str) {
21
24
  .replace(/>/g, '>')
22
25
  .replace(/"/g, '"');
23
26
  }
27
+ // ── Dashboard helpers ────────────────────────────────────────────────────────
28
+ function statusColor(value, warnThreshold, dangerThreshold) {
29
+ if (value <= warnThreshold)
30
+ return '#22c55e';
31
+ if (value <= dangerThreshold)
32
+ return '#d97706';
33
+ return '#dc2626';
34
+ }
35
+ function progressBar(value, max, color) {
36
+ if (max === 0)
37
+ return '';
38
+ const pct = Math.min(100, Math.round((value / max) * 100));
39
+ return `<div class="prog-bar"><div class="prog-fill" style="width:${pct}%;background:${color}"></div></div>`;
40
+ }
41
+ function metricRow(label, value, color, bar) {
42
+ const val = color
43
+ ? `<span style="color:${color};font-weight:700">${esc(String(value))}</span>`
44
+ : `<span class="metric-value">${esc(String(value))}</span>`;
45
+ return `<div class="metric-row"><span class="metric-label">${esc(label)}</span><div class="metric-right">${val}${bar ?? ''}</div></div>`;
46
+ }
47
+ function inventoryCard(title, rows) {
48
+ return `<div class="inv-card"><div class="inv-card-title">${esc(title)}</div>${rows.join('')}</div>`;
49
+ }
50
+ function buildScoreRing(score, grade, color) {
51
+ return `
52
+ <div class="score-ring" style="background:conic-gradient(from -90deg, ${color} ${score}%, #2d3748 ${score}%)" aria-label="Health score ${score} out of 100, grade ${grade}">
53
+ <div class="score-inner">
54
+ <div class="score-num" style="color:${color}">${score}<span>/100</span></div>
55
+ <div class="score-grade" style="background:${color}">${esc(grade)}</div>
56
+ </div>
57
+ </div>`;
58
+ }
59
+ function buildDonutSvg(counts) {
60
+ const levels = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'];
61
+ const total = levels.reduce((s, l) => s + (counts[l] ?? 0), 0);
62
+ const cx = 60, cy = 60, R = 44;
63
+ const CIRC = 2 * Math.PI * R;
64
+ if (total === 0) {
65
+ return `<svg width="120" height="120" viewBox="0 0 120 120" aria-hidden="true">
66
+ <circle cx="${cx}" cy="${cy}" r="${R}" fill="none" stroke="#21262d" stroke-width="14" />
67
+ <text x="${cx}" y="${cy + 5}" text-anchor="middle" fill="#22c55e" font-size="12" font-family="system-ui,sans-serif">Clean</text>
68
+ </svg>`;
69
+ }
70
+ let offset = CIRC / 4; // Start from 12 o'clock
71
+ const arcs = levels.map(l => {
72
+ const count = counts[l] ?? 0;
73
+ if (count === 0)
74
+ return '';
75
+ const dash = (count / total) * CIRC;
76
+ const arc = `<circle cx="${cx}" cy="${cy}" r="${R}" fill="none" stroke="${RISK_COLORS[l]}" stroke-width="14" stroke-dasharray="${dash.toFixed(2)} ${CIRC.toFixed(2)}" stroke-dashoffset="${offset.toFixed(2)}" />`;
77
+ offset -= dash;
78
+ return arc;
79
+ });
80
+ return `<svg width="120" height="120" viewBox="0 0 120 120" aria-hidden="true">
81
+ <circle cx="${cx}" cy="${cy}" r="${R}" fill="none" stroke="#21262d" stroke-width="14" />
82
+ ${arcs.join('')}
83
+ <text x="${cx}" y="${cy - 5}" text-anchor="middle" fill="#f0f6fc" font-size="20" font-weight="700" font-family="system-ui,sans-serif">${total}</text>
84
+ <text x="${cx}" y="${cy + 14}" text-anchor="middle" fill="#8b949e" font-size="10" font-family="system-ui,sans-serif">findings</text>
85
+ </svg>`;
86
+ }
87
+ function buildDashboard(result, counts) {
88
+ const m = result.metrics;
89
+ const gradeColor = GRADE_COLOR[result.grade] ?? '#64748b';
90
+ const gauge = buildScoreRing(result.healthScore, result.grade, gradeColor);
91
+ const donut = buildDonutSvg(counts);
92
+ const kpiCards = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'].map(l => `<div class="kpi-card" style="border-top:3px solid ${RISK_COLORS[l]}">
93
+ <div class="kpi-value" style="color:${RISK_COLORS[l]}">${counts[l] ?? 0}</div>
94
+ <div class="kpi-label">${l}</div>
95
+ </div>`).join('');
96
+ // Users & Access
97
+ const modifyColor = statusColor(m.modifyAllDataUsersCount, 2, 5);
98
+ const viewColor = statusColor(m.viewAllDataUsersCount, 5, 15);
99
+ const inactiveColor = statusColor(m.inactiveUsers90d, 0, 5);
100
+ const usersCard = inventoryCard('Users & Access', [
101
+ metricRow('Active Users', m.totalActiveUsers),
102
+ metricRow('Modify All Data', m.modifyAllDataUsersCount, modifyColor, m.totalActiveUsers > 0 ? progressBar(m.modifyAllDataUsersCount, m.totalActiveUsers, modifyColor) : ''),
103
+ metricRow('View All Data', m.viewAllDataUsersCount, viewColor, m.totalActiveUsers > 0 ? progressBar(m.viewAllDataUsersCount, m.totalActiveUsers, viewColor) : ''),
104
+ metricRow('Inactive 90d', m.inactiveUsers90d, inactiveColor),
105
+ metricRow('Profiles', m.profileCount),
106
+ metricRow('Permission Sets', m.permissionSetCount),
107
+ ]);
108
+ // Code Quality
109
+ const covColor = m.codeCoveragePercent >= 75 ? '#22c55e' : m.codeCoveragePercent >= 50 ? '#d97706' : '#dc2626';
110
+ const codeCard = inventoryCard('Code Quality', [
111
+ metricRow('Apex Classes', m.apexClassCount),
112
+ metricRow('Apex Triggers', m.apexTriggerCount),
113
+ metricRow('Code Coverage', `${m.codeCoveragePercent}%`, covColor, progressBar(m.codeCoveragePercent, 100, covColor)),
114
+ ]);
115
+ // Integrations
116
+ const insecureColor = m.insecureRemoteSitesCount > 0 ? '#dc2626' : '#22c55e';
117
+ const unusedCredColor = statusColor(m.unusedNamedCredentialsCount, 0, 2);
118
+ const integrationsCard = inventoryCard('Integrations', [
119
+ metricRow('Connected Apps', m.connectedAppsCount),
120
+ metricRow('Remote Sites', m.remoteSitesCount),
121
+ metricRow('↳ Insecure', m.insecureRemoteSitesCount, insecureColor, m.remoteSitesCount > 0 ? progressBar(m.insecureRemoteSitesCount, m.remoteSitesCount, insecureColor) : ''),
122
+ metricRow('Named Credentials', m.namedCredentialsCount),
123
+ metricRow('↳ Unused', m.unusedNamedCredentialsCount, m.unusedNamedCredentialsCount > 0 ? '#d97706' : '#22c55e', m.namedCredentialsCount > 0 ? progressBar(m.unusedNamedCredentialsCount, m.namedCredentialsCount, unusedCredColor) : ''),
124
+ ]);
125
+ // Governance & Events
126
+ const failedColor = statusColor(m.failedLogins30d, 10, 100);
127
+ const healthChkColor = m.healthCheckScore >= 75 ? '#22c55e' : m.healthCheckScore >= 50 ? '#d97706' : '#dc2626';
128
+ const governanceCard = inventoryCard('Governance & Events', [
129
+ metricRow('Failed Logins (30d)', m.failedLogins30d, failedColor),
130
+ metricRow('SF Health Check', `${m.healthCheckScore}%`, healthChkColor, progressBar(m.healthCheckScore, 100, healthChkColor)),
131
+ ]);
132
+ return `
133
+ <div class="dashboard">
134
+ <div class="dash-top">
135
+ <div class="dash-score-panel">
136
+ <div class="gauge-wrap">
137
+ ${gauge}
138
+ </div>
139
+ </div>
140
+ <div class="dash-risk-panel">
141
+ <div class="donut-wrap">
142
+ ${donut}
143
+ <div class="donut-legend">
144
+ ${['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'].map(l => `<div class="legend-row">
145
+ <span class="legend-dot" style="background:${RISK_COLORS[l]}"></span>
146
+ <span>${l}</span>
147
+ <span class="legend-count">${counts[l] ?? 0}</span>
148
+ </div>`).join('')}
149
+ </div>
150
+ </div>
151
+ </div>
152
+ </div>
153
+ <div class="kpi-strip">${kpiCards}</div>
154
+ <div class="inv-grid">
155
+ ${usersCard}
156
+ ${codeCard}
157
+ ${integrationsCard}
158
+ ${governanceCard}
159
+ </div>
160
+ </div>`;
161
+ }
162
+ // ── Main renderer ────────────────────────────────────────────────────────────
24
163
  export class HtmlRenderer {
25
164
  format = 'html';
26
165
  fileExtension = '.html';
166
+ renderAttackPaths(result) {
167
+ if (!result.attackChains || result.attackChains.length === 0)
168
+ return '';
169
+ const escStr = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
170
+ const cards = result.attackChains
171
+ .map((c) => {
172
+ const conf = c.confidence === 'named' ? '' : ' (potential)';
173
+ const steps = c.steps
174
+ .map((s, i) => `<li><strong>${escStr(s.title ?? s.findingId)}</strong> (${escStr(s.severity ?? '—')}) — grants <code>${escStr(s.capability)}</code></li>`)
175
+ .join('');
176
+ return `<div class="attack-chain severity-${c.severity.toLowerCase()}">
177
+ <h3>[${escStr(c.severity)}] ${escStr(c.title)}${conf}</h3>
178
+ <p>${escStr(c.narrative)}</p>
179
+ <ol>${steps}</ol>
180
+ <p class="remediation"><strong>Remediation:</strong> ${escStr(c.remediation)}</p>
181
+ </div>`;
182
+ })
183
+ .join('\n');
184
+ return `<section class="attack-paths">
185
+ <h2>Attack Paths (${result.attackChains.length})</h2>
186
+ <p class="subtitle">Combinations of findings that together enable an exploit more severe than any single finding.</p>
187
+ ${cards}
188
+ </section>`;
189
+ }
27
190
  render(result) {
28
191
  const levels = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'];
29
192
  const counts = Object.fromEntries(levels.map((l) => [l, result.findings.filter((f) => f.riskLevel === l).length]));
30
- const gradeColor = {
31
- A: '#22c55e', B: '#84cc16', C: '#eab308', D: '#f97316', F: '#ef4444',
32
- };
33
- const summaryBadges = levels
34
- .map((l) => `<span class="badge" style="background:${RISK_COLORS[l]}">${counts[l]} ${l}</span>`)
35
- .join('');
36
193
  const filterButtons = [
37
194
  `<button class="filter-btn active" data-filter="all">All (${result.findings.length})</button>`,
38
195
  ...levels.map((l) => `<button class="filter-btn" data-filter="${l}" style="--accent:${RISK_COLORS[l]}">${l} (${counts[l]})</button>`),
39
196
  ].join('\n ');
197
+ const attackPathsHtml = this.renderAttackPaths(result);
40
198
  const findingsHtml = result.findings.length === 0
41
- ? '<p style="color:#64748b;text-align:center;padding:2rem 0">No findings.</p>'
199
+ ? '<p class="no-findings">No findings.</p>'
42
200
  : result.findings.map((f) => {
43
- const cardAccent = f.passed ? PASS_COLOR : (RISK_COLORS[f.riskLevel] ?? '#64748b');
44
- const cardBg = f.passed ? PASS_BG : (RISK_BG[f.riskLevel] ?? 'rgba(100,116,139,0.12)');
45
- const badgeStyle = f.passed ? PASS_COLOR : (RISK_COLORS[f.riskLevel] ?? '#64748b');
46
- const badgeLabel = f.passed ? '✓ PASS' : esc(f.riskLevel);
201
+ const isInconclusive = !!f.inconclusive;
202
+ const cardAccent = isInconclusive ? '#8b949e' : (f.passed ? PASS_COLOR : (RISK_COLORS[f.riskLevel] ?? '#64748b'));
203
+ const cardBg = isInconclusive ? 'rgba(139,148,158,0.06)' : (f.passed ? PASS_BG : (RISK_BG[f.riskLevel] ?? 'rgba(100,116,139,0.12)'));
204
+ const badgeHtml = isInconclusive
205
+ ? `<span class="inconclusive-badge">? INCONCLUSIVE</span>`
206
+ : f.passed
207
+ ? `<span class="risk-badge" style="background:${PASS_COLOR}">✓ PASS</span>`
208
+ : `<span class="risk-badge" style="background:${RISK_COLORS[f.riskLevel] ?? '#64748b'}">${esc(f.riskLevel)}</span>`;
209
+ const tagsHtml = f.complianceTags?.length
210
+ ? `<div class="compliance-tags">${f.complianceTags.map((t) => `<span class="compliance-tag">${esc(t)}</span>`).join('')}</div>`
211
+ : '';
47
212
  return `
48
- <details class="finding-card" data-risk="${esc(f.riskLevel)}" style="--card-accent:${cardAccent};--card-bg:${cardBg}">
213
+ <details class="finding-card${isInconclusive ? ' is-inconclusive' : ''}" data-risk="${esc(f.riskLevel)}" style="--card-accent:${cardAccent};--card-bg:${cardBg}">
49
214
  <summary class="finding-summary">
50
- <span class="risk-badge" style="background:${badgeStyle}">${badgeLabel}</span>
215
+ ${badgeHtml}
51
216
  <span class="finding-title">${esc(f.title)}</span>
52
217
  <span class="finding-category">${esc(f.category)}</span>
53
218
  <span class="chevron">›</span>
@@ -73,6 +238,7 @@ export class HtmlRenderer {
73
238
  }).join('');
74
239
  return `<div class="affected-items"><strong>Affected items (${f.affectedItems.length})</strong><table class="affected-table"><thead>${thead}</thead><tbody>${tbody}</tbody></table></div>`;
75
240
  })() : ''}
241
+ ${tagsHtml}
76
242
  </div>
77
243
  </details>`;
78
244
  }).join('\n');
@@ -82,57 +248,143 @@ export class HtmlRenderer {
82
248
  <meta charset="UTF-8">
83
249
  <meta name="viewport" content="width=device-width,initial-scale=1">
84
250
  <title>SF Security Audit — ${esc(result.orgName)}</title>
251
+ <link rel="preconnect" href="https://fonts.googleapis.com">
252
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;700&family=Fira+Sans:wght@300;400;500;600;700&display=swap">
85
253
  <style>
86
254
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
87
255
  body {
88
- font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
256
+ font-family: 'Fira Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
89
257
  background: #0d1117;
90
258
  color: #c9d1d9;
91
- max-width: 1000px;
259
+ max-width: 1100px;
92
260
  margin: 2rem auto;
93
261
  padding: 0 1.25rem 4rem;
94
262
  line-height: 1.6;
95
263
  }
96
- /* Header */
97
- .header { margin-bottom: 2rem; }
264
+
265
+ /* ── Header ── */
266
+ .header { margin-bottom: 1.5rem; }
98
267
  .header h1 { color: #f0f6fc; font-size: 1.5rem; font-weight: 700; margin-bottom: 0.4rem; }
99
- .meta { font-size: 0.8rem; color: #8b949e; display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
100
- /* Score card */
101
- .scorecard {
268
+ .meta { font-size: 0.8rem; color: #8b949e; display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; }
269
+
270
+ /* ── Dashboard ── */
271
+ .dashboard { margin-bottom: 2rem; }
272
+
273
+ .dash-top {
274
+ display: grid;
275
+ grid-template-columns: 1fr 1fr;
276
+ gap: 0.75rem;
277
+ margin-bottom: 0.75rem;
278
+ }
279
+ .dash-score-panel, .dash-risk-panel {
102
280
  background: #161b22;
103
281
  border: 1px solid #30363d;
104
282
  border-radius: 12px;
105
- padding: 1.5rem 2rem;
283
+ padding: 1.5rem;
106
284
  display: flex;
107
285
  align-items: center;
108
- gap: 2rem;
109
- margin-bottom: 1.5rem;
110
- flex-wrap: wrap;
286
+ justify-content: center;
111
287
  }
112
- .score-number {
113
- font-size: 3.5rem;
114
- font-weight: 800;
115
- color: #f0f6fc;
288
+
289
+ /* Score ring */
290
+ .gauge-wrap { display: flex; align-items: center; justify-content: center; }
291
+ .score-ring {
292
+ width: 152px;
293
+ height: 152px;
294
+ border-radius: 50%;
295
+ padding: 11px;
296
+ display: flex;
297
+ align-items: center;
298
+ justify-content: center;
299
+ }
300
+ .score-inner {
301
+ width: 100%;
302
+ height: 100%;
303
+ border-radius: 50%;
304
+ background: #161b22;
305
+ display: flex;
306
+ flex-direction: column;
307
+ align-items: center;
308
+ justify-content: center;
309
+ gap: 0.4rem;
310
+ }
311
+ .score-num {
312
+ font-size: 2rem;
313
+ font-weight: 700;
116
314
  line-height: 1;
315
+ font-family: 'Fira Code', monospace;
117
316
  }
118
- .score-number span { font-size: 1.25rem; color: #8b949e; font-weight: 400; }
119
- .grade-badge {
120
- width: 3rem; height: 3rem;
317
+ .score-num span { font-size: 0.75rem; color: #8b949e; font-weight: 400; }
318
+ .score-grade {
319
+ display: inline-flex;
320
+ align-items: center;
321
+ justify-content: center;
322
+ width: 1.75rem;
323
+ height: 1.75rem;
121
324
  border-radius: 50%;
122
- display: flex; align-items: center; justify-content: center;
123
- font-size: 1.5rem; font-weight: 800;
325
+ font-size: 0.9rem;
326
+ font-weight: 800;
124
327
  color: #fff;
125
- background: ${gradeColor[result.grade] ?? '#64748b'};
126
328
  }
127
- .summary-badges { display: flex; flex-wrap: wrap; gap: 0.5rem; }
128
- .badge {
129
- padding: 0.2rem 0.65rem;
130
- border-radius: 20px;
131
- font-size: 0.75rem;
329
+
330
+ /* Donut */
331
+ .donut-wrap { display: flex; align-items: center; gap: 1.5rem; }
332
+ .donut-legend { display: flex; flex-direction: column; gap: 0.45rem; }
333
+ .legend-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; color: #c9d1d9; }
334
+ .legend-dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
335
+ .legend-count { margin-left: auto; font-weight: 700; color: #f0f6fc; padding-left: 1rem; }
336
+
337
+ /* KPI strip */
338
+ .kpi-strip {
339
+ display: grid;
340
+ grid-template-columns: repeat(4, 1fr);
341
+ gap: 0.75rem;
342
+ margin-bottom: 0.75rem;
343
+ }
344
+ .kpi-card {
345
+ background: #161b22;
346
+ border: 1px solid #30363d;
347
+ border-radius: 10px;
348
+ padding: 1rem 1.25rem;
349
+ }
350
+ .kpi-value { font-size: 2rem; font-weight: 800; line-height: 1; margin-bottom: 0.25rem; }
351
+ .kpi-label { font-size: 0.7rem; font-weight: 700; color: #8b949e; letter-spacing: 0.06em; }
352
+
353
+ /* Inventory grid */
354
+ .inv-grid {
355
+ display: grid;
356
+ grid-template-columns: repeat(2, 1fr);
357
+ gap: 0.75rem;
358
+ }
359
+ .inv-card {
360
+ background: #161b22;
361
+ border: 1px solid #30363d;
362
+ border-radius: 10px;
363
+ padding: 1rem 1.25rem;
364
+ }
365
+ .inv-card-title {
366
+ font-size: 0.7rem;
132
367
  font-weight: 700;
133
- color: #fff;
368
+ color: #8b949e;
369
+ letter-spacing: 0.06em;
370
+ text-transform: uppercase;
371
+ margin-bottom: 0.6rem;
372
+ padding-bottom: 0.5rem;
373
+ border-bottom: 1px solid #21262d;
374
+ }
375
+ .metric-row {
376
+ display: flex;
377
+ align-items: center;
378
+ gap: 0.5rem;
379
+ padding: 0.28rem 0;
134
380
  }
135
- /* Filters */
381
+ .metric-label { flex: 1; font-size: 0.82rem; color: #c9d1d9; }
382
+ .metric-right { display: flex; flex-direction: column; align-items: flex-end; gap: 0.2rem; min-width: 72px; }
383
+ .metric-value { font-size: 0.9rem; font-weight: 700; color: #f0f6fc; }
384
+ .prog-bar { width: 72px; height: 4px; background: #21262d; border-radius: 2px; overflow: hidden; }
385
+ .prog-fill { height: 100%; border-radius: 2px; }
386
+
387
+ /* ── Filters ── */
136
388
  .filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.25rem; }
137
389
  .filter-btn {
138
390
  padding: 0.35rem 0.9rem;
@@ -151,7 +403,8 @@ export class HtmlRenderer {
151
403
  border-color: var(--accent, #238636);
152
404
  color: #fff;
153
405
  }
154
- /* Finding cards */
406
+
407
+ /* ── Finding cards ── */
155
408
  .finding-card {
156
409
  background: var(--card-bg);
157
410
  border: 1px solid #30363d;
@@ -185,7 +438,7 @@ export class HtmlRenderer {
185
438
  .finding-category { font-size: 0.75rem; color: #8b949e; white-space: nowrap; }
186
439
  .chevron { color: #8b949e; font-size: 1.2rem; transition: transform 0.2s; }
187
440
  .finding-card[open] .chevron { transform: rotate(90deg); }
188
- .finding-body { padding: 0 1rem 1rem 1rem; border-top: 1px solid #30363d; }
441
+ .finding-body { padding: 0 1rem 1rem; border-top: 1px solid #30363d; }
189
442
  .finding-detail { color: #c9d1d9; font-size: 0.875rem; padding: 0.75rem 0 0.5rem; }
190
443
  .remediation-box {
191
444
  background: rgba(35,134,54,0.1);
@@ -196,10 +449,7 @@ export class HtmlRenderer {
196
449
  font-size: 0.85rem;
197
450
  }
198
451
  .remediation-box strong { color: #3fb950; display: block; margin-bottom: 0.25rem; }
199
- .affected-items {
200
- margin-top: 0.75rem;
201
- font-size: 0.82rem;
202
- }
452
+ .affected-items { margin-top: 0.75rem; font-size: 0.82rem; }
203
453
  .affected-items strong { color: #c9d1d9; display: block; margin-bottom: 0.5rem; }
204
454
  .affected-table {
205
455
  width: 100%;
@@ -226,8 +476,57 @@ export class HtmlRenderer {
226
476
  .affected-table tr:last-child td { border-bottom: none; }
227
477
  .affected-table a { color: #58a6ff; text-decoration: none; white-space: nowrap; }
228
478
  .affected-table a:hover { text-decoration: underline; }
229
- /* Empty state */
479
+
230
480
  .no-findings { color: #8b949e; text-align: center; padding: 3rem 0; }
481
+
482
+ /* ── Compliance tags ── */
483
+ .compliance-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.5rem; }
484
+ .compliance-tag {
485
+ font-size: 0.65rem;
486
+ font-weight: 700;
487
+ padding: 0.1rem 0.45rem;
488
+ border-radius: 3px;
489
+ background: rgba(88,166,255,0.12);
490
+ border: 1px solid rgba(88,166,255,0.25);
491
+ color: #58a6ff;
492
+ letter-spacing: 0.03em;
493
+ white-space: nowrap;
494
+ }
495
+ /* ── Inconclusive findings ── */
496
+ .finding-card.is-inconclusive {
497
+ border-left-color: #8b949e !important;
498
+ opacity: 0.8;
499
+ }
500
+ .finding-card.is-inconclusive .finding-summary { background: rgba(139,148,158,0.05); }
501
+ .inconclusive-badge {
502
+ flex-shrink: 0;
503
+ padding: 0.15rem 0.6rem;
504
+ border-radius: 4px;
505
+ font-size: 0.7rem;
506
+ font-weight: 800;
507
+ color: #8b949e;
508
+ border: 1px dashed #8b949e;
509
+ letter-spacing: 0.04em;
510
+ }
511
+ /* ── Offline footer ── */
512
+ .offline-footer {
513
+ margin-top: 3rem;
514
+ padding: 0.75rem 1rem;
515
+ border-radius: 8px;
516
+ background: rgba(34,197,94,0.05);
517
+ border: 1px solid rgba(34,197,94,0.15);
518
+ font-size: 0.78rem;
519
+ color: #8b949e;
520
+ text-align: center;
521
+ }
522
+ .offline-footer strong { color: #3fb950; }
523
+
524
+ /* ── Responsive ── */
525
+ @media (max-width: 680px) {
526
+ .dash-top { grid-template-columns: 1fr; }
527
+ .kpi-strip { grid-template-columns: repeat(2, 1fr); }
528
+ .inv-grid { grid-template-columns: 1fr; }
529
+ }
231
530
  </style>
232
531
  </head>
233
532
  <body>
@@ -242,11 +541,9 @@ export class HtmlRenderer {
242
541
  </div>
243
542
  </div>
244
543
 
245
- <div class="scorecard">
246
- <div class="score-number">${result.healthScore}<span>/100</span></div>
247
- <div class="grade-badge" title="Grade">${esc(result.grade)}</div>
248
- <div class="summary-badges">${summaryBadges}</div>
249
- </div>
544
+ ${buildDashboard(result, counts)}
545
+
546
+ ${attackPathsHtml}
250
547
 
251
548
  <div class="filters">
252
549
  ${filterButtons}
@@ -258,7 +555,7 @@ export class HtmlRenderer {
258
555
 
259
556
  <script>
260
557
  const buttons = document.querySelectorAll('.filter-btn');
261
- const cards = document.querySelectorAll('.finding-card');
558
+ const cards = document.querySelectorAll('.finding-card');
262
559
 
263
560
  buttons.forEach(btn => {
264
561
  btn.addEventListener('click', () => {
@@ -271,6 +568,9 @@ export class HtmlRenderer {
271
568
  });
272
569
  });
273
570
  </script>
571
+ <div class="offline-footer">
572
+ <strong>Offline-first audit</strong> — all analysis performed locally; no data is transmitted outside your Salesforce org. Generated by CloudCounsel SF Audit.
573
+ </div>
274
574
  </body>
275
575
  </html>`;
276
576
  }
@@ -1,5 +1,5 @@
1
1
  function escapeMdCell(s) {
2
- return s.replace(/\|/g, '\\|').replace(/\n/g, ' ');
2
+ return s.replace(/\\/g, '\\\\').replace(/\|/g, '\\|').replace(/\n/g, ' ');
3
3
  }
4
4
  export class MarkdownRenderer {
5
5
  format = 'md';
@@ -12,6 +12,29 @@ export class MarkdownRenderer {
12
12
  lines.push(`**Instance:** ${result.instance} | **Type:** ${result.orgType}${result.isSandbox ? ' (Sandbox)' : ''}`);
13
13
  lines.push(`**Health Score:** ${result.healthScore}/100 | **Grade:** ${result.grade}`);
14
14
  lines.push('');
15
+ if (result.attackChains && result.attackChains.length > 0) {
16
+ lines.push(`## Attack Paths (${result.attackChains.length})`);
17
+ lines.push('');
18
+ lines.push('_Combinations of findings that together enable an exploit more severe than any single finding._');
19
+ lines.push('');
20
+ for (const c of result.attackChains) {
21
+ const conf = c.confidence === 'named' ? '' : ' _(potential)_';
22
+ lines.push(`### [${c.severity}] ${c.title}${conf}`);
23
+ lines.push('');
24
+ lines.push(c.narrative);
25
+ lines.push('');
26
+ lines.push('**Steps:**');
27
+ lines.push('');
28
+ c.steps.forEach((s, i) => {
29
+ lines.push(`${i + 1}. **${s.title ?? s.findingId}** (${s.severity ?? '—'}) — grants \`${s.capability}\``);
30
+ });
31
+ lines.push('');
32
+ lines.push(`**Remediation:** ${c.remediation}`);
33
+ lines.push('');
34
+ lines.push('---');
35
+ lines.push('');
36
+ }
37
+ }
15
38
  lines.push(`## Findings (${result.findings.length})`);
16
39
  lines.push('');
17
40
  if (result.findings.length === 0) {
@@ -19,12 +42,17 @@ export class MarkdownRenderer {
19
42
  }
20
43
  else {
21
44
  for (const f of result.findings) {
22
- lines.push(`### [${f.riskLevel}] ${f.title}`);
45
+ const levelLabel = f.inconclusive ? 'INCONCLUSIVE' : f.riskLevel;
46
+ lines.push(`### [${levelLabel}] ${f.title}`);
23
47
  lines.push(`**Category:** ${f.category}`);
24
48
  lines.push('');
25
49
  lines.push(f.detail);
26
50
  lines.push('');
27
51
  lines.push(`**Remediation:** ${f.remediation}`);
52
+ if (f.complianceTags?.length) {
53
+ lines.push('');
54
+ lines.push(`**Compliance:** ${f.complianceTags.join(' · ')}`);
55
+ }
28
56
  if (f.affectedItems?.length) {
29
57
  const hasUrls = f.affectedItems.some((i) => i.url);
30
58
  const hasNotes = f.affectedItems.some((i) => i.note);
@@ -48,6 +76,11 @@ export class MarkdownRenderer {
48
76
  lines.push('');
49
77
  }
50
78
  }
79
+ lines.push('');
80
+ lines.push('---');
81
+ lines.push('');
82
+ lines.push('> **Offline-first audit** — all analysis is performed locally; no data is transmitted outside your Salesforce org. Generated by CloudCounsel SF Audit.');
83
+ lines.push('');
51
84
  return lines.join('\n');
52
85
  }
53
86
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@cclabsnz/sf-audit",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Salesforce Security Audit — native sf plugin",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
8
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",
9
+ "test": "node --experimental-vm-modules node_modules/jest-cli/bin/jest.js --passWithNoTests",
10
+ "test:unit": "node --experimental-vm-modules node_modules/jest-cli/bin/jest.js test/unit --passWithNoTests",
11
11
  "prepack": "npm run build",
12
12
  "clean": "rm -rf lib"
13
13
  },
@@ -45,6 +45,15 @@
45
45
  }
46
46
  }
47
47
  },
48
+ "overrides": {
49
+ "handlebars": "^4.7.9",
50
+ "minimatch@5": {
51
+ "brace-expansion": "^2.0.3"
52
+ },
53
+ "minimatch@10": {
54
+ "brace-expansion": "^5.0.5"
55
+ }
56
+ },
48
57
  "files": [
49
58
  "/lib",
50
59
  "/messages",