@cclabsnz/sf-audit 1.16.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +172 -1
- package/PERMISSIONS.md +139 -0
- package/README.md +98 -26
- package/config/scoring.sample.json +104 -5
- package/docs/permissionset/SF_Audit_ReadOnly.permissionset-meta.xml +54 -0
- package/lib/apps/analyzeApps.d.ts +8 -2
- package/lib/apps/analyzeApps.js +7 -2
- package/lib/apps/apiLogSource.d.ts +39 -0
- package/lib/apps/apiLogSource.js +75 -0
- package/lib/apps/appResolver.js +30 -4
- package/lib/apps/grantedAccess.js +16 -3
- package/lib/apps/leastPrivilege.d.ts +3 -1
- package/lib/apps/leastPrivilege.js +7 -3
- package/lib/apps/permissionSetGenerator.d.ts +22 -0
- package/lib/apps/permissionSetGenerator.js +100 -0
- package/lib/apps/types.d.ts +6 -0
- package/lib/apps/usageCollector.d.ts +7 -1
- package/lib/apps/usageCollector.js +57 -26
- package/lib/chains/CapabilityRegistry.js +26 -0
- package/lib/chains/ChainEngine.js +11 -1
- package/lib/chains/namedChains.js +130 -24
- package/lib/checks/CheckEngine.d.ts +3 -1
- package/lib/checks/CheckEngine.js +65 -26
- package/lib/checks/impl/AgentUserPrivilegeCheck.js +5 -4
- package/lib/checks/impl/AnonymousApexAuditCheck.js +41 -8
- package/lib/checks/impl/ApexCrudFLSCheck.js +45 -10
- package/lib/checks/impl/ApexSharingCheck.js +19 -26
- package/lib/checks/impl/ApiClientPermissionCheck.js +21 -5
- package/lib/checks/impl/AuditTrailCheck.js +23 -8
- package/lib/checks/impl/AuthProviderRegistrationHandlerCheck.d.ts +10 -0
- package/lib/checks/impl/AuthProviderRegistrationHandlerCheck.js +131 -0
- package/lib/checks/impl/CertificateExpiryCheck.js +2 -1
- package/lib/checks/impl/ConnectedAppScopeCheck.js +61 -5
- package/lib/checks/impl/ConnectedAppsCheck.js +60 -5
- package/lib/checks/impl/ContentLinksCheck.js +33 -9
- package/lib/checks/impl/CorsAllowlistCheck.js +3 -2
- package/lib/checks/impl/DataClassificationCheck.js +15 -13
- package/lib/checks/impl/DataCloudDataSpaceIsolationCheck.d.ts +10 -0
- package/lib/checks/impl/DataCloudDataSpaceIsolationCheck.js +116 -0
- package/lib/checks/impl/DebugLogAccessCheck.js +4 -4
- package/lib/checks/impl/DelegatedAdministrationGroupsCheck.d.ts +10 -0
- package/lib/checks/impl/DelegatedAdministrationGroupsCheck.js +76 -0
- package/lib/checks/impl/DelegatedAuthenticationExposureCheck.d.ts +10 -0
- package/lib/checks/impl/DelegatedAuthenticationExposureCheck.js +105 -0
- package/lib/checks/impl/DeploymentIdentityCheck.js +32 -5
- package/lib/checks/impl/EmailSecurityCheck.d.ts +1 -1
- package/lib/checks/impl/EmailSecurityCheck.js +14 -34
- package/lib/checks/impl/EncryptionCoverageCheck.js +21 -15
- package/lib/checks/impl/EnhancedDomainsCheck.js +17 -2
- package/lib/checks/impl/EscalationPermsCheck.d.ts +2 -0
- package/lib/checks/impl/EscalationPermsCheck.js +88 -21
- package/lib/checks/impl/ExperienceCloudSiteCheck.js +56 -5
- package/lib/checks/impl/ExternalAccountHierarchyExposureCheck.d.ts +10 -0
- package/lib/checks/impl/ExternalAccountHierarchyExposureCheck.js +65 -0
- package/lib/checks/impl/ExternalCredentialsCheck.js +6 -3
- package/lib/checks/impl/FailedLoginCheck.js +36 -9
- package/lib/checks/impl/FieldHistoryTrackingCheck.js +14 -11
- package/lib/checks/impl/FlowHttpCalloutCredentialBypassCheck.d.ts +10 -0
- package/lib/checks/impl/FlowHttpCalloutCredentialBypassCheck.js +115 -0
- package/lib/checks/impl/GenAiPromptTemplateGroundingCheck.d.ts +10 -0
- package/lib/checks/impl/GenAiPromptTemplateGroundingCheck.js +227 -0
- package/lib/checks/impl/GuestExecutableApexCheck.d.ts +1 -1
- package/lib/checks/impl/GuestExecutableApexCheck.js +105 -14
- package/lib/checks/impl/GuestRecordAccessPolicyCheck.js +52 -11
- package/lib/checks/impl/HardcodedCredentialsCheck.js +7 -2
- package/lib/checks/impl/HealthCheckCheck.js +1 -0
- package/lib/checks/impl/HighAssuranceSessionCheck.js +16 -11
- package/lib/checks/impl/InactiveUsersCheck.js +1 -1
- package/lib/checks/impl/InboundEmailHandlerExposureCheck.d.ts +10 -0
- package/lib/checks/impl/InboundEmailHandlerExposureCheck.js +136 -0
- package/lib/checks/impl/IntegrationLeastPrivilegeCheck.js +7 -6
- package/lib/checks/impl/InternalUserMfaCheck.js +26 -8
- package/lib/checks/impl/IpRestrictionsCheck.js +35 -16
- package/lib/checks/impl/LoginAccessPolicyCheck.js +5 -4
- package/lib/checks/impl/LoginAnomalyCheck.js +10 -7
- package/lib/checks/impl/LoginSessionCheck.js +2 -0
- package/lib/checks/impl/MfaEnforcementCheck.js +23 -6
- package/lib/checks/impl/MfaMethodStrengthCheck.js +18 -3
- package/lib/checks/impl/MfaRegistrationCheck.js +4 -3
- package/lib/checks/impl/MyDomainLoginPolicyCheck.js +23 -10
- package/lib/checks/impl/OauthDeviceAndAssetTokenFlowsCheck.d.ts +10 -0
- package/lib/checks/impl/OauthDeviceAndAssetTokenFlowsCheck.js +84 -0
- package/lib/checks/impl/OrgWideEmailSpoofingCheck.d.ts +10 -0
- package/lib/checks/impl/OrgWideEmailSpoofingCheck.js +106 -0
- package/lib/checks/impl/OutboundMessagesCheck.js +48 -6
- package/lib/checks/impl/PackagePostInstallSupplyChainCheck.d.ts +10 -0
- package/lib/checks/impl/PackagePostInstallSupplyChainCheck.js +89 -0
- package/lib/checks/impl/PlatformEventSubscriberContextCheck.d.ts +10 -0
- package/lib/checks/impl/PlatformEventSubscriberContextCheck.js +88 -0
- package/lib/checks/impl/PrivilegedAccessCheck.js +12 -5
- package/lib/checks/impl/ReleaseUpdatesCheck.js +18 -3
- package/lib/checks/impl/RemoteSitesCheck.js +4 -4
- package/lib/checks/impl/RestrictionRulesIntegrityCheck.d.ts +10 -0
- package/lib/checks/impl/RestrictionRulesIntegrityCheck.js +105 -0
- package/lib/checks/impl/SeparationOfDutiesCheck.js +14 -3
- package/lib/checks/impl/ShieldTenantSecretLifecycleCheck.d.ts +10 -0
- package/lib/checks/impl/ShieldTenantSecretLifecycleCheck.js +90 -0
- package/lib/checks/impl/SoapLoginApiAuthCheck.js +20 -8
- package/lib/checks/impl/SsoEnforcementCheck.js +16 -5
- package/lib/checks/impl/TransactionSecurityPolicyCheck.js +5 -5
- package/lib/checks/impl/TrustedIPRangesCheck.js +18 -9
- package/lib/checks/impl/UsersAndAdminsCheck.js +24 -4
- package/lib/checks/permCatalog.js +1 -1
- package/lib/checks/registry.js +30 -0
- package/lib/checks/support/apexAccess.d.ts +56 -0
- package/lib/checks/support/apexAccess.js +127 -0
- package/lib/checks/support/missingObject.d.ts +13 -0
- package/lib/checks/support/missingObject.js +37 -0
- package/lib/checks/support/schema.d.ts +17 -0
- package/lib/checks/support/schema.js +41 -0
- package/lib/commands/audit/apps.d.ts +1 -0
- package/lib/commands/audit/apps.js +86 -30
- package/lib/commands/audit/diff.js +2 -2
- package/lib/commands/audit/events/pull.js +3 -1
- package/lib/commands/audit/history.js +2 -2
- package/lib/commands/audit/incident/collect.js +3 -1
- package/lib/commands/audit/incident/report.js +2 -2
- package/lib/commands/audit/security.d.ts +3 -0
- package/lib/commands/audit/security.js +65 -10
- package/lib/commands/audit/timeline.js +2 -2
- package/lib/compliance/mapping.js +28 -7
- package/lib/findings/AuditResult.d.ts +10 -0
- package/lib/findings/CheckMeta.js +15 -0
- package/lib/findings/Finding.d.ts +4 -0
- package/lib/findings/ScoringConfig.d.ts +10 -8
- package/lib/findings/ScoringConfig.js +12 -5
- package/lib/findings/coverage.d.ts +34 -0
- package/lib/findings/coverage.js +42 -0
- package/lib/findings/exitCode.js +1 -1
- package/lib/findings/loadScoringConfig.js +51 -8
- package/lib/findings/scoring.js +61 -10
- package/lib/history/HistoryStore.js +9 -3
- package/lib/history/archivePolicy.d.ts +19 -0
- package/lib/history/archivePolicy.js +34 -0
- package/lib/incident/bundleIo.js +4 -3
- package/lib/incident/collect/collectBundle.d.ts +1 -1
- package/lib/incident/collect/collectBundle.js +4 -3
- package/lib/incident/collect/streamGuestLogs.d.ts +1 -1
- package/lib/incident/collect/streamGuestLogs.js +3 -2
- package/lib/incident/csv.js +4 -4
- package/lib/incident/render/evidence.js +3 -3
- package/lib/incident/render/html.js +2 -3
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/lib/packageInfo.d.ts +6 -0
- package/lib/lib/packageInfo.js +19 -0
- package/lib/preflight/permissionMap.d.ts +2 -20
- package/lib/preflight/permissionMap.js +2 -43
- package/lib/preflight/permissions.d.ts +25 -0
- package/lib/preflight/permissions.js +50 -0
- package/lib/renderers/AttackChainDagRenderer.d.ts +7 -0
- package/lib/renderers/AttackChainDagRenderer.js +139 -0
- package/lib/renderers/ClientReportRenderer.d.ts +2 -0
- package/lib/renderers/ClientReportRenderer.js +34 -6
- package/lib/renderers/DiffHtmlRenderer.js +2 -7
- package/lib/renderers/HistoryRenderer.js +19 -11
- package/lib/renderers/HtmlRenderer.js +23 -6
- package/lib/renderers/MarkdownRenderer.js +11 -1
- package/lib/renderers/SarifRenderer.d.ts +43 -0
- package/lib/renderers/SarifRenderer.js +250 -0
- package/lib/report/ExecutivePriorities.js +1 -1
- package/lib/report/RemediationRoadmap.d.ts +5 -1
- package/lib/report/RemediationRoadmap.js +6 -2
- package/lib/waivers/WaiverLoader.d.ts +28 -0
- package/lib/waivers/WaiverLoader.js +103 -0
- package/lib/waivers/WaiverModel.d.ts +32 -0
- package/lib/waivers/WaiverModel.js +28 -0
- package/lib/waivers/applyWaivers.d.ts +22 -0
- package/lib/waivers/applyWaivers.js +85 -0
- package/package.json +6 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
/**
|
|
3
|
+
* This plugin's own name and version, read from its package.json so that output which
|
|
4
|
+
* identifies the tool (e.g. the SARIF driver) never drifts from the published release.
|
|
5
|
+
*
|
|
6
|
+
* Resolved relative to this module, which sits two levels below the package root in both
|
|
7
|
+
* `src/lib/` (tests) and `lib/lib/` (the published build). package.json always ships in the
|
|
8
|
+
* npm tarball, whatever `files` says.
|
|
9
|
+
*/
|
|
10
|
+
const requireFrom = createRequire(import.meta.url);
|
|
11
|
+
let cached;
|
|
12
|
+
export function packageInfo() {
|
|
13
|
+
if (cached)
|
|
14
|
+
return cached;
|
|
15
|
+
const pkg = requireFrom('../../package.json');
|
|
16
|
+
cached = { name: pkg.name, version: pkg.version };
|
|
17
|
+
return cached;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=packageInfo.js.map
|
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import type { AuditCache } from '@cclabsnz/sf-core';
|
|
2
1
|
import type { SecurityCheck } from '../checks/SecurityCheck.js';
|
|
3
|
-
export type AuditPermission
|
|
4
|
-
|
|
5
|
-
/** Field on UserPermissionAccess carrying the effective grant. */
|
|
6
|
-
readonly field: string;
|
|
7
|
-
readonly label: string;
|
|
8
|
-
/** What the audit loses without it. */
|
|
9
|
-
readonly impact: string;
|
|
10
|
-
/**
|
|
11
|
-
* Cache keys whose producers and consumers need this permission. The affected
|
|
12
|
-
* check list is derived from the registry via these keys rather than hand-written,
|
|
13
|
-
* so a check added later is covered without touching this file.
|
|
14
|
-
*
|
|
15
|
-
* Empty for permissions too broad to attribute to specific checks.
|
|
16
|
-
*/
|
|
17
|
-
readonly cacheKeys: ReadonlyArray<keyof AuditCache>;
|
|
18
|
-
/** The audit cannot run at all without this. */
|
|
19
|
-
readonly blocking?: boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare const AUDIT_PERMISSIONS: Readonly<Record<AuditPermission, PermissionSpec>>;
|
|
2
|
+
export { AUDIT_PERMISSIONS, type AuditPermission, type PermissionSpec } from './permissions.js';
|
|
3
|
+
import { type AuditPermission } from './permissions.js';
|
|
22
4
|
export interface MissingPermission {
|
|
23
5
|
permission: AuditPermission;
|
|
24
6
|
label: string;
|
|
@@ -1,47 +1,6 @@
|
|
|
1
1
|
import { CHECKS } from '../checks/registry.js';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
field: 'PermissionsApiEnabled',
|
|
5
|
-
label: 'API Enabled',
|
|
6
|
-
impact: 'All access is via SOQL/Tooling/REST. Without it the audit cannot run at all.',
|
|
7
|
-
cacheKeys: [],
|
|
8
|
-
blocking: true,
|
|
9
|
-
},
|
|
10
|
-
ViewSetup: {
|
|
11
|
-
field: 'PermissionsViewSetup',
|
|
12
|
-
label: 'View Setup and Configuration',
|
|
13
|
-
impact: 'Reads the bulk of the surface — connected apps, remote sites, CSP, named credentials, auth config, ' +
|
|
14
|
-
'Experience sites, and Tooling metadata. Most setup and configuration checks return inconclusive without it.',
|
|
15
|
-
cacheKeys: [],
|
|
16
|
-
},
|
|
17
|
-
ViewAllUsers: {
|
|
18
|
-
field: 'PermissionsViewAllUsers',
|
|
19
|
-
label: 'View All Users',
|
|
20
|
-
impact: 'Enumerates every User, PermissionSetAssignment and TwoFactorInfo org-wide. Without it the user, ' +
|
|
21
|
-
'admin and MFA checks under-count and miss accounts outside the role hierarchy.',
|
|
22
|
-
cacheKeys: ['mfaRegistrations', 'effectivePermissions'],
|
|
23
|
-
},
|
|
24
|
-
ViewHealthCheckScreen: {
|
|
25
|
-
field: 'PermissionsViewHealthCheck',
|
|
26
|
-
label: 'View Health Check',
|
|
27
|
-
impact: 'Reads SecurityHealthCheck and its risks. Health Check and password/session baselines are inconclusive without it.',
|
|
28
|
-
cacheKeys: ['healthCheckRisks'],
|
|
29
|
-
},
|
|
30
|
-
AuthorApex: {
|
|
31
|
-
field: 'PermissionsAuthorApex',
|
|
32
|
-
label: 'Author Apex (read-only use)',
|
|
33
|
-
impact: 'The only standard gate exposing ApexClass/ApexTrigger/ApexPage Body via the Tooling API. ' +
|
|
34
|
-
'Grants no ability to modify org data. The code-security checks are inconclusive without it.',
|
|
35
|
-
cacheKeys: ['apexBodies', 'vfPageBodies'],
|
|
36
|
-
},
|
|
37
|
-
ViewEventLogFiles: {
|
|
38
|
-
field: 'PermissionsViewEventLogFiles',
|
|
39
|
-
label: 'View Event Log Files',
|
|
40
|
-
impact: 'Reads EventLogFile. Whether login and API activity is monitored cannot be established without it.',
|
|
41
|
-
cacheKeys: ['eventLogSummary'],
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
const usesKey = (check, key) => (check.dependsOnCache?.includes(key) ?? false) || (check.populatesCache?.includes(key) ?? false);
|
|
2
|
+
export { AUDIT_PERMISSIONS } from './permissions.js';
|
|
3
|
+
import { AUDIT_PERMISSIONS, usesKey } from './permissions.js';
|
|
45
4
|
/** Check ids that need `permission`, derived from the registry's declared cache wiring. */
|
|
46
5
|
export function checksRequiring(permission, checks = CHECKS) {
|
|
47
6
|
const { cacheKeys } = AUDIT_PERMISSIONS[permission];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AuditCache } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { SecurityCheck } from '../checks/SecurityCheck.js';
|
|
3
|
+
export type AuditPermission = 'ApiEnabled' | 'ViewSetup' | 'ViewAllUsers' | 'ViewHealthCheckScreen' | 'AuthorApex' | 'ViewEventLogFiles';
|
|
4
|
+
export interface PermissionSpec {
|
|
5
|
+
/** Field on UserPermissionAccess carrying the effective grant. */
|
|
6
|
+
readonly field: string;
|
|
7
|
+
readonly label: string;
|
|
8
|
+
/** What the audit loses without it. */
|
|
9
|
+
readonly impact: string;
|
|
10
|
+
/**
|
|
11
|
+
* Cache keys whose producers and consumers need this permission. The affected
|
|
12
|
+
* check list is derived from the registry via these keys rather than hand-written,
|
|
13
|
+
* so a check added later is covered without touching this file.
|
|
14
|
+
*
|
|
15
|
+
* Empty for permissions too broad to attribute to specific checks.
|
|
16
|
+
*/
|
|
17
|
+
readonly cacheKeys: ReadonlyArray<keyof AuditCache>;
|
|
18
|
+
/** The audit cannot run at all without this. */
|
|
19
|
+
readonly blocking?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const AUDIT_PERMISSIONS: Readonly<Record<AuditPermission, PermissionSpec>>;
|
|
22
|
+
export declare const usesKey: (check: SecurityCheck, key: keyof AuditCache) => boolean;
|
|
23
|
+
/** Labels of the permissions this check's declared cache wiring needs; empty when none is attributable. */
|
|
24
|
+
export declare function permissionLabelsFor(check: SecurityCheck): string[];
|
|
25
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const AUDIT_PERMISSIONS = {
|
|
2
|
+
ApiEnabled: {
|
|
3
|
+
field: 'PermissionsApiEnabled',
|
|
4
|
+
label: 'API Enabled',
|
|
5
|
+
impact: 'All access is via SOQL/Tooling/REST. Without it the audit cannot run at all.',
|
|
6
|
+
cacheKeys: [],
|
|
7
|
+
blocking: true,
|
|
8
|
+
},
|
|
9
|
+
ViewSetup: {
|
|
10
|
+
field: 'PermissionsViewSetup',
|
|
11
|
+
label: 'View Setup and Configuration',
|
|
12
|
+
impact: 'Reads the bulk of the surface — connected apps, remote sites, CSP, named credentials, auth config, ' +
|
|
13
|
+
'Experience sites, and Tooling metadata. Most setup and configuration checks return inconclusive without it.',
|
|
14
|
+
cacheKeys: [],
|
|
15
|
+
},
|
|
16
|
+
ViewAllUsers: {
|
|
17
|
+
field: 'PermissionsViewAllUsers',
|
|
18
|
+
label: 'View All Users',
|
|
19
|
+
impact: 'Enumerates every User, PermissionSetAssignment and TwoFactorInfo org-wide. Without it the user, ' +
|
|
20
|
+
'admin and MFA checks under-count and miss accounts outside the role hierarchy.',
|
|
21
|
+
cacheKeys: ['mfaRegistrations', 'effectivePermissions'],
|
|
22
|
+
},
|
|
23
|
+
ViewHealthCheckScreen: {
|
|
24
|
+
field: 'PermissionsViewHealthCheck',
|
|
25
|
+
label: 'View Health Check',
|
|
26
|
+
impact: 'Reads SecurityHealthCheck and its risks. Health Check and password/session baselines are inconclusive without it.',
|
|
27
|
+
cacheKeys: ['healthCheckRisks'],
|
|
28
|
+
},
|
|
29
|
+
AuthorApex: {
|
|
30
|
+
field: 'PermissionsAuthorApex',
|
|
31
|
+
label: 'Author Apex (read-only use)',
|
|
32
|
+
impact: 'The only standard gate exposing ApexClass/ApexTrigger/ApexPage Body via the Tooling API. ' +
|
|
33
|
+
'Grants no ability to modify org data. The code-security checks are inconclusive without it.',
|
|
34
|
+
cacheKeys: ['apexBodies', 'vfPageBodies'],
|
|
35
|
+
},
|
|
36
|
+
ViewEventLogFiles: {
|
|
37
|
+
field: 'PermissionsViewEventLogFiles',
|
|
38
|
+
label: 'View Event Log Files',
|
|
39
|
+
impact: 'Reads EventLogFile. Whether login and API activity is monitored cannot be established without it.',
|
|
40
|
+
cacheKeys: ['eventLogSummary'],
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export const usesKey = (check, key) => (check.dependsOnCache?.includes(key) ?? false) || (check.populatesCache?.includes(key) ?? false);
|
|
44
|
+
/** Labels of the permissions this check's declared cache wiring needs; empty when none is attributable. */
|
|
45
|
+
export function permissionLabelsFor(check) {
|
|
46
|
+
return Object.values(AUDIT_PERMISSIONS)
|
|
47
|
+
.filter((spec) => spec.cacheKeys.some((k) => usesKey(check, k)))
|
|
48
|
+
.map((spec) => spec.label);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AttackChain } from '../chains/AttackChain.js';
|
|
2
|
+
export interface DagRenderOptions {
|
|
3
|
+
theme?: 'dark' | 'light';
|
|
4
|
+
}
|
|
5
|
+
export declare function identifyCutPointIndex(chain: AttackChain): number;
|
|
6
|
+
export declare function renderAttackChainDagSvg(chain: AttackChain, opts?: DagRenderOptions): string;
|
|
7
|
+
//# sourceMappingURL=AttackChainDagRenderer.d.ts.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// src/renderers/AttackChainDagRenderer.ts
|
|
2
|
+
//
|
|
3
|
+
// Draws an attack chain as an inline SVG strip of step cards joined by arrows, with the step whose
|
|
4
|
+
// fix breaks the chain marked as the cut-point. The executive report runs under a strict CSP (no
|
|
5
|
+
// script, inline style only), so the output is self-contained: no <script>, no event handlers, no
|
|
6
|
+
// <foreignObject>, no external references. Every chain/step string is escaped before it is placed
|
|
7
|
+
// in text or an attribute; colours come only from fixed lookup tables.
|
|
8
|
+
import { esc } from '@cclabsnz/sf-core';
|
|
9
|
+
// Severity accents per theme. The light set is darker so the "STEP n · SEV" label stays legible
|
|
10
|
+
// on a white card (the dark set's yellow/blue fall well below 3:1 on white).
|
|
11
|
+
const SEV_COLORS = {
|
|
12
|
+
dark: { CRITICAL: '#ef4444', HIGH: '#f97316', MEDIUM: '#eab308', LOW: '#60a5fa', INFO: '#94a3b8' },
|
|
13
|
+
light: { CRITICAL: '#b91c1c', HIGH: '#c2410c', MEDIUM: '#a16207', LOW: '#1d4ed8', INFO: '#475569' },
|
|
14
|
+
};
|
|
15
|
+
/** Cards per row before the strip wraps, so long chains stay readable when scaled to page width. */
|
|
16
|
+
const MAX_PER_ROW = 4;
|
|
17
|
+
export function identifyCutPointIndex(chain) {
|
|
18
|
+
if (!chain.steps || chain.steps.length === 0)
|
|
19
|
+
return 0;
|
|
20
|
+
const rem = (chain.remediation || '').toLowerCase();
|
|
21
|
+
for (let i = 0; i < chain.steps.length; i++) {
|
|
22
|
+
const s = chain.steps[i];
|
|
23
|
+
if (s.findingId && rem.includes(s.findingId.toLowerCase()))
|
|
24
|
+
return i;
|
|
25
|
+
if (s.title && rem.includes(s.title.toLowerCase()))
|
|
26
|
+
return i;
|
|
27
|
+
}
|
|
28
|
+
const sevRank = { CRITICAL: 4, HIGH: 3, MEDIUM: 2, LOW: 1, INFO: 0 };
|
|
29
|
+
let bestIdx = 0;
|
|
30
|
+
let bestRank = -1;
|
|
31
|
+
for (let i = 0; i < chain.steps.length; i++) {
|
|
32
|
+
const rank = sevRank[chain.steps[i].severity ?? 'LOW'] ?? 1;
|
|
33
|
+
if (rank > bestRank) {
|
|
34
|
+
bestRank = rank;
|
|
35
|
+
bestIdx = i;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return bestIdx;
|
|
39
|
+
}
|
|
40
|
+
/** Truncate by code point (never splitting a surrogate pair); escaping happens after. */
|
|
41
|
+
function truncate(str, maxLen) {
|
|
42
|
+
const chars = Array.from(str);
|
|
43
|
+
return chars.length > maxLen ? chars.slice(0, maxLen - 1).join('') + '…' : str;
|
|
44
|
+
}
|
|
45
|
+
export function renderAttackChainDagSvg(chain, opts = {}) {
|
|
46
|
+
const theme = opts.theme === 'light' ? 'light' : 'dark';
|
|
47
|
+
const steps = chain.steps ?? [];
|
|
48
|
+
if (steps.length === 0)
|
|
49
|
+
return '';
|
|
50
|
+
const cutPointIdx = identifyCutPointIndex(chain);
|
|
51
|
+
const cardW = 220;
|
|
52
|
+
const cardH = 96;
|
|
53
|
+
const gap = 52;
|
|
54
|
+
const rowGap = 44;
|
|
55
|
+
const padX = 24;
|
|
56
|
+
const padY = 24;
|
|
57
|
+
const cols = Math.min(steps.length, MAX_PER_ROW);
|
|
58
|
+
const rows = Math.ceil(steps.length / cols);
|
|
59
|
+
const totalW = padX * 2 + cols * cardW + (cols - 1) * gap;
|
|
60
|
+
const totalH = padY * 2 + rows * cardH + (rows - 1) * rowGap;
|
|
61
|
+
const posOf = (idx) => ({
|
|
62
|
+
x: padX + (idx % cols) * (cardW + gap),
|
|
63
|
+
y: padY + Math.floor(idx / cols) * (cardH + rowGap),
|
|
64
|
+
});
|
|
65
|
+
const isDark = theme === 'dark';
|
|
66
|
+
const sevColors = SEV_COLORS[theme];
|
|
67
|
+
const cardBg = isDark ? '#1e293b' : '#ffffff';
|
|
68
|
+
const cardBorder = isDark ? '#334155' : '#cbd5e1';
|
|
69
|
+
const textColor = isDark ? '#f8fafc' : '#0f172a';
|
|
70
|
+
const mutedColor = isDark ? '#94a3b8' : '#475569';
|
|
71
|
+
const pillBg = isDark ? '#0f172a' : '#f1f5f9';
|
|
72
|
+
const arrowColor = isDark ? '#64748b' : '#94a3b8';
|
|
73
|
+
const cutAccent = isDark ? '#ef4444' : '#dc2626';
|
|
74
|
+
const markerId = `dag-arrow-${String(chain.id).replace(/[^a-zA-Z0-9_-]/g, '_')}-${theme}`;
|
|
75
|
+
const nodesSvg = steps
|
|
76
|
+
.map((step, idx) => {
|
|
77
|
+
const { x, y } = posOf(idx);
|
|
78
|
+
const isCut = idx === cutPointIdx;
|
|
79
|
+
const sevRaw = String(step.severity ?? 'LOW');
|
|
80
|
+
const sevCol = sevColors[sevRaw] ?? sevColors.INFO;
|
|
81
|
+
const sev = esc(truncate(sevRaw, 10));
|
|
82
|
+
const title = esc(truncate(String(step.title || step.findingId || ''), 26));
|
|
83
|
+
const cap = esc(truncate(String(step.capability ?? ''), 24));
|
|
84
|
+
const stroke = isCut ? cutAccent : cardBorder;
|
|
85
|
+
const strokeWidth = isCut ? '2.5' : '1';
|
|
86
|
+
const dash = isCut ? ' stroke-dasharray="4 2"' : '';
|
|
87
|
+
const cutBadge = isCut
|
|
88
|
+
? `<g transform="translate(${x + cardW - 84}, ${y - 10})">
|
|
89
|
+
<rect width="80" height="18" rx="4" fill="${cutAccent}" />
|
|
90
|
+
<text x="40" y="12" fill="#ffffff" font-size="9" font-weight="700" text-anchor="middle" font-family="system-ui, sans-serif">✂ CUT-POINT</text>
|
|
91
|
+
</g>`
|
|
92
|
+
: '';
|
|
93
|
+
const cutNote = isCut
|
|
94
|
+
? `<text x="${x + 10}" y="${y + cardH - 10}" fill="${cutAccent}" font-size="9" font-weight="600" font-family="system-ui, sans-serif">★ Remediating breaks chain</text>`
|
|
95
|
+
: '';
|
|
96
|
+
return `<g class="dag-node${isCut ? ' dag-cut-point' : ''}">
|
|
97
|
+
<rect x="${x}" y="${y}" width="${cardW}" height="${cardH}" rx="8" fill="${cardBg}" stroke="${stroke}" stroke-width="${strokeWidth}"${dash} />
|
|
98
|
+
${cutBadge}
|
|
99
|
+
<circle cx="${x + 18}" cy="${y + 20}" r="4" fill="${sevCol}" />
|
|
100
|
+
<text x="${x + 28}" y="${y + 24}" fill="${sevCol}" font-size="10" font-weight="700" font-family="system-ui, sans-serif">STEP ${idx + 1} · ${sev}</text>
|
|
101
|
+
<text x="${x + 10}" y="${y + 44}" fill="${textColor}" font-size="12" font-weight="600" font-family="system-ui, sans-serif">${title}</text>
|
|
102
|
+
<rect x="${x + 10}" y="${y + 54}" width="${cardW - 20}" height="18" rx="4" fill="${pillBg}" />
|
|
103
|
+
<text x="${x + 16}" y="${y + 67}" fill="${mutedColor}" font-size="10" font-family="ui-monospace, monospace">grants: ${cap}</text>
|
|
104
|
+
${cutNote}
|
|
105
|
+
</g>`;
|
|
106
|
+
})
|
|
107
|
+
.join('\n');
|
|
108
|
+
const arrowsSvg = steps
|
|
109
|
+
.slice(0, -1)
|
|
110
|
+
.map((_, idx) => {
|
|
111
|
+
const from = posOf(idx);
|
|
112
|
+
const to = posOf(idx + 1);
|
|
113
|
+
let d;
|
|
114
|
+
if (from.y === to.y) {
|
|
115
|
+
// Same row: straight right-pointing arrow across the gap.
|
|
116
|
+
const centerY = from.y + cardH / 2;
|
|
117
|
+
d = `M ${from.x + cardW} ${centerY} L ${to.x - 6} ${centerY}`;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Row wrap: drop from the bottom of the last card, run back left, enter the next row's first card.
|
|
121
|
+
const sx = from.x + cardW / 2;
|
|
122
|
+
const ex = to.x + cardW / 2;
|
|
123
|
+
const midY = from.y + cardH + rowGap / 2;
|
|
124
|
+
d = `M ${sx} ${from.y + cardH} L ${sx} ${midY} L ${ex} ${midY} L ${ex} ${to.y - 6}`;
|
|
125
|
+
}
|
|
126
|
+
return `<path d="${d}" stroke="${arrowColor}" stroke-width="2" marker-end="url(#${markerId})" fill="none" />`;
|
|
127
|
+
})
|
|
128
|
+
.join('\n');
|
|
129
|
+
return `<svg class="attack-chain-dag" role="img" aria-label="${esc(`Attack chain diagram: ${chain.title ?? ''}`)}" viewBox="0 0 ${totalW} ${totalH}" width="100%" style="max-width:${totalW}px;display:block;margin:16px 0;">
|
|
130
|
+
<defs>
|
|
131
|
+
<marker id="${markerId}" viewBox="0 0 10 10" refX="6" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
|
|
132
|
+
<path d="M 0 1 L 8 5 L 0 9 z" fill="${arrowColor}" />
|
|
133
|
+
</marker>
|
|
134
|
+
</defs>
|
|
135
|
+
<g class="dag-arrows">${arrowsSvg}</g>
|
|
136
|
+
<g class="dag-nodes">${nodesSvg}</g>
|
|
137
|
+
</svg>`;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=AttackChainDagRenderer.js.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { esc } from '@cclabsnz/sf-core';
|
|
1
|
+
import { esc, STRICT_CSP_META } from '@cclabsnz/sf-core';
|
|
2
2
|
import { fontFaceCss } from '@cclabsnz/sf-core';
|
|
3
3
|
import { getCheckMeta } from '../findings/CheckMeta.js';
|
|
4
4
|
import { toolCreditHtml } from './toolCredit.js';
|
|
5
5
|
import { selectPriorities } from '../report/ExecutivePriorities.js';
|
|
6
6
|
import { buildRoadmap } from '../report/RemediationRoadmap.js';
|
|
7
7
|
import { buildComplianceMatrix } from '../report/ComplianceMatrix.js';
|
|
8
|
+
import { renderAttackChainDagSvg } from './AttackChainDagRenderer.js';
|
|
9
|
+
import { coverageSummary, coverageAdvice } from '../findings/coverage.js';
|
|
8
10
|
const SEV_COLOR = {
|
|
9
11
|
CRITICAL: '#7d3a3a', HIGH: '#a35a2a', MEDIUM: '#8a6d1f', LOW: '#3a5a82', INFO: '#636770',
|
|
10
12
|
};
|
|
@@ -42,12 +44,13 @@ export class ClientReportRenderer {
|
|
|
42
44
|
this.summary(result, num()),
|
|
43
45
|
this.prioritiesSection(priorities, chainIds, num()),
|
|
44
46
|
chains.length ? this.scenarios(chains, num()) : '',
|
|
47
|
+
result.waivedFindings?.length ? this.waiversSection(result.waivedFindings, num()) : '',
|
|
45
48
|
this.roadmapSection(roadmap, num()),
|
|
46
49
|
matrix.length ? this.matrixSection(matrix, num()) : '',
|
|
47
50
|
this.findingsAppendix(result, num()),
|
|
48
51
|
].join('\n');
|
|
49
52
|
return `<!DOCTYPE html>
|
|
50
|
-
<html lang="en"><head><meta charset="utf-8"
|
|
53
|
+
<html lang="en"><head><meta charset="utf-8">${STRICT_CSP_META}<title>Security Audit: ${esc(result.orgName)}</title>
|
|
51
54
|
<style>${fontFaceCss()}
|
|
52
55
|
:root{--ink:${b.ink};--bg:${b.bg};--bgalt:${b.bgAlt};--muted:${b.muted};--border:${b.border};--primary:${b.primary};
|
|
53
56
|
--display:'${b.fontDisplay}',Georgia,serif;--body:'${b.fontBody}',system-ui,sans-serif;--mono:ui-monospace,'SF Mono',Menlo,monospace;}
|
|
@@ -137,9 +140,11 @@ ${this.footer(b)}
|
|
|
137
140
|
}
|
|
138
141
|
summary(r, numStr) {
|
|
139
142
|
const incon = r.findings.filter((f) => f.inconclusive).length;
|
|
140
|
-
const active = r.findings.filter((f) => !f.passed && !f.inconclusive).length;
|
|
143
|
+
const active = r.findings.filter((f) => !f.passed && !f.inconclusive && !f.waived).length;
|
|
144
|
+
const waived = r.findings.filter((f) => f.waived).length;
|
|
145
|
+
const waivedNote = waived ? `, with ${waived} waived as accepted risk` : '';
|
|
141
146
|
return `${this.sectionHead(numStr, 'Executive Summary')}
|
|
142
|
-
<p>This audit assessed the org’s security configuration and scored it <strong>${r.healthScore}/100 (Grade ${esc(r.grade)})</strong
|
|
147
|
+
<p>This audit assessed the org’s security configuration and scored it <strong>${r.healthScore}/100 (Grade ${esc(r.grade)})</strong>${r.gradeReason ? `, a grade set by ${esc(r.gradeReason.replace(/^[A-F]: /, ''))},` : ''} across ${active} active finding${active === 1 ? '' : 's'}${incon ? `, with ${incon} inconclusive (no evidence gathered)` : ''}${waivedNote}. The priorities below are the highest-impact items to address first; the remediation roadmap groups every fix by effort. See Scope & Liability for the basis and limits of this assessment.</p>${this.coverageNote(r)}`;
|
|
143
148
|
}
|
|
144
149
|
prioritiesSection(priorities, chainIds, numStr) {
|
|
145
150
|
const head = this.sectionHead(numStr, 'Executive Priorities');
|
|
@@ -155,10 +160,33 @@ ${impact}${chained}<p><strong>Fix:</strong> ${esc(f.remediation)}</p></div>`;
|
|
|
155
160
|
}).join('');
|
|
156
161
|
return `${head}<p class="muted">Focus areas, highest impact first.</p>${items}`;
|
|
157
162
|
}
|
|
163
|
+
coverageNote(r) {
|
|
164
|
+
const c = r.coverage;
|
|
165
|
+
if (!c || c.notAssessed.length === 0)
|
|
166
|
+
return '';
|
|
167
|
+
return `<p class="muted">${esc(coverageSummary(c))}. The checks that gathered no evidence are listed as inconclusive in the findings appendix; their areas are unassessed, not clean. ${esc(coverageAdvice(c))}</p>`;
|
|
168
|
+
}
|
|
169
|
+
waiversSection(waived, numStr) {
|
|
170
|
+
const items = waived
|
|
171
|
+
.map((f) => {
|
|
172
|
+
// The approval (reason, approver, expiry) is on each item's note, or on the detail when the finding has no items.
|
|
173
|
+
const scope = f.affectedItems?.length ? f.affectedItems.map((i) => (i.note ? `${i.label} ${i.note}` : i.label)).join('; ') : f.id;
|
|
174
|
+
return `<div class="card" style="--c:#16a34a">
|
|
175
|
+
<div class="row"><h3>${esc(f.title)}</h3>${this.chip('INFO', 'WAIVED')}</div>
|
|
176
|
+
<p><strong>Scope:</strong> ${esc(scope)}</p><p>${esc(f.detail)}</p></div>`;
|
|
177
|
+
})
|
|
178
|
+
.join('');
|
|
179
|
+
return `${this.sectionHead(numStr, 'Accepted Risks')}<p class="muted">Findings covered by an approved, unexpired waiver. They are excluded from the score and from the priorities above, and still count toward the attack scenarios.</p>${items}`;
|
|
180
|
+
}
|
|
158
181
|
scenarios(chains, numStr) {
|
|
159
|
-
const items = chains.map((c) =>
|
|
182
|
+
const items = chains.map((c) => {
|
|
183
|
+
const dagSvg = renderAttackChainDagSvg(c, { theme: 'light' });
|
|
184
|
+
return `<div class="card scenario" style="--c:${SEV_COLOR[c.severity]}">
|
|
160
185
|
<div class="row"><h3>${esc(c.title)}</h3>${this.chip(c.severity, c.severity)}</div>
|
|
161
|
-
<p>${esc(c.narrative)}</p
|
|
186
|
+
<p>${esc(c.narrative)}</p>
|
|
187
|
+
${dagSvg}
|
|
188
|
+
<p><strong>Breaks the chain:</strong> ${esc(c.remediation)}</p></div>`;
|
|
189
|
+
}).join('');
|
|
162
190
|
return `${this.sectionHead(numStr, 'Attack Scenarios')}<p class="muted">How findings combine into real attack paths.</p>${items}`;
|
|
163
191
|
}
|
|
164
192
|
roadmapSection(roadmap, numStr) {
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
return str
|
|
3
|
-
.replace(/&/g, '&')
|
|
4
|
-
.replace(/</g, '<')
|
|
5
|
-
.replace(/>/g, '>')
|
|
6
|
-
.replace(/"/g, '"');
|
|
7
|
-
}
|
|
1
|
+
import { esc, INTERACTIVE_CSP_META } from '@cclabsnz/sf-core';
|
|
8
2
|
function fmtDate(d) {
|
|
9
3
|
return d.toISOString().replace('T', ' ').substring(0, 16);
|
|
10
4
|
}
|
|
@@ -83,6 +77,7 @@ export class DiffHtmlRenderer {
|
|
|
83
77
|
<html lang="en">
|
|
84
78
|
<head>
|
|
85
79
|
<meta charset="UTF-8">
|
|
80
|
+
${INTERACTIVE_CSP_META}
|
|
86
81
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
87
82
|
<title>SF Audit Diff: ${esc(baseline.orgName)}</title>
|
|
88
83
|
<style>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { esc, INTERACTIVE_CSP_META } from '@cclabsnz/sf-core';
|
|
1
2
|
import { chartJsScript } from './chartAsset.js';
|
|
2
3
|
function fmtDate(d) {
|
|
3
4
|
return d.toISOString().replace('T', ' ').substring(0, 16);
|
|
@@ -38,21 +39,23 @@ export class HistoryRenderer {
|
|
|
38
39
|
return '<!DOCTYPE html><html><body><p>No audit history found.</p></body></html>';
|
|
39
40
|
const orgName = results[0].orgName;
|
|
40
41
|
const orgId = results[0].orgId;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
42
|
+
// History is read back from files on disk, so nothing in it is trusted: scores are coerced to
|
|
43
|
+
// numbers, and JSON embedded in the inline <script> cannot close the script element.
|
|
44
|
+
const labels = scriptJson(results.map((r) => fmtDate(r.generatedAt)));
|
|
45
|
+
const scores = scriptJson(results.map((r) => Number(r.healthScore)));
|
|
46
|
+
const crits = scriptJson(results.map((r) => countBySeverity(r, 'CRITICAL')));
|
|
47
|
+
const highs = scriptJson(results.map((r) => countBySeverity(r, 'HIGH')));
|
|
48
|
+
const meds = scriptJson(results.map((r) => countBySeverity(r, 'MEDIUM')));
|
|
49
|
+
const lows = scriptJson(results.map((r) => countBySeverity(r, 'LOW')));
|
|
47
50
|
const tableRows = results.map((r, i) => {
|
|
48
51
|
const prev = i > 0 ? results[i - 1] : null;
|
|
49
52
|
const delta = prev ? (r.healthScore - prev.healthScore >= 0 ? `+${r.healthScore - prev.healthScore}` : `${r.healthScore - prev.healthScore}`) : '—';
|
|
50
53
|
const deltaColor = prev ? (r.healthScore >= prev.healthScore ? '#22c55e' : '#dc2626') : '#8b949e';
|
|
51
54
|
return `<tr>
|
|
52
55
|
<td>${i + 1}</td>
|
|
53
|
-
<td>${fmtDate(r.generatedAt)}</td>
|
|
54
|
-
<td style="text-align:right;font-weight:700">${r.healthScore}</td>
|
|
55
|
-
<td style="text-align:center">${r.grade}</td>
|
|
56
|
+
<td>${esc(fmtDate(r.generatedAt))}</td>
|
|
57
|
+
<td style="text-align:right;font-weight:700">${Number(r.healthScore)}</td>
|
|
58
|
+
<td style="text-align:center">${esc(r.grade)}</td>
|
|
56
59
|
<td style="text-align:right;color:#dc2626">${countBySeverity(r, 'CRITICAL')}</td>
|
|
57
60
|
<td style="text-align:right;color:#ea580c">${countBySeverity(r, 'HIGH')}</td>
|
|
58
61
|
<td style="text-align:right;color:#d97706">${countBySeverity(r, 'MEDIUM')}</td>
|
|
@@ -64,8 +67,9 @@ export class HistoryRenderer {
|
|
|
64
67
|
<html lang="en">
|
|
65
68
|
<head>
|
|
66
69
|
<meta charset="UTF-8">
|
|
70
|
+
${INTERACTIVE_CSP_META}
|
|
67
71
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
68
|
-
<title>SF Audit History: ${orgName}</title>
|
|
72
|
+
<title>SF Audit History: ${esc(orgName)}</title>
|
|
69
73
|
<script>${chartJsScript()}</script>
|
|
70
74
|
<style>
|
|
71
75
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
@@ -85,7 +89,7 @@ export class HistoryRenderer {
|
|
|
85
89
|
</head>
|
|
86
90
|
<body>
|
|
87
91
|
<h1>Salesforce Audit History</h1>
|
|
88
|
-
<div class="meta">Org: <strong style="color:#c9d1d9">${orgName}</strong> (${orgId})</div>
|
|
92
|
+
<div class="meta">Org: <strong style="color:#c9d1d9">${esc(orgName)}</strong> (${esc(orgId)})</div>
|
|
89
93
|
|
|
90
94
|
<div class="charts">
|
|
91
95
|
<div class="chart-box">
|
|
@@ -138,4 +142,8 @@ new Chart(document.getElementById('findingsChart'), {
|
|
|
138
142
|
</html>`;
|
|
139
143
|
}
|
|
140
144
|
}
|
|
145
|
+
/** JSON safe to place inside an inline <script>: `<` is escaped so no value can end the element. */
|
|
146
|
+
function scriptJson(value) {
|
|
147
|
+
return JSON.stringify(value).replace(/</g, '\\u003c');
|
|
148
|
+
}
|
|
141
149
|
//# sourceMappingURL=HistoryRenderer.js.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { esc, firaFontFaceCss } from '@cclabsnz/sf-core';
|
|
1
|
+
import { esc, firaFontFaceCss, INTERACTIVE_CSP_META } from '@cclabsnz/sf-core';
|
|
2
|
+
import { renderAttackChainDagSvg } from './AttackChainDagRenderer.js';
|
|
3
|
+
import { coverageSummary, coverageAdvice } from '../findings/coverage.js';
|
|
2
4
|
const RISK_COLORS = {
|
|
3
5
|
CRITICAL: '#dc2626',
|
|
4
6
|
HIGH: '#ea580c',
|
|
@@ -123,13 +125,26 @@ function buildDashboard(result, counts) {
|
|
|
123
125
|
metricRow('Failed Logins (30d)', m.failedLogins30d, failedColor),
|
|
124
126
|
metricRow('SF Health Check', `${m.healthCheckScore}%`, healthChkColor, progressBar(m.healthCheckScore, 100, healthChkColor)),
|
|
125
127
|
]);
|
|
128
|
+
const waivedBanner = result.waivedFindings?.length
|
|
129
|
+
? `<div class="waived-banner" style="background:#0f291e;border:1px solid #16a34a;border-radius:8px;padding:12px 16px;margin-bottom:20px;color:#dcfce7;font-size:13px;"><strong>Accepted risks:</strong> ${result.waivedFindings.length} finding(s) waived under an approved waiver and excluded from the score.</div>`
|
|
130
|
+
: '';
|
|
131
|
+
const gradeReasonLine = result.gradeReason
|
|
132
|
+
? `<div class="grade-reason" style="margin-top:10px;font-size:12px;color:#94a3b8">Why ${esc(result.grade)}: ${esc(result.gradeReason.replace(/^[A-F]: /, ''))}</div>`
|
|
133
|
+
: '';
|
|
134
|
+
const cov = result.coverage;
|
|
135
|
+
const coverageLine = cov
|
|
136
|
+
? `<div class="coverage${cov.gradeCapped ? ' is-capped' : ''}" style="margin-top:10px;font-size:12px;color:${cov.gradeCapped ? '#fbbf24' : '#94a3b8'}">${esc(coverageSummary(cov))}${cov.notAssessed.length ? `<br>Not assessed: ${cov.notAssessed.map((id) => `<code>${esc(id)}</code>`).join(', ')}<br>${esc(coverageAdvice(cov))}` : ''}</div>`
|
|
137
|
+
: '';
|
|
126
138
|
return `
|
|
139
|
+
${waivedBanner}
|
|
127
140
|
<div class="dashboard">
|
|
128
141
|
<div class="dash-top">
|
|
129
142
|
<div class="dash-score-panel">
|
|
130
143
|
<div class="gauge-wrap">
|
|
131
144
|
${gauge}
|
|
132
145
|
</div>
|
|
146
|
+
${gradeReasonLine}
|
|
147
|
+
${coverageLine}
|
|
133
148
|
</div>
|
|
134
149
|
<div class="dash-risk-panel">
|
|
135
150
|
<div class="donut-wrap">
|
|
@@ -160,18 +175,19 @@ export class HtmlRenderer {
|
|
|
160
175
|
renderAttackPaths(result) {
|
|
161
176
|
if (!result.attackChains || result.attackChains.length === 0)
|
|
162
177
|
return '';
|
|
163
|
-
const escStr = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
164
178
|
const cards = result.attackChains
|
|
165
179
|
.map((c) => {
|
|
166
180
|
const conf = c.confidence === 'named' ? '' : ' (potential)';
|
|
181
|
+
const dagSvg = renderAttackChainDagSvg(c, { theme: 'dark' });
|
|
167
182
|
const steps = c.steps
|
|
168
|
-
.map((s) => `<li><strong>${
|
|
183
|
+
.map((s) => `<li><strong>${esc(s.title ?? s.findingId)}</strong> (${esc(s.severity ?? '—')}): grants <code>${esc(s.capability)}</code></li>`)
|
|
169
184
|
.join('');
|
|
170
185
|
return `<div class="attack-chain severity-${c.severity.toLowerCase()}">
|
|
171
|
-
<h3>[${
|
|
172
|
-
<p>${
|
|
186
|
+
<h3>[${esc(c.severity)}] ${esc(c.title)}${conf}</h3>
|
|
187
|
+
<p>${esc(c.narrative)}</p>
|
|
188
|
+
${dagSvg}
|
|
173
189
|
<ol>${steps}</ol>
|
|
174
|
-
<p class="remediation"><strong>Remediation:</strong> ${
|
|
190
|
+
<p class="remediation"><strong>Remediation:</strong> ${esc(c.remediation)}</p>
|
|
175
191
|
</div>`;
|
|
176
192
|
})
|
|
177
193
|
.join('\n');
|
|
@@ -240,6 +256,7 @@ export class HtmlRenderer {
|
|
|
240
256
|
<html lang="en">
|
|
241
257
|
<head>
|
|
242
258
|
<meta charset="UTF-8">
|
|
259
|
+
${INTERACTIVE_CSP_META}
|
|
243
260
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
244
261
|
<title>SF Security Audit: ${esc(result.orgName)}</title>
|
|
245
262
|
<style>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { coverageSummary, coverageAdvice } from '../findings/coverage.js';
|
|
1
2
|
function escapeMdCell(s) {
|
|
2
3
|
return s.replace(/\\/g, '\\\\').replace(/\|/g, '\\|').replace(/\n/g, ' ');
|
|
3
4
|
}
|
|
@@ -10,7 +11,16 @@ export class MarkdownRenderer {
|
|
|
10
11
|
lines.push(`**Org:** ${result.orgName} (${result.orgId})`);
|
|
11
12
|
lines.push(`**Generated:** ${result.generatedAt.toISOString()}`);
|
|
12
13
|
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(`**Health Score:** ${result.healthScore}/100 | **Grade:** ${result.grade}${result.gradeReason ? ` (${result.gradeReason})` : ''}`);
|
|
15
|
+
if (result.coverage) {
|
|
16
|
+
lines.push('');
|
|
17
|
+
lines.push(`**${coverageSummary(result.coverage)}**`);
|
|
18
|
+
if (result.coverage.notAssessed.length > 0) {
|
|
19
|
+
lines.push(`Not assessed: ${result.coverage.notAssessed.map((id) => `\`${id}\``).join(', ')}`);
|
|
20
|
+
lines.push('');
|
|
21
|
+
lines.push(coverageAdvice(result.coverage));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
14
24
|
lines.push('');
|
|
15
25
|
if (result.attackChains && result.attackChains.length > 0) {
|
|
16
26
|
lines.push(`## Attack Paths (${result.attackChains.length})`);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { RiskLevel } from '@cclabsnz/sf-core';
|
|
2
|
+
import type { AuditResult } from '../findings/AuditResult.js';
|
|
3
|
+
import type { AuditRenderer } from './AuditRenderer.js';
|
|
4
|
+
/**
|
|
5
|
+
* SARIF 2.1.0 output, for GitHub code scanning and other SARIF consumers.
|
|
6
|
+
*
|
|
7
|
+
* The audit inspects an org's configuration, not files, so there is no real source location.
|
|
8
|
+
* Each result carries:
|
|
9
|
+
* - a logical location per affected item (the actual subject of the finding), and
|
|
10
|
+
* - a synthetic physical location, `salesforce-org/<ruleId>`, because GitHub code scanning
|
|
11
|
+
* only displays results that have a physicalLocation with an artifactLocation.uri. The
|
|
12
|
+
* file does not exist in the repository; it groups alerts by check in the UI.
|
|
13
|
+
*
|
|
14
|
+
* Results carry a `partialFingerprints` entry derived from the rule id and the finding id, so
|
|
15
|
+
* the same finding on the next run updates the existing alert instead of opening a new one.
|
|
16
|
+
* Finding ids are stable per subject (checks embed the user / domain / component they are
|
|
17
|
+
* about), whereas affected-item lists change size between runs.
|
|
18
|
+
*
|
|
19
|
+
* Only actionable findings become results. Passing checks are omitted, and inconclusive
|
|
20
|
+
* checks (no evidence, usually a missing permission) are reported as tool execution
|
|
21
|
+
* notifications with `executionSuccessful: false`, never as error/warning alerts.
|
|
22
|
+
*/
|
|
23
|
+
export type SarifLevel = 'error' | 'warning' | 'note' | 'none';
|
|
24
|
+
/** Fingerprint key. Bump the version suffix if the hashed inputs ever change. */
|
|
25
|
+
export declare const FINGERPRINT_KEY = "sfAuditFindingHash/v1";
|
|
26
|
+
/** Root of the synthetic artifact path every result points at. */
|
|
27
|
+
export declare const ORG_ARTIFACT_ROOT = "salesforce-org";
|
|
28
|
+
export declare function riskToSarifLevel(level: RiskLevel): SarifLevel;
|
|
29
|
+
export declare class SarifRenderer implements AuditRenderer {
|
|
30
|
+
readonly format = "sarif";
|
|
31
|
+
readonly fileExtension = ".sarif";
|
|
32
|
+
readonly filenamePrefix = "sf-audit";
|
|
33
|
+
render(result: AuditResult): string;
|
|
34
|
+
private ruleFor;
|
|
35
|
+
/**
|
|
36
|
+
* One SARIF result per actionable finding. Accepted-risk waivers, when they land, attach
|
|
37
|
+
* here as `suppressions` (SARIF 3.27.23) rather than by dropping the result, so consumers
|
|
38
|
+
* can still see the finding and that it was waived.
|
|
39
|
+
*/
|
|
40
|
+
private findingResult;
|
|
41
|
+
private chainResult;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=SarifRenderer.d.ts.map
|