@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
@@ -1,3 +1,16 @@
1
+ // SBS-AUTH-003: detect ranges covering the full public internet or overly broad blocks.
2
+ // Anything larger than a /16 (65 536 hosts) is flagged; 0.0.0.0 start is always flagged.
3
+ function ipToNumber(ip) {
4
+ const parts = ip.split('.').map(Number);
5
+ return ((parts[0] ?? 0) * 16_777_216) +
6
+ ((parts[1] ?? 0) * 65_536) +
7
+ ((parts[2] ?? 0) * 256) +
8
+ (parts[3] ?? 0);
9
+ }
10
+ function rangeHostCount(start, end) {
11
+ return ipToNumber(end) - ipToNumber(start) + 1;
12
+ }
13
+ const BROAD_THRESHOLD = 65_536; // /16
1
14
  export class IpRestrictionsCheck {
2
15
  id = 'ip-restrictions';
3
16
  name = 'Login IP Restrictions';
@@ -23,26 +36,28 @@ export class IpRestrictionsCheck {
23
36
  ipRanges = [];
24
37
  }
25
38
  }
26
- // 3. Connected apps with IP relaxation
27
- let connectedApps = [];
28
- try {
29
- connectedApps = await ctx.tooling.query('SELECT Id, Name FROM ConnectedApplication');
30
- }
31
- catch {
32
- connectedApps = [];
33
- }
39
+ // 3. Connected apps — single Tooling SOQL with Metadata field (same pattern as
40
+ // SELECT Body FROM ApexClass). Replaces the previous N+1 getRecord loop.
41
+ // Salesforce ConnectedApp.Metadata.oauthConfig.ipRelaxation enum:
42
+ // 'All' → bypass IP restrictions (every IP allowed)
43
+ // 'Relax' → relax restrictions for this app's users
44
+ // 'WhiteList'→ enforce the org-level IP whitelist (secure)
34
45
  const ipBypassingApps = [];
35
- for (const app of connectedApps) {
36
- try {
37
- const detail = await ctx.tooling.getRecord('ConnectedApplication', app.Id);
38
- const relaxation = detail.Metadata?.ipRelaxation;
39
- if (relaxation === 'BYPASS' || relaxation === 'RELAX_IP') {
46
+ const ipRelaxingApps = [];
47
+ try {
48
+ const connectedApps = await ctx.tooling.query('SELECT Id, Name, Metadata FROM ConnectedApplication');
49
+ for (const app of connectedApps) {
50
+ const relaxation = app.Metadata?.oauthConfig?.ipRelaxation;
51
+ if (relaxation === 'All') {
40
52
  ipBypassingApps.push({ name: app.Name, id: app.Id });
41
53
  }
54
+ else if (relaxation === 'Relax') {
55
+ ipRelaxingApps.push({ name: app.Name, id: app.Id });
56
+ }
42
57
  }
43
- catch {
44
- // Skip apps whose detail record cannot be fetched
45
- }
58
+ }
59
+ catch {
60
+ // Metadata field not accessible — skip connected app IP check
46
61
  }
47
62
  // Determine which profile IDs have at least one IP range
48
63
  const profilesWithRanges = new Set(ipRanges.map((r) => r.ProfileId));
@@ -67,25 +82,73 @@ export class IpRestrictionsCheck {
67
82
  findings.push({
68
83
  id: 'connected-apps-bypass-ip',
69
84
  category: this.category,
70
- riskLevel: 'MEDIUM',
71
- title: `${ipBypassingApps.length} connected app(s) bypass login IP enforcement`,
85
+ riskLevel: 'HIGH',
86
+ title: `${ipBypassingApps.length} connected app(s) completely bypass login IP enforcement`,
72
87
  affectedItems: ipBypassingApps.map((app) => ({
73
88
  label: app.name,
74
89
  url: `${baseUrl}/lightning/setup/ConnectedApplication/page`,
75
- note: 'Set IP Relaxation to "Enforce IP restrictions" unless remote access is required',
90
+ note: 'IP Relaxation = All — change to "Enforce IP Restrictions" or "Relax IP Restrictions" to reinstate controls',
91
+ })),
92
+ detail: `Connected apps configured with IP Relaxation set to "All" allow API access from any IP address for any user, completely overriding profile-level IP restrictions. An attacker with a stolen OAuth token or credential can authenticate from anywhere regardless of org-level IP policies.`,
93
+ remediation: 'Set IP Relaxation to "Enforce IP Restrictions" (WhiteList) for all connected apps unless there is a documented, audited business requirement for remote access. Review each app and confirm the relaxation setting is intentional.',
94
+ });
95
+ }
96
+ if (ipRelaxingApps.length > 0) {
97
+ findings.push({
98
+ id: 'connected-apps-relax-ip',
99
+ category: this.category,
100
+ riskLevel: 'MEDIUM',
101
+ title: `${ipRelaxingApps.length} connected app(s) relax login IP enforcement for their users`,
102
+ affectedItems: ipRelaxingApps.map((app) => ({
103
+ label: app.name,
104
+ url: `${baseUrl}/lightning/setup/ConnectedApplication/page`,
105
+ note: 'IP Relaxation = Relax — confirm documented justification exists',
106
+ })),
107
+ detail: `Connected apps configured with IP Relaxation set to "Relax" allow the app's users to access the org from outside the IP ranges defined on their profile when using this app. This weakens the IP restriction control for API access.`,
108
+ remediation: 'Set IP Relaxation to "Enforce IP Restrictions" unless the integration genuinely requires access from IP addresses outside the corporate network. Document any justified relaxations in the system of record.',
109
+ });
110
+ }
111
+ const broadRanges = [];
112
+ // Build a map of profileId → profile name from admin users (best effort)
113
+ const profileNameMap = new Map(adminUsers.map((u) => [u.ProfileId, u.Profile.Name]));
114
+ for (const range of ipRanges) {
115
+ const count = rangeHostCount(range.StartAddress, range.EndAddress);
116
+ if (count >= BROAD_THRESHOLD || range.StartAddress === '0.0.0.0') {
117
+ broadRanges.push({
118
+ profileId: range.ProfileId,
119
+ profileName: profileNameMap.get(range.ProfileId) ?? range.ProfileId,
120
+ start: range.StartAddress,
121
+ end: range.EndAddress,
122
+ hostCount: count,
123
+ });
124
+ }
125
+ }
126
+ if (broadRanges.length > 0) {
127
+ findings.push({
128
+ id: 'broad-ip-ranges',
129
+ category: this.category,
130
+ riskLevel: 'HIGH',
131
+ title: `${broadRanges.length} login IP range(s) are overly broad (>${BROAD_THRESHOLD.toLocaleString()} hosts or start at 0.0.0.0)`,
132
+ detail: 'SBS-AUTH-003 requires that profile IP ranges do not cover the full public internet or excessively large blocks. Broad ranges effectively disable IP-based login controls.',
133
+ remediation: 'Replace overly broad IP ranges with your specific corporate network CIDR blocks. Remove 0.0.0.0 start addresses entirely.',
134
+ affectedItems: broadRanges.map((r) => ({
135
+ label: r.profileName,
136
+ url: `${baseUrl}/lightning/setup/Profiles/home`,
137
+ note: `${r.start} – ${r.end} (${r.hostCount.toLocaleString()} hosts)`,
76
138
  })),
77
- detail: "Connected apps configured to relax IP restrictions allow API access from any IP address, even when the user's profile has IP restrictions.",
78
- remediation: 'Set IP Relaxation to "Enforce IP restrictions" for connected apps unless there is a documented business requirement for remote access.',
79
139
  });
80
140
  }
81
- if (unrestrictedAdmins.length === 0 && ipBypassingApps.length === 0) {
141
+ if (unrestrictedAdmins.length === 0 &&
142
+ ipBypassingApps.length === 0 &&
143
+ ipRelaxingApps.length === 0 &&
144
+ broadRanges.length === 0) {
82
145
  findings.push({
83
146
  id: 'ip-restrictions-ok',
84
147
  category: this.category,
85
148
  riskLevel: 'LOW',
86
149
  passed: true,
87
150
  title: 'Login IP restrictions appear appropriately configured',
88
- detail: 'All checked admin profiles have login IP ranges configured and no connected apps bypass IP enforcement.',
151
+ detail: 'All checked admin profiles have login IP ranges configured, no connected apps bypass or relax IP enforcement, and no overly broad ranges were found.',
89
152
  remediation: 'Periodically review IP restriction configuration as new admins and connected apps are added.',
90
153
  });
91
154
  }
@@ -0,0 +1,10 @@
1
+ import type { AuditContext } from '../../context/AuditContext.js';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ export declare class LegacyApiVersionCheck implements SecurityCheck {
4
+ readonly id = "legacy-api-version";
5
+ readonly name = "Legacy API Versions";
6
+ readonly category = "Platform Hygiene";
7
+ readonly description = "Flags Apex classes compiled on old API versions and detects SOAP-based remote site integrations";
8
+ run(ctx: AuditContext): Promise<CheckResult>;
9
+ }
10
+ //# sourceMappingURL=LegacyApiVersionCheck.d.ts.map
@@ -0,0 +1,91 @@
1
+ // API v50 = Winter '21. Classes below this miss 4+ years of platform security improvements.
2
+ // API v30 = Spring '14. Classes at or below this may rely on behaviors Salesforce has since deprecated.
3
+ const OLD_API_THRESHOLD = 50;
4
+ const CRITICAL_API_THRESHOLD = 30;
5
+ export class LegacyApiVersionCheck {
6
+ id = 'legacy-api-version';
7
+ name = 'Legacy API Versions';
8
+ category = 'Platform Hygiene';
9
+ description = 'Flags Apex classes compiled on old API versions and detects SOAP-based remote site integrations';
10
+ async run(ctx) {
11
+ const findings = [];
12
+ const apexClassesUrl = `${ctx.orgInfo.instanceUrl}/lightning/setup/ApexClasses/home`;
13
+ // Q1: Fetch Apex classes compiled below the threshold.
14
+ // ORDER BY ApiVersion ASC means index 0 = oldest (minimum), used for risk determination.
15
+ const oldClasses = await ctx.tooling.query(`SELECT Id, Name, ApiVersion FROM ApexClass WHERE NamespacePrefix = null AND ApiVersion < ${OLD_API_THRESHOLD} ORDER BY ApiVersion ASC LIMIT 50`);
16
+ if (oldClasses.length === 0) {
17
+ findings.push({
18
+ id: 'legacy-api-version-apex-ok',
19
+ category: this.category,
20
+ riskLevel: 'LOW',
21
+ passed: true,
22
+ title: `All custom Apex classes are compiled on API v${OLD_API_THRESHOLD}+ (Winter '21 or later)`,
23
+ detail: 'No custom Apex classes with API versions older than the baseline threshold were found. Modern API versions ensure classes benefit from current platform security behaviors and FLS enforcement.',
24
+ remediation: 'When developing new Apex classes, target the current API version. Periodically update old classes and regression-test to stay current.',
25
+ });
26
+ }
27
+ else {
28
+ const minVer = oldClasses[0].ApiVersion;
29
+ const count = oldClasses.length;
30
+ const hitLimit = count === 50;
31
+ let riskLevel = 'LOW';
32
+ if (minVer <= CRITICAL_API_THRESHOLD) {
33
+ riskLevel = 'HIGH';
34
+ }
35
+ else if (minVer < 40 || count > 10) {
36
+ riskLevel = 'MEDIUM';
37
+ }
38
+ findings.push({
39
+ id: 'legacy-api-version-apex',
40
+ category: this.category,
41
+ riskLevel,
42
+ title: `${hitLimit ? '50+' : count} custom Apex class(es) compiled on API v${OLD_API_THRESHOLD - 1} or older (oldest: v${minVer})`,
43
+ detail: `Apex classes compiled on old API versions run against older Salesforce platform behaviors that predate security improvements introduced in later releases. API v${CRITICAL_API_THRESHOLD} (Spring '14) and below may rely on deprecated FLS and sharing model defaults that newer versions enforce more strictly. Updating the API version causes the class to compile against the current platform contract but may surface new runtime behaviors that require testing.`,
44
+ remediation: `Open each affected class in Developer Console or VS Code, increment the API version to the current release, then run all related tests. Classes using old DML/SOQL patterns may need refactoring to pass FLS checks enforced in newer API versions. Prioritize classes that perform DML or handle sensitive data.`,
45
+ affectedItems: oldClasses.map((c) => ({
46
+ label: c.Name,
47
+ url: apexClassesUrl,
48
+ note: `API v${c.ApiVersion}`,
49
+ })),
50
+ });
51
+ }
52
+ // Q2: Detect active remote sites configured for SOAP-based endpoints.
53
+ // /services/Soap/ in the URL indicates a WSDL/SOAP integration (Salesforce or third-party).
54
+ try {
55
+ const soapRemoteSites = await ctx.tooling.query("SELECT Id, SiteName, EndpointUrl FROM RemoteProxy WHERE IsActive = true AND EndpointUrl LIKE '%/services/Soap/%'");
56
+ if (soapRemoteSites.length > 0) {
57
+ findings.push({
58
+ id: 'legacy-api-soap-remote-sites',
59
+ category: this.category,
60
+ riskLevel: 'MEDIUM',
61
+ title: `${soapRemoteSites.length} active remote site setting(s) point to SOAP API endpoints (outbound callouts)`,
62
+ detail: 'Remote site settings with /services/Soap/ endpoints indicate Apex code making outbound WSDL-based SOAP callouts rather than REST. These integrations are harder to maintain, often pin outdated API versions, and typically require broader API Enabled permissions.',
63
+ remediation: 'Review each SOAP remote site and evaluate whether a REST equivalent exists. For Salesforce-to-Salesforce integrations, migrate to REST API or Salesforce Connect. For third-party SOAP services, check for a REST endpoint. If SOAP is necessary, document the justification and confirm the pinned API version is current.',
64
+ affectedItems: soapRemoteSites.map((r) => ({
65
+ label: r.SiteName,
66
+ url: `${ctx.orgInfo.instanceUrl}/lightning/setup/SecurityRemoteProxy/home`,
67
+ note: r.EndpointUrl,
68
+ })),
69
+ });
70
+ }
71
+ }
72
+ catch {
73
+ // RemoteProxy LIKE query may not be supported in all org editions — skip silently.
74
+ // RemoteSitesCheck covers general remote site access concerns.
75
+ }
76
+ // Advisory: inbound SOAP API detection requires EventLogFile CSV analysis.
77
+ // Salesforce stores API_TYPE per-call in EventLogFile (EventType = 'API'):
78
+ // 'E' = Enterprise WSDL (SOAP), 'P' = Partner WSDL (SOAP), 'R' = REST, 'T' = Tooling
79
+ // LoginHistory.LoginType cannot distinguish SOAP logins from UI logins — both show 'Application'.
80
+ findings.push({
81
+ id: 'legacy-api-soap-inbound-advisory',
82
+ category: this.category,
83
+ riskLevel: 'INFO',
84
+ title: 'Inbound SOAP API usage: manual review required via Event Monitoring',
85
+ detail: 'Salesforce does not expose inbound SOAP API call details in SOQL-queryable objects — they are captured only in EventLogFile with EventType = "API". The API_TYPE column in those log files distinguishes SOAP callers: "E" = Enterprise WSDL, "P" = Partner WSDL. LoginHistory cannot make this distinction; SOAP login() calls and UI logins both appear as LoginType = "Application". If external systems are calling this org via the Enterprise or Partner WSDL, those callers should be migrated to REST API or connected-app-governed OAuth flows.',
86
+ remediation: 'In Setup → Event Monitoring, download an API event log and filter on API_TYPE = "E" or "P" to identify active SOAP callers. For each SOAP caller, work with the integration owner to migrate to REST API using a connected app with appropriate OAuth scopes and IP restrictions.',
87
+ });
88
+ return { findings };
89
+ }
90
+ }
91
+ //# sourceMappingURL=LegacyApiVersionCheck.js.map
@@ -0,0 +1,10 @@
1
+ import type { AuditContext } from '../../context/AuditContext.js';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ export declare class MfaEnforcementCheck implements SecurityCheck {
4
+ readonly id = "mfa-enforcement";
5
+ readonly name = "MFA for External Users";
6
+ readonly category = "Authentication";
7
+ readonly description = "SBS-AUTH-004: checks that external/portal users with data access have MFA enforced";
8
+ run(ctx: AuditContext): Promise<CheckResult>;
9
+ }
10
+ //# sourceMappingURL=MfaEnforcementCheck.d.ts.map
@@ -0,0 +1,76 @@
1
+ // Experience Cloud / portal user types that represent external human users
2
+ const EXTERNAL_USER_TYPES = ['CsnOnly', 'CustomerSuccess', 'PowerPartner', 'PowerCustomerSuccess', 'SelfService'];
3
+ export class MfaEnforcementCheck {
4
+ id = 'mfa-enforcement';
5
+ name = 'MFA for External Users';
6
+ category = 'Authentication';
7
+ description = 'SBS-AUTH-004: checks that external/portal users with data access have MFA enforced';
8
+ async run(ctx) {
9
+ const findings = [];
10
+ const baseUrl = ctx.orgInfo.instanceUrl;
11
+ const userTypeList = EXTERNAL_USER_TYPES.map((t) => `'${t}'`).join(', ');
12
+ // Query 1: all active external/portal users
13
+ const allPortalResult = await ctx.soql.queryAll(`SELECT Id, Username, UserType, Profile.Name
14
+ FROM User
15
+ WHERE IsActive = true
16
+ AND UserType IN (${userTypeList})
17
+ ORDER BY UserType, Username
18
+ LIMIT 500`);
19
+ const allPortalUsers = allPortalResult;
20
+ if (allPortalUsers.length === 0) {
21
+ findings.push({
22
+ id: 'mfa-no-portal-users',
23
+ category: this.category,
24
+ riskLevel: 'LOW',
25
+ passed: true,
26
+ title: 'No active external/portal users found — SBS-AUTH-004 not applicable',
27
+ detail: 'SBS-AUTH-004 applies to external users with substantial access to sensitive data. No active portal user types were found in this org.',
28
+ remediation: 'If Experience Cloud sites are added in future, ensure SBS-AUTH-004 MFA requirements are met for external users.',
29
+ });
30
+ return { findings };
31
+ }
32
+ // Query 2: portal users who have MFA explicitly enforced via permission
33
+ let mfaEnforcedIds = new Set();
34
+ try {
35
+ const mfaResult = await ctx.soql.query(`SELECT AssigneeId
36
+ FROM PermissionSetAssignment
37
+ WHERE PermissionSet.PermissionsMultiFactorForUiLogins = true
38
+ AND Assignee.IsActive = true
39
+ AND Assignee.UserType IN (${userTypeList})`);
40
+ mfaEnforcedIds = new Set(mfaResult.records.map((r) => r.AssigneeId));
41
+ }
42
+ catch {
43
+ // PermissionsMultiFactorForUiLogins may not exist in all editions — treat as none enforced
44
+ }
45
+ const withoutMfa = allPortalUsers.filter((u) => !mfaEnforcedIds.has(u.Id));
46
+ const withMfa = allPortalUsers.filter((u) => mfaEnforcedIds.has(u.Id));
47
+ if (withoutMfa.length === 0) {
48
+ findings.push({
49
+ id: 'mfa-portal-users-enforced',
50
+ category: this.category,
51
+ riskLevel: 'LOW',
52
+ passed: true,
53
+ title: `All ${allPortalUsers.length} external/portal user(s) have MFA enforced`,
54
+ detail: 'SBS-AUTH-004 requires MFA for external users with substantial access. All active portal users have the "Multi-Factor Authentication for User Interface Logins" permission assigned.',
55
+ remediation: 'Continue monitoring as new portal users are added.',
56
+ });
57
+ return { findings };
58
+ }
59
+ const riskLevel = withoutMfa.length > 10 ? 'HIGH' : 'MEDIUM';
60
+ findings.push({
61
+ id: 'mfa-portal-users-without-enforcement',
62
+ category: this.category,
63
+ riskLevel,
64
+ title: `${withoutMfa.length} of ${allPortalUsers.length} external/portal user(s) do not have MFA enforced — SBS-AUTH-004`,
65
+ detail: `SBS-AUTH-004 requires all external human users with substantial access to sensitive data to enforce MFA including at least one strong authentication factor. ${withoutMfa.length} active portal user(s) lack the "Multi-Factor Authentication for User Interface Logins" permission. ${withMfa.length > 0 ? `${withMfa.length} user(s) already have MFA enforced.` : ''}`,
66
+ remediation: 'Assign the "Multi-Factor Authentication for User Interface Logins" permission to all Experience Cloud users with access to sensitive data. Create a permission set for this purpose and assign it to all in-scope portal profiles.',
67
+ affectedItems: withoutMfa.slice(0, 50).map((u) => ({
68
+ label: u.Username,
69
+ url: `${baseUrl}/${u.Id}`,
70
+ note: `UserType: ${u.UserType} | Profile: ${u.Profile.Name} — assign MFA permission set`,
71
+ })),
72
+ });
73
+ return { findings };
74
+ }
75
+ }
76
+ //# sourceMappingURL=MfaEnforcementCheck.js.map
@@ -0,0 +1,11 @@
1
+ import type { AuditContext } from '../../context/AuditContext.js';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ export declare class MfaMethodStrengthCheck implements SecurityCheck {
4
+ readonly id = "mfa-method-strength";
5
+ readonly name = "MFA Method Strength";
6
+ readonly category = "Authentication";
7
+ readonly description = "Classifies registered MFA methods by strength (phishing-resistant / TOTP / weak) using Salesforce's guidance and NIST; flags admin users with weak-only methods";
8
+ readonly dependsOnCache: readonly ["mfaRegistrations"];
9
+ run(ctx: AuditContext): Promise<CheckResult>;
10
+ }
11
+ //# sourceMappingURL=MfaMethodStrengthCheck.d.ts.map
@@ -0,0 +1,116 @@
1
+ const PHISHING_RESISTANT = new Set(['U2F', 'FIDO2', 'WEBAUTHN', 'BUILT_IN_AUTHENTICATOR']);
2
+ const STRONG = new Set(['TOTP', 'SALESFORCE_AUTHENTICATOR']);
3
+ const WEAK = new Set(['EMAIL', 'VERIFICATIONCODE', 'SMS_OTP']);
4
+ function strongestMethod(methods) {
5
+ if (methods.some((m) => PHISHING_RESISTANT.has(m)))
6
+ return 'PHISHING_RESISTANT';
7
+ if (methods.some((m) => STRONG.has(m)))
8
+ return 'STRONG';
9
+ if (methods.some((m) => WEAK.has(m)))
10
+ return 'WEAK';
11
+ return 'UNKNOWN';
12
+ }
13
+ function isAdminProfile(profileName) {
14
+ const lower = profileName.toLowerCase();
15
+ return lower.includes('admin') || lower.includes('system administrator');
16
+ }
17
+ export class MfaMethodStrengthCheck {
18
+ id = 'mfa-method-strength';
19
+ name = 'MFA Method Strength';
20
+ category = 'Authentication';
21
+ description = `Classifies registered MFA methods by strength (phishing-resistant / TOTP / weak) using Salesforce's guidance and NIST; flags admin users with weak-only methods`;
22
+ dependsOnCache = ['mfaRegistrations'];
23
+ async run(ctx) {
24
+ const findings = [];
25
+ const baseUrl = ctx.orgInfo.instanceUrl;
26
+ const setupUrl = `${baseUrl}/lightning/setup/SetupOneIdEntityManagement/home`;
27
+ const registrations = ctx.cache.mfaRegistrations ?? [];
28
+ if (registrations.length === 0) {
29
+ findings.push({
30
+ id: 'mfa-no-data',
31
+ category: this.category,
32
+ riskLevel: 'INFO',
33
+ inconclusive: true,
34
+ title: 'No MFA registration data available — MfaRegistrationCheck must run first',
35
+ detail: 'The mfaRegistrations cache is empty. Either MfaRegistrationCheck did not run, or TwoFactorInfo was not accessible. MFA method strength analysis cannot be performed without this data.',
36
+ remediation: 'Ensure MfaRegistrationCheck runs before this check. Grant "Manage Multi-Factor Authentication in API" permission to the audit user.',
37
+ });
38
+ return { findings };
39
+ }
40
+ let phishingResistantCount = 0;
41
+ let strongCount = 0;
42
+ let weakOnlyCount = 0;
43
+ const adminWeakUsers = [];
44
+ const nonAdminWeakUsers = [];
45
+ for (const reg of registrations) {
46
+ const strength = strongestMethod(reg.methods);
47
+ if (strength === 'PHISHING_RESISTANT') {
48
+ phishingResistantCount += 1;
49
+ }
50
+ else if (strength === 'STRONG') {
51
+ strongCount += 1;
52
+ }
53
+ else if (strength === 'WEAK' || strength === 'UNKNOWN') {
54
+ weakOnlyCount += 1;
55
+ if (isAdminProfile(reg.profileName)) {
56
+ adminWeakUsers.push(reg);
57
+ }
58
+ else {
59
+ nonAdminWeakUsers.push(reg);
60
+ }
61
+ }
62
+ }
63
+ findings.push({
64
+ id: 'mfa-methods-summary',
65
+ category: this.category,
66
+ riskLevel: 'INFO',
67
+ title: `MFA method summary: ${phishingResistantCount} phishing-resistant, ${strongCount} TOTP/authenticator, ${weakOnlyCount} weak-only`,
68
+ detail: `Of ${registrations.length} user(s) with registered MFA methods: ${phishingResistantCount} use phishing-resistant methods (FIDO2/passkeys/WebAuthn, supported since Salesforce Winter 2024); ${strongCount} use TOTP or Salesforce Authenticator; ${weakOnlyCount} use only weak methods (email, SMS, or verification code). Phishing-resistant methods cannot be intercepted via real-time phishing attacks, making them the strongest option per NIST SP 800-63B and Salesforce's own MFA guidance.`,
69
+ remediation: 'Encourage adoption of phishing-resistant MFA methods (FIDO2 security keys, passkeys, or the Salesforce Authenticator built-in biometric) for all users. Prioritise admin-profile users.',
70
+ });
71
+ if (adminWeakUsers.length > 0) {
72
+ findings.push({
73
+ id: 'mfa-admin-weak-methods',
74
+ category: this.category,
75
+ riskLevel: 'HIGH',
76
+ title: `${adminWeakUsers.length} admin-profile user(s) rely on weak MFA methods only (email or SMS)`,
77
+ detail: 'Admin-profile users with only weak MFA methods (email verification codes, SMS OTP) are high-value targets. Email-based and SMS-based MFA codes can be intercepted via phishing, SIM-swapping, or email account compromise. An attacker who compromises the email inbox or phone number of an admin can bypass MFA entirely and gain full administrative access to the Salesforce org.',
78
+ remediation: `Require all admin-profile users to register a phishing-resistant MFA method (FIDO2 security key, passkey, or built-in biometric authenticator) or at minimum a TOTP authenticator app (Salesforce Authenticator, Google Authenticator, Authy). Remove email-based MFA as the sole option for privileged users. Consider enforcing a minimum method strength via Salesforce's High Assurance session policy.`,
79
+ affectedItems: adminWeakUsers.map((u) => ({
80
+ label: u.username,
81
+ url: setupUrl,
82
+ note: `profile: ${u.profileName} — methods: ${u.methods.join(', ') || 'none'}`,
83
+ })),
84
+ });
85
+ }
86
+ if (nonAdminWeakUsers.length > 0) {
87
+ findings.push({
88
+ id: 'mfa-weak-only-users',
89
+ category: this.category,
90
+ riskLevel: 'MEDIUM',
91
+ title: `${nonAdminWeakUsers.length} non-admin user(s) rely on weak MFA methods only`,
92
+ detail: 'Non-admin users with only weak MFA methods (email verification, SMS OTP) have MFA that can be bypassed via phishing or SIM-swapping. While the risk is lower than for admin users, these users can still access sensitive CRM data and their accounts can be used to exfiltrate information or as a pivot point for privilege escalation.',
93
+ remediation: 'Encourage all users to upgrade to TOTP authenticator apps or phishing-resistant methods. Communicate the risks of email-based and SMS-based MFA to end users. Consider providing security keys or passkey onboarding guidance as part of your security awareness programme.',
94
+ affectedItems: nonAdminWeakUsers.slice(0, 30).map((u) => ({
95
+ label: u.username,
96
+ url: setupUrl,
97
+ note: `profile: ${u.profileName} — methods: ${u.methods.join(', ') || 'none'}`,
98
+ })),
99
+ });
100
+ }
101
+ const phishingResistantPct = registrations.length > 0 ? (phishingResistantCount / registrations.length) * 100 : 0;
102
+ if (phishingResistantPct > 50) {
103
+ findings.push({
104
+ id: 'mfa-phishing-resistant-users',
105
+ category: this.category,
106
+ riskLevel: 'LOW',
107
+ passed: true,
108
+ title: `${phishingResistantCount} of ${registrations.length} user(s) (${Math.round(phishingResistantPct)}%) use phishing-resistant MFA`,
109
+ detail: `More than half of registered users use phishing-resistant MFA methods (FIDO2, WebAuthn, passkeys, or built-in biometric authenticators), which are supported since Salesforce Winter 2024. Phishing-resistant methods cannot be intercepted by real-time phishing proxies, providing the strongest available protection against credential theft.`,
110
+ remediation: 'Continue to drive phishing-resistant MFA adoption for remaining users. Target 100% coverage for admin-profile users as a priority.',
111
+ });
112
+ }
113
+ return { findings };
114
+ }
115
+ }
116
+ //# sourceMappingURL=MfaMethodStrengthCheck.js.map
@@ -0,0 +1,11 @@
1
+ import type { AuditContext } from '../../context/AuditContext.js';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ export declare class MfaRegistrationCheck implements SecurityCheck {
4
+ readonly id = "mfa-registration";
5
+ readonly name = "MFA Method Registration";
6
+ readonly category = "Authentication";
7
+ readonly description = "Identifies active standard users who have not registered any MFA method in TwoFactorInfo";
8
+ readonly populatesCache: readonly ["mfaRegistrations"];
9
+ run(ctx: AuditContext): Promise<CheckResult>;
10
+ }
11
+ //# sourceMappingURL=MfaRegistrationCheck.d.ts.map
@@ -0,0 +1,95 @@
1
+ export class MfaRegistrationCheck {
2
+ id = 'mfa-registration';
3
+ name = 'MFA Method Registration';
4
+ category = 'Authentication';
5
+ description = 'Identifies active standard users who have not registered any MFA method in TwoFactorInfo';
6
+ populatesCache = ['mfaRegistrations'];
7
+ async run(ctx) {
8
+ const findings = [];
9
+ const baseUrl = ctx.orgInfo.instanceUrl;
10
+ const setupUrl = `${baseUrl}/lightning/setup/SetupOneIdEntityManagement/home`;
11
+ const frozenFilter = `Id NOT IN (SELECT UserId FROM UserLogin WHERE IsFrozen = true)`;
12
+ // COUNT(Id) expr0 puts the result in records[0].expr0; COUNT() without a field puts it in
13
+ // totalSize which is not exposed on the typed return value.
14
+ const countResult = await ctx.soql.query(`SELECT COUNT(Id) expr0 FROM User
15
+ WHERE IsActive = true
16
+ AND UserType = 'Standard'
17
+ AND ${frozenFilter}`);
18
+ const totalActiveUsers = countResult.records[0]?.expr0 ?? 0;
19
+ let twoFactorRecords = [];
20
+ try {
21
+ twoFactorRecords = await ctx.soql.queryAll(`SELECT UserId, User.Username, User.Profile.Name, Type
22
+ FROM TwoFactorInfo
23
+ WHERE User.IsActive = true
24
+ AND User.UserType = 'Standard'
25
+ ORDER BY UserId
26
+ LIMIT 2000`);
27
+ }
28
+ catch {
29
+ ctx.cache.mfaRegistrations = [];
30
+ findings.push({
31
+ id: 'mfa-registration-inaccessible',
32
+ category: this.category,
33
+ riskLevel: 'INFO',
34
+ inconclusive: true,
35
+ title: 'TwoFactorInfo could not be queried — MFA registration status cannot be verified',
36
+ detail: 'The TwoFactorInfo object was not accessible. This may indicate the audit user lacks the "Manage Multi-Factor Authentication in API" permission or the org edition does not support this query.',
37
+ remediation: 'Grant "Manage Multi-Factor Authentication in API" permission to the audit user. Review MFA registration status manually in Setup → Identity → Identity Verification.',
38
+ affectedItems: [{ label: 'Identity Verification Setup', url: setupUrl }],
39
+ });
40
+ return { findings };
41
+ }
42
+ const userMethodMap = new Map();
43
+ for (const r of twoFactorRecords) {
44
+ const existing = userMethodMap.get(r.UserId);
45
+ if (existing) {
46
+ existing.methods.push(r.Type);
47
+ }
48
+ else {
49
+ userMethodMap.set(r.UserId, {
50
+ username: r.User.Username,
51
+ profileName: r.User.Profile?.Name ?? 'Unknown',
52
+ methods: [r.Type],
53
+ });
54
+ }
55
+ }
56
+ ctx.cache.mfaRegistrations = [...userMethodMap.entries()].map(([userId, data]) => ({
57
+ userId,
58
+ username: data.username,
59
+ profileName: data.profileName,
60
+ methods: data.methods,
61
+ }));
62
+ const registeredCount = userMethodMap.size;
63
+ const unregisteredCount = Math.max(0, totalActiveUsers - registeredCount);
64
+ if (unregisteredCount === 0) {
65
+ findings.push({
66
+ id: 'mfa-registration-ok',
67
+ category: this.category,
68
+ riskLevel: 'LOW',
69
+ passed: true,
70
+ title: `All ${totalActiveUsers} active standard user(s) have registered at least one MFA method`,
71
+ detail: `All ${totalActiveUsers} active, unfrozen standard users have at least one MFA method registered in TwoFactorInfo. Users who have not registered a method cannot complete MFA challenges and may be locked out of the org if MFA is enforced.`,
72
+ remediation: 'Continue monitoring MFA registration as new users are onboarded. Ensure new user onboarding includes an MFA registration step before their first login.',
73
+ });
74
+ return { findings };
75
+ }
76
+ const riskLevel = unregisteredCount > 20 ? 'HIGH' : 'MEDIUM';
77
+ findings.push({
78
+ id: 'mfa-registration-gap',
79
+ category: this.category,
80
+ riskLevel,
81
+ title: `${unregisteredCount} of ${totalActiveUsers} active user(s) have not registered any MFA method`,
82
+ detail: `${unregisteredCount} active standard users have no registered MFA methods in TwoFactorInfo. These users cannot complete MFA challenges and may be locked out or have a degraded authentication experience when MFA is enforced. ${registeredCount} user(s) have registered at least one method. Unregistered users should complete MFA setup immediately.`,
83
+ remediation: 'Identify unregistered users in Setup → Identity → Identity Verification → User Management. Send MFA registration prompts or require registration on next login. Consider using Salesforce automation or the MFA rollout tools to enforce registration deadlines.',
84
+ affectedItems: [
85
+ {
86
+ label: `${unregisteredCount} unregistered user(s)`,
87
+ url: setupUrl,
88
+ note: `${totalActiveUsers} total active users — ${registeredCount} registered — ${unregisteredCount} unregistered`,
89
+ },
90
+ ],
91
+ });
92
+ return { findings };
93
+ }
94
+ }
95
+ //# sourceMappingURL=MfaRegistrationCheck.js.map
@@ -0,0 +1,10 @@
1
+ import type { AuditContext } from '../../context/AuditContext.js';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ export declare class MyDomainLoginPolicyCheck implements SecurityCheck {
4
+ readonly id = "my-domain-login-policy";
5
+ readonly name = "My Domain Login Policy";
6
+ readonly category = "Authentication";
7
+ readonly description = "Checks that My Domain is configured and login from login.salesforce.com is prevented \u2014 stops SSO bypass";
8
+ run(ctx: AuditContext): Promise<CheckResult>;
9
+ }
10
+ //# sourceMappingURL=MyDomainLoginPolicyCheck.d.ts.map