@cclabsnz/sf-audit 1.1.0 → 1.3.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 (133) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +168 -38
  3. package/lib/chains/namedChains.js +4 -4
  4. package/lib/checks/CheckEngine.js +1 -1
  5. package/lib/checks/impl/AnonymousApexAuditCheck.js +5 -5
  6. package/lib/checks/impl/ApexCrudFLSCheck.d.ts +1 -1
  7. package/lib/checks/impl/ApexCrudFLSCheck.js +4 -4
  8. package/lib/checks/impl/ApexLoggingCheck.js +10 -10
  9. package/lib/checks/impl/ApexRestEndpointCheck.js +5 -5
  10. package/lib/checks/impl/ApexSharingCheck.js +3 -3
  11. package/lib/checks/impl/ApiClientPermissionCheck.js +2 -2
  12. package/lib/checks/impl/CertificateExpiryCheck.js +1 -1
  13. package/lib/checks/impl/ConnectedAppInactivityCheck.d.ts +1 -1
  14. package/lib/checks/impl/ConnectedAppInactivityCheck.js +5 -5
  15. package/lib/checks/impl/ConnectedAppScopeCheck.d.ts +1 -1
  16. package/lib/checks/impl/ConnectedAppScopeCheck.js +4 -4
  17. package/lib/checks/impl/ConnectedAppsCheck.js +2 -2
  18. package/lib/checks/impl/ContentLinksCheck.js +6 -6
  19. package/lib/checks/impl/CorsAllowlistCheck.js +3 -3
  20. package/lib/checks/impl/CustomLabelsCredentialCheck.d.ts +1 -1
  21. package/lib/checks/impl/CustomLabelsCredentialCheck.js +7 -7
  22. package/lib/checks/impl/DataClassificationCheck.js +6 -6
  23. package/lib/checks/impl/DebugLogAccessCheck.js +6 -6
  24. package/lib/checks/impl/DeploymentIdentityCheck.js +8 -8
  25. package/lib/checks/impl/EmailSecurityCheck.d.ts +10 -0
  26. package/lib/checks/impl/EmailSecurityCheck.js +117 -0
  27. package/lib/checks/impl/EnhancedDomainsCheck.d.ts +1 -1
  28. package/lib/checks/impl/EnhancedDomainsCheck.js +6 -6
  29. package/lib/checks/impl/EscalationPermsCheck.js +2 -2
  30. package/lib/checks/impl/EventMonitoringCheck.js +6 -6
  31. package/lib/checks/impl/ExperienceCloudSiteCheck.js +3 -3
  32. package/lib/checks/impl/FailedLoginCheck.js +5 -5
  33. package/lib/checks/impl/FieldHistoryTrackingCheck.js +3 -3
  34. package/lib/checks/impl/FieldLevelSecurityCheck.js +2 -2
  35. package/lib/checks/impl/GuestExecutableApexCheck.d.ts +1 -1
  36. package/lib/checks/impl/GuestExecutableApexCheck.js +5 -5
  37. package/lib/checks/impl/GuestUserAccessCheck.js +5 -5
  38. package/lib/checks/impl/HealthCheckCheck.js +2 -2
  39. package/lib/checks/impl/HighAssuranceSessionCheck.js +4 -4
  40. package/lib/checks/impl/InstalledPackagesCheck.js +5 -5
  41. package/lib/checks/impl/IntegrationUsersCheck.js +5 -5
  42. package/lib/checks/impl/InternalUserMfaCheck.js +2 -2
  43. package/lib/checks/impl/IpRestrictionsCheck.js +3 -3
  44. package/lib/checks/impl/LegacyApiVersionCheck.js +1 -1
  45. package/lib/checks/impl/MfaEnforcementCheck.js +3 -3
  46. package/lib/checks/impl/MfaMethodStrengthCheck.js +3 -3
  47. package/lib/checks/impl/MfaRegistrationCheck.js +2 -2
  48. package/lib/checks/impl/MyDomainLoginPolicyCheck.d.ts +1 -1
  49. package/lib/checks/impl/MyDomainLoginPolicyCheck.js +9 -9
  50. package/lib/checks/impl/NamedCredentialsCheck.js +3 -3
  51. package/lib/checks/impl/OutboundMessagesCheck.d.ts +10 -0
  52. package/lib/checks/impl/OutboundMessagesCheck.js +88 -0
  53. package/lib/checks/impl/PasswordSessionPolicyCheck.js +3 -3
  54. package/lib/checks/impl/PermissionsCheck.js +3 -3
  55. package/lib/checks/impl/PrivilegedAccessCheck.d.ts +11 -0
  56. package/lib/checks/impl/PrivilegedAccessCheck.js +111 -0
  57. package/lib/checks/impl/PublicContentExposureCheck.d.ts +10 -0
  58. package/lib/checks/impl/PublicContentExposureCheck.js +98 -0
  59. package/lib/checks/impl/PublicGroupSharingCheck.js +1 -1
  60. package/lib/checks/impl/ReleaseUpdatesCheck.js +2 -2
  61. package/lib/checks/impl/RemoteSitesCheck.js +1 -1
  62. package/lib/checks/impl/ReportFolderAccessCheck.d.ts +1 -1
  63. package/lib/checks/impl/ReportFolderAccessCheck.js +4 -4
  64. package/lib/checks/impl/ScheduledApexCheck.js +1 -1
  65. package/lib/checks/impl/SeparationOfDutiesCheck.d.ts +11 -0
  66. package/lib/checks/impl/SeparationOfDutiesCheck.js +114 -0
  67. package/lib/checks/impl/SharingModelCheck.d.ts +1 -1
  68. package/lib/checks/impl/SharingModelCheck.js +8 -8
  69. package/lib/checks/impl/SiemIntegrationCheck.js +4 -4
  70. package/lib/checks/impl/SsoEnforcementCheck.js +5 -5
  71. package/lib/checks/impl/StandardProfilesCheck.js +2 -2
  72. package/lib/checks/impl/TransactionSecurityPolicyCheck.js +2 -2
  73. package/lib/checks/impl/TrustedIPRangesCheck.js +5 -5
  74. package/lib/checks/impl/VisualforceXssCheck.js +6 -6
  75. package/lib/checks/permCatalog.d.ts +15 -0
  76. package/lib/checks/permCatalog.js +42 -0
  77. package/lib/checks/registry.js +12 -0
  78. package/lib/commands/audit/diff.js +1 -1
  79. package/lib/commands/audit/security.d.ts +5 -0
  80. package/lib/commands/audit/security.js +33 -4
  81. package/lib/compliance/catalogs/hiso10029.d.ts +3 -0
  82. package/lib/compliance/catalogs/hiso10029.js +35 -0
  83. package/lib/compliance/catalogs/index.d.ts +4 -0
  84. package/lib/compliance/catalogs/index.js +21 -0
  85. package/lib/compliance/catalogs/iso27001.d.ts +3 -0
  86. package/lib/compliance/catalogs/iso27001.js +39 -0
  87. package/lib/compliance/catalogs/nzism.d.ts +3 -0
  88. package/lib/compliance/catalogs/nzism.js +31 -0
  89. package/lib/compliance/catalogs/owasp.d.ts +3 -0
  90. package/lib/compliance/catalogs/owasp.js +37 -0
  91. package/lib/compliance/catalogs/privacyAct.d.ts +3 -0
  92. package/lib/compliance/catalogs/privacyAct.js +17 -0
  93. package/lib/compliance/catalogs/sbs.d.ts +3 -0
  94. package/lib/compliance/catalogs/sbs.js +61 -0
  95. package/lib/compliance/catalogs/soc2.d.ts +3 -0
  96. package/lib/compliance/catalogs/soc2.js +42 -0
  97. package/lib/compliance/mapping.d.ts +2 -0
  98. package/lib/compliance/mapping.js +118 -0
  99. package/lib/compliance/resolve.d.ts +12 -0
  100. package/lib/compliance/resolve.js +49 -0
  101. package/lib/compliance/types.d.ts +13 -0
  102. package/lib/compliance/types.js +2 -0
  103. package/lib/context/AuditCache.d.ts +9 -0
  104. package/lib/findings/CheckMeta.d.ts +9 -0
  105. package/lib/findings/CheckMeta.js +72 -0
  106. package/lib/renderers/AuditRenderer.d.ts +2 -0
  107. package/lib/renderers/ClientReportRenderer.d.ts +29 -0
  108. package/lib/renderers/ClientReportRenderer.js +205 -0
  109. package/lib/renderers/DiffHtmlRenderer.js +1 -1
  110. package/lib/renderers/HistoryRenderer.js +1 -1
  111. package/lib/renderers/HtmlRenderer.js +4 -10
  112. package/lib/renderers/MarkdownRenderer.js +2 -2
  113. package/lib/renderers/html-utils.d.ts +2 -0
  114. package/lib/renderers/html-utils.js +8 -0
  115. package/lib/report/ComplianceMatrix.d.ts +19 -0
  116. package/lib/report/ComplianceMatrix.js +47 -0
  117. package/lib/report/ExecutivePriorities.d.ts +8 -0
  118. package/lib/report/ExecutivePriorities.js +22 -0
  119. package/lib/report/RemediationRoadmap.d.ts +9 -0
  120. package/lib/report/RemediationRoadmap.js +18 -0
  121. package/lib/report/branding.d.ts +18 -0
  122. package/lib/report/branding.js +19 -0
  123. package/lib/report/fonts.d.ts +2 -0
  124. package/lib/report/fonts.js +22 -0
  125. package/messages/audit.security.md +30 -2
  126. package/package.json +3 -1
  127. package/src/assets/fonts/dm-sans-italic-latin.woff2 +0 -0
  128. package/src/assets/fonts/dm-sans-normal-latin.woff2 +0 -0
  129. package/src/assets/fonts/dm-serif-display-italic-latin.woff2 +0 -0
  130. package/src/assets/fonts/dm-serif-display-normal-latin.woff2 +0 -0
  131. package/config/queries/soql.json +0 -24
  132. package/config/queries/tooling.json +0 -28
  133. package/config/scoring.json +0 -17
@@ -0,0 +1,49 @@
1
+ import { CHECK_CONTROL_MAP } from './mapping.js';
2
+ import { getControl } from './catalogs/index.js';
3
+ const PACKS = {
4
+ universal: ['OWASP', 'SOC2', 'ISO27001'],
5
+ nz: ['ISO27001', 'HISO10029', 'PRIVACY_ACT', 'NZISM'],
6
+ all: ['OWASP', 'SOC2', 'ISO27001', 'SBS', 'HISO10029', 'PRIVACY_ACT', 'NZISM', 'HIPAA', 'GDPR'],
7
+ };
8
+ export function packFrameworks(pack) {
9
+ return PACKS[pack];
10
+ }
11
+ export function resolveControls(checkId, opts = {}) {
12
+ const requireVerified = opts.requireVerified ?? true;
13
+ const ids = CHECK_CONTROL_MAP[checkId] ?? [];
14
+ const out = [];
15
+ for (const id of ids) {
16
+ const c = getControl(id);
17
+ if (!c)
18
+ continue;
19
+ if (opts.frameworks && !opts.frameworks.includes(c.framework))
20
+ continue;
21
+ if (requireVerified && !c.verified)
22
+ continue;
23
+ out.push(c);
24
+ }
25
+ return out;
26
+ }
27
+ /** Backward-compatible: the bare id strings, as the old ComplianceMapping returned. */
28
+ export function getComplianceTags(checkId) {
29
+ return CHECK_CONTROL_MAP[checkId] ?? [];
30
+ }
31
+ const ALIAS = {
32
+ owasp: 'OWASP', soc2: 'SOC2', iso: 'ISO27001', iso27001: 'ISO27001', sbs: 'SBS',
33
+ privacy: 'PRIVACY_ACT', 'privacy-act': 'PRIVACY_ACT', hiso: 'HISO10029', nzism: 'NZISM',
34
+ hipaa: 'HIPAA', gdpr: 'GDPR',
35
+ };
36
+ /** Resolve a --frameworks value: a pack name (universal|nz|all) or a comma list of aliases. */
37
+ export function resolveFrameworks(input) {
38
+ const v = input.trim().toLowerCase();
39
+ if (v === 'universal' || v === 'nz' || v === 'all')
40
+ return packFrameworks(v);
41
+ const out = [];
42
+ for (const part of v.split(',').map((s) => s.trim())) {
43
+ const fw = ALIAS[part];
44
+ if (fw && !out.includes(fw))
45
+ out.push(fw);
46
+ }
47
+ return out;
48
+ }
49
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1,13 @@
1
+ export type Framework = 'OWASP' | 'SOC2' | 'ISO27001' | 'SBS' | 'HISO10029' | 'PRIVACY_ACT' | 'NZISM' | 'HIPAA' | 'GDPR';
2
+ export interface ControlDef {
3
+ id: string;
4
+ framework: Framework;
5
+ version: string;
6
+ title: string;
7
+ requirement: string;
8
+ sourceRef: string;
9
+ url?: string;
10
+ verified: boolean;
11
+ }
12
+ export type FrameworkPack = 'universal' | 'nz' | 'all';
13
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -23,6 +23,14 @@ export interface MfaRegistration {
23
23
  profileName: string;
24
24
  methods: string[];
25
25
  }
26
+ export interface EffectivePermissionGrant {
27
+ userId: string;
28
+ username: string;
29
+ name: string;
30
+ profileName: string;
31
+ /** Stable permission keys from DANGEROUS_PERMS held by this user. */
32
+ perms: string[];
33
+ }
26
34
  export interface AuditCache {
27
35
  healthCheckRisks?: HealthCheckRisk[];
28
36
  apexBodies?: ApexClassBody[];
@@ -34,5 +42,6 @@ export interface AuditCache {
34
42
  eventLogSummary?: EventLogSummary;
35
43
  mfaRegistrations?: MfaRegistration[];
36
44
  vfPageBodies?: VfPageBody[];
45
+ effectivePermissions?: EffectivePermissionGrant[];
37
46
  }
38
47
  //# sourceMappingURL=AuditCache.d.ts.map
@@ -0,0 +1,9 @@
1
+ export interface CheckMeta {
2
+ /** Remediation effort tier: quick = ≤1 day, moderate = days, project = weeks. */
3
+ effort: 'quick' | 'moderate' | 'project';
4
+ /** One-sentence abuse/incident narrative for standalone (non-chained) top-N findings. */
5
+ impact: string;
6
+ }
7
+ export declare const CHECK_META: Record<string, CheckMeta>;
8
+ export declare function getCheckMeta(id: string): CheckMeta | undefined;
9
+ //# sourceMappingURL=CheckMeta.d.ts.map
@@ -0,0 +1,72 @@
1
+ export const CHECK_META = {
2
+ 'users-and-admins': { effort: 'moderate', impact: 'Over-privileged admins mean one compromised account can read, alter, or export the entire org’s data.' },
3
+ 'permissions': { effort: 'moderate', impact: 'Permission-set sprawl widens the blast radius of any single account takeover.' },
4
+ 'inactive-users': { effort: 'quick', impact: 'Dormant but active accounts are unmonitored entry points attackers reuse without raising suspicion.' },
5
+ 'login-session': { effort: 'quick', impact: 'Weak session settings let a stolen session token stay valid long enough to be replayed.' },
6
+ 'ip-restrictions': { effort: 'moderate', impact: 'Without IP restrictions, stolen admin credentials work from anywhere in the world.' },
7
+ 'password-session-policy': { effort: 'quick', impact: 'Weak password and session policy makes credential guessing and session hijacking far easier.' },
8
+ 'field-level-security': { effort: 'moderate', impact: 'Sensitive fields (SSN, card, tax id) exposed to broad permission sets leak PII to users who shouldn’t see it.' },
9
+ 'sharing-model': { effort: 'project', impact: 'Loose org-wide defaults expose records org-wide; any internal user can read data meant to be private.' },
10
+ 'public-group-sharing': { effort: 'moderate', impact: 'Sharing rules granting “All Internal Users” turn a low-privilege account into a path to sensitive records.' },
11
+ 'guest-user-access': { effort: 'moderate', impact: 'Object access granted to unauthenticated guests lets anonymous web visitors read or modify records.' },
12
+ 'apex-sharing': { effort: 'project', impact: 'without-sharing Apex bypasses record access, letting low-privilege or guest users reach data they can’t otherwise see.' },
13
+ 'flows-without-sharing': { effort: 'moderate', impact: 'System-context flows without sharing run with elevated rights, exposing records to whoever triggers them.' },
14
+ 'connected-apps': { effort: 'moderate', impact: 'Connected apps not admin-restricted let any user authorize a third-party app to act on org data.' },
15
+ 'remote-sites': { effort: 'quick', impact: 'Permissive remote sites allow Apex callouts to attacker-controlled endpoints (SSRF and data exfiltration).' },
16
+ 'csp-trusted-sites': { effort: 'quick', impact: 'Insecure HTTP CSP entries allow mixed-content loading and man-in-the-middle script injection.' },
17
+ 'named-credentials': { effort: 'quick', impact: 'Unmanaged callout endpoints can send org data to unintended or attacker-controlled destinations.' },
18
+ 'hardcoded-credentials': { effort: 'moderate', impact: 'Secrets embedded in Apex can be read by anyone with code access and reused to reach connected systems.' },
19
+ 'custom-settings': { effort: 'quick', impact: 'Credential-like custom settings may store secrets readable by users who can query them.' },
20
+ 'health-check': { effort: 'moderate', impact: 'Unaddressed Health Check high-risk settings are documented, exploitable misconfigurations.' },
21
+ 'audit-trail': { effort: 'quick', impact: 'Without reviewing the audit trail, malicious permission changes and Login-As abuse go undetected.' },
22
+ 'code-security': { effort: 'project', impact: 'Low Apex test coverage and injection-prone code hide exploitable vulnerabilities behind untested paths.' },
23
+ 'api-limits': { effort: 'quick', impact: 'API exhaustion, deliberate or accidental, can cause denial of service for integrations and users.' },
24
+ 'scheduled-apex': { effort: 'quick', impact: 'Unreviewed scheduled jobs can run unauthorized logic on a recurring basis unnoticed.' },
25
+ 'standard-profiles': { effort: 'moderate', impact: 'Standard profiles grant broad default permissions; users on them often have more access than intended.' },
26
+ 'sso-enforcement': { effort: 'project', impact: 'Without enforced SSO, username/password logins bypass your identity provider’s MFA and conditional access.' },
27
+ 'mfa-enforcement': { effort: 'quick', impact: 'Portal/external users without MFA let a stolen password reach customer or partner data directly.' },
28
+ 'api-client-permission': { effort: 'quick', impact: '“Use Any API Client” bypasses API Access Control, letting a user reach the org from any tool.' },
29
+ 'integration-users': { effort: 'moderate', impact: 'Over-privileged service accounts are prime targets: one stolen key grants broad, unattended access.' },
30
+ 'content-links': { effort: 'quick', impact: 'Public file links without expiry or password leak documents to anyone who finds the URL.' },
31
+ 'field-history-tracking': { effort: 'quick', impact: 'Without field history, tampering with sensitive records can’t be reconstructed after an incident.' },
32
+ 'data-classification': { effort: 'moderate', impact: 'Unclassified sensitive data can’t be protected or encrypted consistently, increasing exposure.' },
33
+ 'deployment-identity': { effort: 'moderate', impact: 'No controlled deployment identity means malicious metadata changes blend in with normal admin activity.' },
34
+ 'apex-logging': { effort: 'moderate', impact: 'Missing logging leaves no trail to detect or investigate abuse of Apex execution.' },
35
+ 'event-monitoring': { effort: 'moderate', impact: 'Without Event Monitoring, data exfiltration and abuse leave no detailed forensic record.' },
36
+ 'siem-integration': { effort: 'project', impact: 'No SIEM forwarding means security events are never correlated or alerted on outside the org.' },
37
+ 'apex-crud-fls': { effort: 'project', impact: 'Apex skipping CRUD/FLS checks lets callers read or write records and fields they have no rights to.' },
38
+ 'apex-rest-endpoint': { effort: 'project', impact: 'without-sharing @RestResource endpoints expose records to REST callers without record-level access control.' },
39
+ 'visualforce-xss': { effort: 'moderate', impact: 'Unescaped Visualforce merge fields let attackers inject scripts that run in victims’ sessions.' },
40
+ 'certificate-expiry': { effort: 'quick', impact: 'An expired certificate breaks integrations or, if ignored, invites insecure fallback.' },
41
+ 'installed-packages': { effort: 'moderate', impact: 'Unmanaged or beta packages in production can carry unvetted code with broad org access.' },
42
+ 'trusted-ip-ranges': { effort: 'quick', impact: 'Overly broad trusted IP ranges silently exempt large networks from MFA.' },
43
+ 'anonymous-apex-audit': { effort: 'quick', impact: 'Anonymous Apex execution in production can run arbitrary privileged code leaving little trace.' },
44
+ 'debug-log-access': { effort: 'quick', impact: 'Active high-detail debug traces capture sensitive field values readable by anyone with log access.' },
45
+ 'connected-app-inactivity': { effort: 'quick', impact: 'Stale connected apps remain authorized attack surface long after they’re abandoned.' },
46
+ 'my-domain-login-policy': { effort: 'quick', impact: 'Allowing login.salesforce.com login bypasses My Domain SSO enforcement.' },
47
+ 'high-assurance-session': { effort: 'moderate', impact: 'Admin-capable apps without short or high-assurance sessions let a hijacked session retain elevated rights.' },
48
+ 'enhanced-domains': { effort: 'moderate', impact: 'Without Enhanced Domains, cross-org cookie leakage and URL spoofing become possible.' },
49
+ 'internal-user-mfa': { effort: 'quick', impact: 'A stolen or guessed admin password grants full org access with no second factor to stop it.' },
50
+ 'mfa-registration': { effort: 'quick', impact: 'Users with no registered MFA method are effectively single-factor and easily phished.' },
51
+ 'mfa-method-strength': { effort: 'moderate', impact: 'Weak MFA methods such as SMS are bypassable via SIM-swap and real-time phishing.' },
52
+ 'release-updates': { effort: 'quick', impact: 'Ignored release updates leave known-deprecated, sometimes insecure behavior active past its deadline.' },
53
+ 'legacy-api-version': { effort: 'moderate', impact: 'Apex on old API versions and SOAP remote sites carry deprecated, less-secure behavior.' },
54
+ 'connected-app-scope': { effort: 'moderate', impact: 'Full-scope OAuth grants and infinite refresh tokens make a single leaked token catastrophic.' },
55
+ 'transaction-security-policy': { effort: 'moderate', impact: 'Without transaction security policies, automated threats like bulk export or anomalous logins go unblocked.' },
56
+ 'failed-login-detection': { effort: 'quick', impact: 'No brute-force detection means credential-stuffing campaigns run unnoticed until they succeed.' },
57
+ 'experience-cloud-site': { effort: 'moderate', impact: 'Self-registration on live sites lets attackers create their own accounts to probe guest-accessible data.' },
58
+ 'custom-labels-credential': { effort: 'quick', impact: 'Credentials in custom labels are globally readable by all authenticated users via merge fields.' },
59
+ 'report-folder-access': { effort: 'quick', impact: 'Public report folders let any authenticated user view all reports and the data behind them: mass exfiltration.' },
60
+ 'escalation-perms': { effort: 'moderate', impact: 'Lateral-movement permissions let a compromised account grant itself more access and persist.' },
61
+ 'cors-allowlist': { effort: 'quick', impact: 'Wildcard CORS origins let malicious sites make authenticated browser requests against the org.' },
62
+ 'guest-executable-apex': { effort: 'project', impact: 'Unauthenticated web users can execute Apex that bypasses sharing: bulk record exfiltration without login.' },
63
+ 'email-security': { effort: 'quick', impact: 'Unauthenticated inbound email services and all-profile send-as addresses let attackers trigger Apex or spoof internal senders.' },
64
+ 'outbound-messages': { effort: 'quick', impact: 'Outbound messages can ship a live session ID to external endpoints over cleartext: a direct session-hijack and exfiltration path.' },
65
+ 'public-content-exposure': { effort: 'quick', impact: 'Documents marked externally available and public static resources are retrievable without authentication by anyone with the URL.' },
66
+ 'privileged-access': { effort: 'moderate', impact: 'Shadow admins hold full org control outside the admin profile, so a single takeover bypasses admin-focused monitoring and owns everything.' },
67
+ 'separation-of-duties': { effort: 'moderate', impact: 'A single user holding a toxic permission combination can self-escalate, commit fraud, or tamper undetected with no second party to stop them.' },
68
+ };
69
+ export function getCheckMeta(id) {
70
+ return CHECK_META[id];
71
+ }
72
+ //# sourceMappingURL=CheckMeta.js.map
@@ -2,6 +2,8 @@ import type { AuditResult } from '../findings/AuditResult.js';
2
2
  export interface AuditRenderer {
3
3
  readonly format: string;
4
4
  readonly fileExtension: string;
5
+ /** When set, used instead of 'sf-audit' for the output filename (avoids collisions between renderers sharing an extension). */
6
+ readonly filenamePrefix?: string;
5
7
  render(result: AuditResult): string;
6
8
  }
7
9
  //# sourceMappingURL=AuditRenderer.d.ts.map
@@ -0,0 +1,29 @@
1
+ import type { AuditResult } from '../findings/AuditResult.js';
2
+ import type { AuditRenderer } from './AuditRenderer.js';
3
+ import type { Branding } from '../report/branding.js';
4
+ import type { Framework } from '../compliance/types.js';
5
+ export interface ClientReportOptions {
6
+ branding: Branding;
7
+ topN: number;
8
+ frameworks: Framework[];
9
+ }
10
+ export declare class ClientReportRenderer implements AuditRenderer {
11
+ private readonly opts;
12
+ readonly format = "executive";
13
+ readonly fileExtension = ".html";
14
+ readonly filenamePrefix = "SF_Audit_Executive";
15
+ constructor(opts: ClientReportOptions);
16
+ render(result: AuditResult): string;
17
+ private chip;
18
+ private sectionHead;
19
+ private cover;
20
+ private summary;
21
+ private prioritiesSection;
22
+ private scenarios;
23
+ private roadmapSection;
24
+ private worst;
25
+ private matrixSection;
26
+ private findingsAppendix;
27
+ private footer;
28
+ }
29
+ //# sourceMappingURL=ClientReportRenderer.d.ts.map
@@ -0,0 +1,205 @@
1
+ import { esc } from './html-utils.js';
2
+ import { fontFaceCss } from '../report/fonts.js';
3
+ import { getCheckMeta } from '../findings/CheckMeta.js';
4
+ import { selectPriorities } from '../report/ExecutivePriorities.js';
5
+ import { buildRoadmap } from '../report/RemediationRoadmap.js';
6
+ import { buildComplianceMatrix } from '../report/ComplianceMatrix.js';
7
+ const SEV_COLOR = {
8
+ CRITICAL: '#7d3a3a', HIGH: '#a35a2a', MEDIUM: '#8a6d1f', LOW: '#3a5a82', INFO: '#636770',
9
+ };
10
+ const SEV_RANK = { CRITICAL: 0, HIGH: 1, MEDIUM: 2, LOW: 3, INFO: 4 };
11
+ const GRADE_COLOR = {
12
+ A: '#4a7d5e', B: '#4a7d5e', C: '#8a6d1f', D: '#a35a2a', F: '#7d3a3a',
13
+ };
14
+ const SEV_ORDER = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'];
15
+ const FRAMEWORK_LABEL = {
16
+ OWASP: 'OWASP Top 10', SOC2: 'SOC 2', ISO27001: 'ISO/IEC 27001',
17
+ SBS: 'Security Benchmark for Salesforce', PRIVACY_ACT: 'NZ Privacy Act',
18
+ HISO10029: 'HISO 10029', NZISM: 'NZISM', HIPAA: 'HIPAA', GDPR: 'GDPR',
19
+ };
20
+ export class ClientReportRenderer {
21
+ opts;
22
+ format = 'executive';
23
+ fileExtension = '.html';
24
+ filenamePrefix = 'SF_Audit_Executive';
25
+ constructor(opts) {
26
+ this.opts = opts;
27
+ }
28
+ render(result) {
29
+ const b = this.opts.branding;
30
+ const chains = result.attackChains ?? [];
31
+ const chainIds = new Set();
32
+ for (const c of chains)
33
+ for (const s of c.steps)
34
+ chainIds.add(s.findingId);
35
+ const priorities = selectPriorities(result.findings, chainIds, this.opts.topN);
36
+ const roadmap = buildRoadmap(result.findings);
37
+ const matrix = buildComplianceMatrix(result, this.opts.frameworks);
38
+ let n = 0;
39
+ const num = () => String(++n).padStart(2, '0');
40
+ const sections = [
41
+ this.summary(result, num()),
42
+ this.prioritiesSection(priorities, chainIds, num()),
43
+ chains.length ? this.scenarios(chains, num()) : '',
44
+ this.roadmapSection(roadmap, num()),
45
+ matrix.length ? this.matrixSection(matrix, num()) : '',
46
+ this.findingsAppendix(result, num()),
47
+ ].join('\n');
48
+ return `<!DOCTYPE html>
49
+ <html lang="en"><head><meta charset="utf-8"><title>Security Audit: ${esc(result.orgName)}</title>
50
+ <style>${fontFaceCss()}
51
+ :root{--ink:${b.ink};--bg:${b.bg};--bgalt:${b.bgAlt};--muted:${b.muted};--border:${b.border};--primary:${b.primary};
52
+ --display:'${b.fontDisplay}',Georgia,serif;--body:'${b.fontBody}',system-ui,sans-serif;--mono:ui-monospace,'SF Mono',Menlo,monospace;}
53
+ *{box-sizing:border-box}
54
+ html{-webkit-print-color-adjust:exact;print-color-adjust:exact}
55
+ body{font-family:var(--body);color:var(--ink);background:var(--bg);margin:0;line-height:1.6;font-variant-numeric:tabular-nums}
56
+ .wrap{max-width:780px;margin:0 auto;padding:64px 44px}
57
+ h1{font-family:var(--display);font-size:clamp(38px,6vw,52px);line-height:1.02;letter-spacing:-0.02em;margin:6px 0 0}
58
+ h2{font-family:var(--display);font-size:25px;letter-spacing:-0.01em;line-height:1.1;margin:0}
59
+ h3{font-family:var(--display);font-size:18px;letter-spacing:-0.01em;margin:0 0 6px}
60
+ p{margin:0 0 10px;max-width:68ch}
61
+ .label{font-family:var(--mono);text-transform:uppercase;letter-spacing:0.16em;font-size:11px;color:var(--muted)}
62
+ .muted{color:var(--muted)}
63
+ /* cover */
64
+ .cover{padding-bottom:8px}
65
+ .meta{font-family:var(--mono);font-size:11px;letter-spacing:0.12em;color:var(--muted);text-transform:uppercase;margin-top:6px}
66
+ .prepared{font-family:var(--mono);font-size:11px;letter-spacing:0.08em;color:var(--muted);text-transform:uppercase;margin-top:14px}
67
+ /* scorecard */
68
+ .scorecard{display:flex;align-items:center;gap:28px;margin:30px 0 8px;padding:24px 28px;background:var(--bgalt);border:1px solid var(--border);border-radius:12px;break-inside:avoid}
69
+ .grade{font-family:var(--display);font-size:104px;line-height:0.86;font-weight:400}
70
+ .score-num{font-family:var(--display);font-size:34px;line-height:1}
71
+ .score-num span{font-size:18px;color:var(--muted)}
72
+ .chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:10px}
73
+ .chip{font-family:var(--mono);font-size:11px;letter-spacing:0.04em;font-weight:600;color:var(--c);border:1px solid var(--c);border-radius:999px;padding:2px 9px;white-space:nowrap}
74
+ .chip.solid{background:var(--c);color:#fff;border-color:var(--c)}
75
+ .pnum{font-family:var(--mono);color:var(--primary);font-size:13px;letter-spacing:0.05em;margin-right:10px}
76
+ /* section markers */
77
+ .sec{display:flex;align-items:baseline;gap:14px;margin:56px 0 18px;border-bottom:1px solid var(--border);padding-bottom:10px}
78
+ .sec-num{font-family:var(--mono);font-size:13px;letter-spacing:0.1em;color:var(--primary)}
79
+ /* cards */
80
+ .card{background:var(--bgalt);border:1px solid var(--border);border-left:3px solid var(--c,var(--border));border-radius:8px;padding:16px 18px;margin:12px 0;break-inside:avoid}
81
+ .card .row{display:flex;align-items:baseline;justify-content:space-between;gap:12px}
82
+ .scenario{border-left-width:3px}
83
+ /* roadmap */
84
+ .tier{display:flex;align-items:baseline;gap:10px;margin:22px 0 6px}
85
+ .tier h3{margin:0}
86
+ .count{font-family:var(--mono);font-size:11px;color:var(--muted);border:1px solid var(--border);border-radius:999px;padding:1px 8px}
87
+ .tier-list{list-style:none;margin:0;padding:0}
88
+ .tier-list li{display:flex;align-items:baseline;justify-content:space-between;gap:12px;padding:6px 0;border-bottom:1px solid var(--border)}
89
+ /* findings appendix — denser, quieter */
90
+ .find{padding:12px 0;border-bottom:1px solid var(--border)}
91
+ .find h3{font-family:var(--body);font-size:15px;font-weight:600;margin:0 0 3px}
92
+ .find p{font-size:13px;color:var(--muted);margin:0}
93
+ .matrix{width:100%;border-collapse:collapse;margin:8px 0 22px;font-size:13px}
94
+ .matrix th{text-align:left;font-family:var(--mono);text-transform:uppercase;letter-spacing:0.08em;font-size:10px;color:var(--muted);border-bottom:1px solid var(--border);padding:6px 8px}
95
+ .matrix td{border-bottom:1px solid var(--border);padding:7px 8px;vertical-align:top}
96
+ .matrix .cid{font-family:var(--mono);font-size:12px;color:var(--primary);white-space:nowrap}
97
+ .matrix .st{text-align:right;white-space:nowrap}
98
+ footer{margin-top:56px;border-top:1px solid var(--border);padding-top:18px;color:var(--muted);font-size:12px;line-height:1.55}
99
+ footer .label{display:block;margin-bottom:6px;color:var(--ink)}
100
+ @page{margin:18mm}
101
+ @media print{.wrap{padding:0 0 24px}.sec{break-after:avoid}.card,.scorecard{break-inside:avoid}}
102
+ </style></head><body><div class="wrap">
103
+ ${this.cover(result, b)}
104
+ ${sections}
105
+ ${this.footer(b)}
106
+ </div></body></html>`;
107
+ }
108
+ chip(sev, text) {
109
+ const solid = sev === 'CRITICAL' ? ' solid' : '';
110
+ return `<span class="chip${solid}" style="--c:${SEV_COLOR[sev]}">${esc(text)}</span>`;
111
+ }
112
+ sectionHead(numStr, title) {
113
+ return `<div class="sec"><span class="sec-num">${numStr} /</span><h2>${esc(title)}</h2></div>`;
114
+ }
115
+ cover(r, b) {
116
+ const meta = [r.orgName, r.orgType, r.orgId, r.generatedAt.toISOString().slice(0, 10)]
117
+ .map((s) => esc(String(s))).join(' · ');
118
+ const counts = SEV_ORDER
119
+ .map((l) => ({ l, n: r.findings.filter((f) => f.riskLevel === l && !f.passed && !f.inconclusive).length }))
120
+ .filter((c) => c.n > 0)
121
+ .map((c) => this.chip(c.l, `${c.n} ${c.l}`)).join('');
122
+ const prepared = b.preparedFor ? ` for ${esc(b.preparedFor)}` : '';
123
+ return `<header class="cover">
124
+ <div class="label">${esc(b.firmName)}</div>
125
+ <h1>Salesforce Security Audit</h1>
126
+ <div class="meta">${meta}</div>
127
+ <div class="scorecard" style="border-left:4px solid ${GRADE_COLOR[r.grade] ?? b.primary}">
128
+ <div class="grade" style="color:${GRADE_COLOR[r.grade] ?? b.primary}">${esc(r.grade)}</div>
129
+ <div>
130
+ <div class="label">Security grade · health score</div>
131
+ <div class="score-num">${r.healthScore}<span>/100</span></div>
132
+ <div class="chips">${counts || this.chip('LOW', 'No active findings')}</div>
133
+ </div>
134
+ </div>
135
+ <div class="prepared">Prepared by ${esc(b.firmName)}${prepared}</div></header>`;
136
+ }
137
+ summary(r, numStr) {
138
+ const incon = r.findings.filter((f) => f.inconclusive).length;
139
+ const active = r.findings.filter((f) => !f.passed && !f.inconclusive).length;
140
+ return `${this.sectionHead(numStr, 'Executive Summary')}
141
+ <p>This audit assessed the org’s security configuration and scored it <strong>${r.healthScore}/100 (Grade ${esc(r.grade)})</strong> across ${active} active finding${active === 1 ? '' : 's'}${incon ? `, with ${incon} inconclusive (insufficient access)` : ''}. The priorities below are the highest-impact items to address first; the remediation roadmap groups every fix by effort. See Scope &amp; Liability for the basis and limits of this assessment.</p>`;
142
+ }
143
+ prioritiesSection(priorities, chainIds, numStr) {
144
+ const head = this.sectionHead(numStr, 'Executive Priorities');
145
+ if (priorities.length === 0)
146
+ return `${head}<p class="muted">No active findings to prioritise.</p>`;
147
+ const items = priorities.map((f, i) => {
148
+ const meta = f.checkId ? getCheckMeta(f.checkId) : undefined;
149
+ const chained = chainIds.has(f.id) ? '<p class="muted">Part of an attack chain. See Attack Scenarios.</p>' : '';
150
+ const impact = meta ? `<p><strong>Impact:</strong> ${esc(meta.impact)}</p>` : '';
151
+ return `<div class="card" style="--c:${SEV_COLOR[f.riskLevel]}">
152
+ <div class="row"><h3><span class="pnum">${String(i + 1).padStart(2, '0')}</span>${esc(f.title)}</h3>${this.chip(f.riskLevel, f.riskLevel)}</div>
153
+ ${impact}${chained}<p><strong>Fix:</strong> ${esc(f.remediation)}</p></div>`;
154
+ }).join('');
155
+ return `${head}<p class="muted">Focus areas, highest impact first.</p>${items}`;
156
+ }
157
+ scenarios(chains, numStr) {
158
+ const items = chains.map((c) => `<div class="card scenario" style="--c:${SEV_COLOR[c.severity]}">
159
+ <div class="row"><h3>${esc(c.title)}</h3>${this.chip(c.severity, c.severity)}</div>
160
+ <p>${esc(c.narrative)}</p><p><strong>Breaks the chain:</strong> ${esc(c.remediation)}</p></div>`).join('');
161
+ return `${this.sectionHead(numStr, 'Attack Scenarios')}<p class="muted">How findings combine into real attack paths.</p>${items}`;
162
+ }
163
+ roadmapSection(roadmap, numStr) {
164
+ const tier = (label, sub, arr) => {
165
+ if (arr.length === 0)
166
+ return '';
167
+ const rows = arr.map((f) => `<li><span>${esc(f.title)}</span>${this.chip(f.riskLevel, f.riskLevel)}</li>`).join('');
168
+ return `<div class="tier"><h3>${esc(label)}</h3><span class="count">${arr.length} · ${esc(sub)}</span></div><ul class="tier-list">${rows}</ul>`;
169
+ };
170
+ return `${this.sectionHead(numStr, 'Remediation Roadmap')}
171
+ ${tier('Quick wins', '≤1 day', roadmap.quick)}
172
+ ${tier('Moderate', 'days', roadmap.moderate)}
173
+ ${tier('Projects', 'weeks', roadmap.project)}`;
174
+ }
175
+ worst(findings) {
176
+ return findings.slice().sort((a, b) => SEV_RANK[a.riskLevel] - SEV_RANK[b.riskLevel])[0]?.riskLevel;
177
+ }
178
+ matrixSection(matrix, numStr) {
179
+ const blocks = matrix.map((fm) => {
180
+ const rows = fm.rows.map((row) => {
181
+ const w = this.worst(row.findings);
182
+ const status = w
183
+ ? this.chip(w, `${row.findings.length} finding${row.findings.length === 1 ? '' : 's'}`)
184
+ : '<span class="muted">No findings detected</span>';
185
+ return `<tr><td class="cid">${esc(row.control.id)}</td><td>${esc(row.control.title)}</td><td class="st">${status}</td></tr>`;
186
+ }).join('');
187
+ return `<h3>${esc(FRAMEWORK_LABEL[fm.framework])} <span class="muted">· ${esc(fm.version)}</span></h3>
188
+ <table class="matrix"><thead><tr><th>Control</th><th>Requirement area</th><th>Status</th></tr></thead><tbody>${rows}</tbody></table>`;
189
+ }).join('');
190
+ return `${this.sectionHead(numStr, 'Compliance Coverage')}<p class="muted">Findings mapped to framework controls. “No findings detected” is not an attestation of compliance. See Scope &amp; Liability.</p>${blocks}`;
191
+ }
192
+ findingsAppendix(r, numStr) {
193
+ const rows = r.findings.map((f) => {
194
+ const tag = f.inconclusive ? this.chip('INFO', 'inconclusive') : f.passed ? this.chip('INFO', 'passed') : this.chip(f.riskLevel, f.riskLevel);
195
+ return `<div class="find"><div class="row"><h3>${esc(f.title)}</h3>${tag}</div>
196
+ <p>${esc(f.detail)}</p><p><strong>Remediation:</strong> ${esc(f.remediation)}</p></div>`;
197
+ }).join('');
198
+ return `${this.sectionHead(numStr, 'All Findings')}${rows}`;
199
+ }
200
+ footer(b) {
201
+ return `<footer><span class="label">Scope &amp; Liability</span>
202
+ Read-only, point-in-time configuration review: not a penetration test, not a code audit. The grade is a prioritisation aid, not a certification. Validate findings before remediation. © ${new Date().getFullYear()} ${esc(b.firmName)} · ${esc(b.contact)}</footer>`;
203
+ }
204
+ }
205
+ //# sourceMappingURL=ClientReportRenderer.js.map
@@ -84,7 +84,7 @@ export class DiffHtmlRenderer {
84
84
  <head>
85
85
  <meta charset="UTF-8">
86
86
  <meta name="viewport" content="width=device-width,initial-scale=1">
87
- <title>SF Audit Diff — ${esc(baseline.orgName)}</title>
87
+ <title>SF Audit Diff: ${esc(baseline.orgName)}</title>
88
88
  <style>
89
89
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
90
90
  body { font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; background: #0d1117; color: #c9d1d9; max-width: 1000px; margin: 2rem auto; padding: 0 1.25rem 4rem; line-height: 1.6; }
@@ -64,7 +64,7 @@ export class HistoryRenderer {
64
64
  <head>
65
65
  <meta charset="UTF-8">
66
66
  <meta name="viewport" content="width=device-width,initial-scale=1">
67
- <title>SF Audit History — ${orgName}</title>
67
+ <title>SF Audit History: ${orgName}</title>
68
68
  <script src="https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js"></script>
69
69
  <style>
70
70
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
@@ -1,3 +1,4 @@
1
+ import { esc } from './html-utils.js';
1
2
  const RISK_COLORS = {
2
3
  CRITICAL: '#dc2626',
3
4
  HIGH: '#ea580c',
@@ -17,13 +18,6 @@ const PASS_BG = 'rgba(34,197,94,0.10)';
17
18
  const GRADE_COLOR = {
18
19
  A: '#22c55e', B: '#84cc16', C: '#eab308', D: '#f97316', F: '#ef4444',
19
20
  };
20
- function esc(str) {
21
- return str
22
- .replace(/&/g, '&amp;')
23
- .replace(/</g, '&lt;')
24
- .replace(/>/g, '&gt;')
25
- .replace(/"/g, '&quot;');
26
- }
27
21
  // ── Dashboard helpers ────────────────────────────────────────────────────────
28
22
  function statusColor(value, warnThreshold, dangerThreshold) {
29
23
  if (value <= warnThreshold)
@@ -171,7 +165,7 @@ export class HtmlRenderer {
171
165
  .map((c) => {
172
166
  const conf = c.confidence === 'named' ? '' : ' (potential)';
173
167
  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>`)
168
+ .map((s, i) => `<li><strong>${escStr(s.title ?? s.findingId)}</strong> (${escStr(s.severity ?? '—')}): grants <code>${escStr(s.capability)}</code></li>`)
175
169
  .join('');
176
170
  return `<div class="attack-chain severity-${c.severity.toLowerCase()}">
177
171
  <h3>[${escStr(c.severity)}] ${escStr(c.title)}${conf}</h3>
@@ -247,7 +241,7 @@ export class HtmlRenderer {
247
241
  <head>
248
242
  <meta charset="UTF-8">
249
243
  <meta name="viewport" content="width=device-width,initial-scale=1">
250
- <title>SF Security Audit — ${esc(result.orgName)}</title>
244
+ <title>SF Security Audit: ${esc(result.orgName)}</title>
251
245
  <link rel="preconnect" href="https://fonts.googleapis.com">
252
246
  <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">
253
247
  <style>
@@ -569,7 +563,7 @@ export class HtmlRenderer {
569
563
  });
570
564
  </script>
571
565
  <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.
566
+ <strong>Offline-first audit:</strong> all analysis performed locally; no data is transmitted outside your Salesforce org. Generated by CloudCounsel SF Audit.
573
567
  </div>
574
568
  </body>
575
569
  </html>`;
@@ -26,7 +26,7 @@ export class MarkdownRenderer {
26
26
  lines.push('**Steps:**');
27
27
  lines.push('');
28
28
  c.steps.forEach((s, i) => {
29
- lines.push(`${i + 1}. **${s.title ?? s.findingId}** (${s.severity ?? '—'}) — grants \`${s.capability}\``);
29
+ lines.push(`${i + 1}. **${s.title ?? s.findingId}** (${s.severity ?? '—'}): grants \`${s.capability}\``);
30
30
  });
31
31
  lines.push('');
32
32
  lines.push(`**Remediation:** ${c.remediation}`);
@@ -79,7 +79,7 @@ export class MarkdownRenderer {
79
79
  lines.push('');
80
80
  lines.push('---');
81
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.');
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
83
  lines.push('');
84
84
  return lines.join('\n');
85
85
  }
@@ -0,0 +1,2 @@
1
+ export declare function esc(str: string): string;
2
+ //# sourceMappingURL=html-utils.d.ts.map
@@ -0,0 +1,8 @@
1
+ export function esc(str) {
2
+ return str
3
+ .replace(/&/g, '&amp;')
4
+ .replace(/</g, '&lt;')
5
+ .replace(/>/g, '&gt;')
6
+ .replace(/"/g, '&quot;');
7
+ }
8
+ //# sourceMappingURL=html-utils.js.map
@@ -0,0 +1,19 @@
1
+ import type { AuditResult } from '../findings/AuditResult.js';
2
+ import type { Finding } from '../findings/Finding.js';
3
+ import type { ControlDef, Framework } from '../compliance/types.js';
4
+ export interface MatrixRow {
5
+ control: ControlDef;
6
+ findings: Finding[];
7
+ }
8
+ export interface FrameworkMatrix {
9
+ framework: Framework;
10
+ version: string;
11
+ rows: MatrixRow[];
12
+ }
13
+ /**
14
+ * Invert the check→control mapping into framework→control→findings, for verified controls
15
+ * in the selected frameworks only. A control is "in scope" if any check maps to it; its row
16
+ * carries the active (non-passed, non-inconclusive) findings whose check maps to that control.
17
+ */
18
+ export declare function buildComplianceMatrix(result: AuditResult, frameworks: Framework[]): FrameworkMatrix[];
19
+ //# sourceMappingURL=ComplianceMatrix.d.ts.map
@@ -0,0 +1,47 @@
1
+ import { CHECK_CONTROL_MAP } from '../compliance/mapping.js';
2
+ import { getControl } from '../compliance/catalogs/index.js';
3
+ /**
4
+ * Invert the check→control mapping into framework→control→findings, for verified controls
5
+ * in the selected frameworks only. A control is "in scope" if any check maps to it; its row
6
+ * carries the active (non-passed, non-inconclusive) findings whose check maps to that control.
7
+ */
8
+ export function buildComplianceMatrix(result, frameworks) {
9
+ const fwSet = new Set(frameworks);
10
+ const active = result.findings.filter((f) => !f.passed && !f.inconclusive);
11
+ const inScope = new Map();
12
+ const hits = new Map();
13
+ for (const controlIds of Object.values(CHECK_CONTROL_MAP)) {
14
+ for (const id of controlIds) {
15
+ const c = getControl(id);
16
+ if (!c || !c.verified || !fwSet.has(c.framework))
17
+ continue;
18
+ inScope.set(id, c);
19
+ if (!hits.has(id))
20
+ hits.set(id, []);
21
+ }
22
+ }
23
+ for (const f of active) {
24
+ if (!f.checkId)
25
+ continue;
26
+ for (const id of CHECK_CONTROL_MAP[f.checkId] ?? []) {
27
+ if (hits.has(id))
28
+ hits.get(id).push(f);
29
+ }
30
+ }
31
+ const byFw = new Map();
32
+ for (const [id, control] of inScope) {
33
+ const rows = byFw.get(control.framework) ?? [];
34
+ rows.push({ control, findings: hits.get(id) ?? [] });
35
+ byFw.set(control.framework, rows);
36
+ }
37
+ const out = [];
38
+ for (const fw of frameworks) {
39
+ const rows = byFw.get(fw);
40
+ if (!rows || rows.length === 0)
41
+ continue;
42
+ rows.sort((a, b) => a.control.id.localeCompare(b.control.id, undefined, { numeric: true }));
43
+ out.push({ framework: fw, version: rows[0].control.version, rows });
44
+ }
45
+ return out;
46
+ }
47
+ //# sourceMappingURL=ComplianceMatrix.js.map
@@ -0,0 +1,8 @@
1
+ import type { Finding } from '../findings/Finding.js';
2
+ /**
3
+ * Select the top-N findings to surface as executive priorities.
4
+ * Order: severity, then findings that participate in an attack chain, then title.
5
+ * Excludes passed and inconclusive findings.
6
+ */
7
+ export declare function selectPriorities(findings: Finding[], chainFindingIds: Set<string>, topN: number): Finding[];
8
+ //# sourceMappingURL=ExecutivePriorities.d.ts.map
@@ -0,0 +1,22 @@
1
+ const RANK = { CRITICAL: 0, HIGH: 1, MEDIUM: 2, LOW: 3, INFO: 4 };
2
+ /**
3
+ * Select the top-N findings to surface as executive priorities.
4
+ * Order: severity, then findings that participate in an attack chain, then title.
5
+ * Excludes passed and inconclusive findings.
6
+ */
7
+ export function selectPriorities(findings, chainFindingIds, topN) {
8
+ return findings
9
+ .filter((f) => !f.passed && !f.inconclusive)
10
+ .slice()
11
+ .sort((a, b) => {
12
+ if (RANK[a.riskLevel] !== RANK[b.riskLevel])
13
+ return RANK[a.riskLevel] - RANK[b.riskLevel];
14
+ const ac = chainFindingIds.has(a.id) ? 0 : 1;
15
+ const bc = chainFindingIds.has(b.id) ? 0 : 1;
16
+ if (ac !== bc)
17
+ return ac - bc;
18
+ return a.title.localeCompare(b.title);
19
+ })
20
+ .slice(0, topN);
21
+ }
22
+ //# sourceMappingURL=ExecutivePriorities.js.map