@cclabsnz/sf-audit 1.6.1 → 1.8.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 (198) hide show
  1. package/README.md +258 -5
  2. package/lib/apps/analyzeApps.d.ts +1 -1
  3. package/lib/apps/appResolver.d.ts +1 -1
  4. package/lib/apps/grantedAccess.d.ts +1 -1
  5. package/lib/chains/AttackChain.d.ts +1 -1
  6. package/lib/chains/namedChains.d.ts +1 -1
  7. package/lib/checks/CheckEngine.d.ts +1 -1
  8. package/lib/checks/SecurityCheck.d.ts +3 -3
  9. package/lib/checks/impl/AgentActionSurfaceCheck.d.ts +1 -1
  10. package/lib/checks/impl/AgentActionSurfaceCheck.js +1 -1
  11. package/lib/checks/impl/AgentChannelExposureCheck.d.ts +1 -1
  12. package/lib/checks/impl/AgentInventoryCheck.d.ts +1 -1
  13. package/lib/checks/impl/AgentInventoryCheck.js +1 -1
  14. package/lib/checks/impl/AgentMonitoringCoverageCheck.d.ts +1 -1
  15. package/lib/checks/impl/AgentUserPrivilegeCheck.d.ts +1 -1
  16. package/lib/checks/impl/AnonymousApexAuditCheck.d.ts +1 -1
  17. package/lib/checks/impl/ApexCrudFLSCheck.d.ts +1 -1
  18. package/lib/checks/impl/ApexLoggingCheck.d.ts +1 -1
  19. package/lib/checks/impl/ApexRestEndpointCheck.d.ts +1 -1
  20. package/lib/checks/impl/ApexSharingCheck.d.ts +1 -1
  21. package/lib/checks/impl/ApexSharingCheck.js +3 -2
  22. package/lib/checks/impl/ApiClientPermissionCheck.d.ts +1 -1
  23. package/lib/checks/impl/ApiLimitsCheck.d.ts +1 -1
  24. package/lib/checks/impl/AuditTrailCheck.d.ts +1 -1
  25. package/lib/checks/impl/AuthProvidersCheck.d.ts +1 -1
  26. package/lib/checks/impl/CertificateExpiryCheck.d.ts +1 -1
  27. package/lib/checks/impl/ClassicSitesCheck.d.ts +1 -1
  28. package/lib/checks/impl/CodeSecurityCheck.d.ts +1 -1
  29. package/lib/checks/impl/CodeSecurityCheck.js +5 -5
  30. package/lib/checks/impl/ConnectedAppInactivityCheck.d.ts +1 -1
  31. package/lib/checks/impl/ConnectedAppScopeCheck.d.ts +1 -1
  32. package/lib/checks/impl/ConnectedAppsCheck.d.ts +1 -1
  33. package/lib/checks/impl/ContentLinksCheck.d.ts +1 -1
  34. package/lib/checks/impl/CorsAllowlistCheck.d.ts +1 -1
  35. package/lib/checks/impl/CspTrustedSitesCheck.d.ts +1 -1
  36. package/lib/checks/impl/CustomLabelsCredentialCheck.d.ts +1 -1
  37. package/lib/checks/impl/CustomSettingsCheck.d.ts +1 -1
  38. package/lib/checks/impl/DataClassificationCheck.d.ts +1 -1
  39. package/lib/checks/impl/DataExportAccessCheck.d.ts +1 -1
  40. package/lib/checks/impl/DebugLogAccessCheck.d.ts +1 -1
  41. package/lib/checks/impl/DeploymentIdentityCheck.d.ts +1 -1
  42. package/lib/checks/impl/EmailSecurityCheck.d.ts +1 -1
  43. package/lib/checks/impl/EncryptionCoverageCheck.d.ts +1 -1
  44. package/lib/checks/impl/EnhancedDomainsCheck.d.ts +1 -1
  45. package/lib/checks/impl/EnhancedDomainsCheck.js +2 -2
  46. package/lib/checks/impl/EscalationPermsCheck.d.ts +1 -1
  47. package/lib/checks/impl/EventMonitoringCheck.d.ts +1 -1
  48. package/lib/checks/impl/EventMonitoringCheck.js +1 -1
  49. package/lib/checks/impl/ExperienceCloudSiteCheck.d.ts +1 -1
  50. package/lib/checks/impl/ExperienceCspCheck.d.ts +1 -1
  51. package/lib/checks/impl/ExternalCredentialsCheck.d.ts +1 -1
  52. package/lib/checks/impl/FailedLoginCheck.d.ts +1 -1
  53. package/lib/checks/impl/FieldHistoryTrackingCheck.d.ts +1 -1
  54. package/lib/checks/impl/FieldLevelSecurityCheck.d.ts +1 -1
  55. package/lib/checks/impl/FlowsWithoutSharingCheck.d.ts +1 -1
  56. package/lib/checks/impl/FlowsWithoutSharingCheck.js +10 -9
  57. package/lib/checks/impl/GuestApiAccessCheck.d.ts +1 -1
  58. package/lib/checks/impl/GuestExecutableApexCheck.d.ts +1 -1
  59. package/lib/checks/impl/GuestExecutableApexCheck.js +4 -3
  60. package/lib/checks/impl/GuestObjectExposureCheck.d.ts +1 -1
  61. package/lib/checks/impl/GuestRecordAccessPolicyCheck.d.ts +1 -1
  62. package/lib/checks/impl/GuestSiteOptionsCheck.d.ts +1 -1
  63. package/lib/checks/impl/GuestTrafficAnomalyCheck.d.ts +1 -1
  64. package/lib/checks/impl/GuestTrafficAnomalyCheck.js +1 -1
  65. package/lib/checks/impl/GuestUserAccessCheck.d.ts +1 -1
  66. package/lib/checks/impl/HardcodedCredentialsCheck.d.ts +1 -1
  67. package/lib/checks/impl/HardcodedCredentialsCheck.js +8 -1
  68. package/lib/checks/impl/HealthCheckCheck.d.ts +1 -1
  69. package/lib/checks/impl/HighAssuranceSessionCheck.d.ts +1 -1
  70. package/lib/checks/impl/InactiveUsersCheck.d.ts +1 -1
  71. package/lib/checks/impl/InstalledPackagesCheck.d.ts +1 -1
  72. package/lib/checks/impl/IntegrationUsersCheck.d.ts +1 -1
  73. package/lib/checks/impl/InternalUserMfaCheck.d.ts +1 -1
  74. package/lib/checks/impl/IpRestrictionsCheck.d.ts +1 -1
  75. package/lib/checks/impl/LegacyApiVersionCheck.d.ts +1 -1
  76. package/lib/checks/impl/LoginAccessPolicyCheck.d.ts +1 -1
  77. package/lib/checks/impl/LoginAnomalyCheck.d.ts +1 -1
  78. package/lib/checks/impl/LoginSessionCheck.d.ts +1 -1
  79. package/lib/checks/impl/MfaEnforcementCheck.d.ts +1 -1
  80. package/lib/checks/impl/MfaMethodStrengthCheck.d.ts +1 -1
  81. package/lib/checks/impl/MfaRegistrationCheck.d.ts +1 -1
  82. package/lib/checks/impl/MyDomainLoginPolicyCheck.d.ts +1 -1
  83. package/lib/checks/impl/NamedCredentialsCheck.d.ts +1 -1
  84. package/lib/checks/impl/NamedCredentialsCheck.js +13 -9
  85. package/lib/checks/impl/OutboundMessagesCheck.d.ts +1 -1
  86. package/lib/checks/impl/PasswordSessionPolicyCheck.d.ts +2 -2
  87. package/lib/checks/impl/PermissionsCheck.d.ts +1 -1
  88. package/lib/checks/impl/PrivilegedAccessCheck.d.ts +1 -1
  89. package/lib/checks/impl/PublicContentExposureCheck.d.ts +1 -1
  90. package/lib/checks/impl/PublicGroupSharingCheck.d.ts +1 -1
  91. package/lib/checks/impl/ReleaseUpdatesCheck.d.ts +1 -1
  92. package/lib/checks/impl/RemoteSitesCheck.d.ts +1 -1
  93. package/lib/checks/impl/ReportFolderAccessCheck.d.ts +1 -1
  94. package/lib/checks/impl/SandboxDataMaskingCheck.d.ts +1 -1
  95. package/lib/checks/impl/ScheduledApexCheck.d.ts +1 -1
  96. package/lib/checks/impl/SeparationOfDutiesCheck.d.ts +1 -1
  97. package/lib/checks/impl/SessionHardeningCheck.d.ts +1 -1
  98. package/lib/checks/impl/SharingModelCheck.d.ts +1 -1
  99. package/lib/checks/impl/SiemIntegrationCheck.d.ts +1 -1
  100. package/lib/checks/impl/SsoEnforcementCheck.d.ts +1 -1
  101. package/lib/checks/impl/StandardProfilesCheck.d.ts +1 -1
  102. package/lib/checks/impl/ThreatDetectionCheck.d.ts +1 -1
  103. package/lib/checks/impl/TransactionSecurityPolicyCheck.d.ts +1 -1
  104. package/lib/checks/impl/TrustedIPRangesCheck.d.ts +1 -1
  105. package/lib/checks/impl/TrustedUrlHygieneCheck.d.ts +1 -1
  106. package/lib/checks/impl/UsersAndAdminsCheck.d.ts +1 -1
  107. package/lib/checks/impl/VisualforceXssCheck.d.ts +1 -1
  108. package/lib/commands/audit/events/pull.d.ts +1 -1
  109. package/lib/commands/audit/events/pull.js +3 -3
  110. package/lib/commands/audit/security.js +3 -1
  111. package/lib/commands/audit/timeline.d.ts +26 -0
  112. package/lib/commands/audit/timeline.js +189 -0
  113. package/lib/findings/AuditResult.d.ts +1 -1
  114. package/lib/findings/Finding.d.ts +1 -1
  115. package/lib/findings/ScoringConfig.d.ts +9 -217
  116. package/lib/findings/scoring.d.ts +2 -2
  117. package/lib/findings/scoring.js +1 -1
  118. package/lib/history/AuditDiff.d.ts +1 -1
  119. package/lib/history/metricMeta.d.ts +1 -1
  120. package/lib/index.d.ts +2 -2
  121. package/lib/lib/apexRefs.d.ts +2 -0
  122. package/lib/lib/apexRefs.js +30 -0
  123. package/lib/lib/wire.d.ts +6 -6
  124. package/lib/lib/wire.js +4 -4
  125. package/lib/renderers/ClientReportRenderer.d.ts +1 -1
  126. package/lib/renderers/ClientReportRenderer.js +6 -3
  127. package/lib/renderers/HistoryRenderer.js +2 -1
  128. package/lib/renderers/HtmlRenderer.js +3 -4
  129. package/lib/renderers/MarkdownRenderer.js +1 -1
  130. package/lib/renderers/chartAsset.d.ts +12 -0
  131. package/lib/renderers/chartAsset.js +25 -0
  132. package/lib/timeline/CaptureIndex.d.ts +34 -0
  133. package/lib/timeline/CaptureIndex.js +82 -0
  134. package/lib/timeline/CardinalityIndex.d.ts +28 -0
  135. package/lib/timeline/CardinalityIndex.js +47 -0
  136. package/lib/timeline/CorrelationEngine.d.ts +65 -0
  137. package/lib/timeline/CorrelationEngine.js +0 -0
  138. package/lib/timeline/EventRow.d.ts +69 -0
  139. package/lib/timeline/EventRow.js +14 -0
  140. package/lib/timeline/JoinKeys.d.ts +50 -0
  141. package/lib/timeline/JoinKeys.js +63 -0
  142. package/lib/timeline/loadCaptures.d.ts +87 -0
  143. package/lib/timeline/loadCaptures.js +424 -0
  144. package/lib/timeline/normalise.d.ts +26 -0
  145. package/lib/timeline/normalise.js +161 -0
  146. package/lib/timeline/parseWindow.d.ts +29 -0
  147. package/lib/timeline/parseWindow.js +133 -0
  148. package/lib/timeline/render.d.ts +33 -0
  149. package/lib/timeline/render.js +120 -0
  150. package/package.json +22 -20
  151. package/lib/api/ApiError.d.ts +0 -6
  152. package/lib/api/ApiError.js +0 -6
  153. package/lib/api/MetadataClient.d.ts +0 -4
  154. package/lib/api/MetadataClient.js +0 -2
  155. package/lib/api/MetadataClientImpl.d.ts +0 -8
  156. package/lib/api/MetadataClientImpl.js +0 -22
  157. package/lib/api/RestClient.d.ts +0 -6
  158. package/lib/api/RestClient.js +0 -2
  159. package/lib/api/RestClientImpl.d.ts +0 -10
  160. package/lib/api/RestClientImpl.js +0 -45
  161. package/lib/api/SoqlClient.d.ts +0 -10
  162. package/lib/api/SoqlClient.js +0 -2
  163. package/lib/api/SoqlClientImpl.d.ts +0 -9
  164. package/lib/api/SoqlClientImpl.js +0 -19
  165. package/lib/api/ToolingClient.d.ts +0 -5
  166. package/lib/api/ToolingClient.js +0 -2
  167. package/lib/api/ToolingClientImpl.d.ts +0 -10
  168. package/lib/api/ToolingClientImpl.js +0 -29
  169. package/lib/api/index.d.ts +0 -9
  170. package/lib/api/index.js +0 -5
  171. package/lib/checks/eventLogAccess.d.ts +0 -14
  172. package/lib/checks/eventLogAccess.js +0 -33
  173. package/lib/context/AuditCache.d.ts +0 -78
  174. package/lib/context/AuditCache.js +0 -2
  175. package/lib/context/AuditContext.d.ts +0 -19
  176. package/lib/context/AuditContext.js +0 -2
  177. package/lib/context/OrgInfo.d.ts +0 -9
  178. package/lib/context/OrgInfo.js +0 -2
  179. package/lib/context/OrgMetrics.d.ts +0 -20
  180. package/lib/context/OrgMetrics.js +0 -20
  181. package/lib/events/EventBaselineStore.d.ts +0 -16
  182. package/lib/events/EventBaselineStore.js +0 -55
  183. package/lib/events/eventLogQuery.d.ts +0 -21
  184. package/lib/events/eventLogQuery.js +0 -34
  185. package/lib/events/pullEventLogs.d.ts +0 -51
  186. package/lib/events/pullEventLogs.js +0 -79
  187. package/lib/findings/RiskLevel.d.ts +0 -3
  188. package/lib/findings/RiskLevel.js +0 -2
  189. package/lib/renderers/html-utils.d.ts +0 -2
  190. package/lib/renderers/html-utils.js +0 -8
  191. package/lib/report/branding.d.ts +0 -18
  192. package/lib/report/branding.js +0 -19
  193. package/lib/report/fonts.d.ts +0 -2
  194. package/lib/report/fonts.js +0 -22
  195. package/src/assets/fonts/dm-sans-italic-latin.woff2 +0 -0
  196. package/src/assets/fonts/dm-sans-normal-latin.woff2 +0 -0
  197. package/src/assets/fonts/dm-serif-display-italic-latin.woff2 +0 -0
  198. package/src/assets/fonts/dm-serif-display-normal-latin.woff2 +0 -0
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Finds the profiles / permission sets that grant a bulk data-extraction
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class DebugLogAccessCheck implements SecurityCheck {
4
4
  readonly id = "debug-log-access";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class DeploymentIdentityCheck implements SecurityCheck {
4
4
  readonly id = "deployment-identity";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class EmailSecurityCheck implements SecurityCheck {
4
4
  readonly id = "email-security";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Cross-references data classification against ACTUAL field encryption. `data-
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class EnhancedDomainsCheck implements SecurityCheck {
4
4
  readonly id = "enhanced-domains";
@@ -10,8 +10,8 @@
10
10
  // 2. The instance URL uses the enhanced domain format (contains .my.salesforce.com or .develop.my.salesforce.com)
11
11
  // 3. Org is not still on a shared instance URL like na1.salesforce.com
12
12
  // Patterns are matched against the parsed hostname and anchored to its end, so a URL
13
- // that merely *contains* the string (e.g. https://evil.example.com/x.my.salesforce.com)
14
- // cannot be mistaken for an enhanced-domain org. All enhanced variants
13
+ // that merely *contains* the string (an attacker-controlled host with a path of
14
+ // `/x.my.salesforce.com`) cannot be mistaken for an enhanced-domain org. All enhanced variants
15
15
  // (sandbox/develop/scratch) are subdomains of my.salesforce.com, so one suffix suffices.
16
16
  const ENHANCED_DOMAIN_PATTERN = /\.my\.salesforce\.com$/i;
17
17
  const LEGACY_INSTANCE_PATTERN = /^[a-z]{2}\d+\.salesforce\.com$/i;
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class EscalationPermsCheck implements SecurityCheck {
4
4
  readonly id = "escalation-perms";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class EventMonitoringCheck implements SecurityCheck {
4
4
  readonly id = "event-monitoring";
@@ -1,4 +1,4 @@
1
- import { classifyEventLogAccessError } from '../eventLogAccess.js';
1
+ import { classifyEventLogAccessError } from '@cclabsnz/sf-core';
2
2
  export class EventMonitoringCheck {
3
3
  id = 'event-monitoring';
4
4
  name = 'Event Monitoring Storage';
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class ExperienceCloudSiteCheck implements SecurityCheck {
4
4
  readonly id = "experience-cloud-site";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Advisory review of Experience Cloud CSP / Lightning Web Security posture.
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Reviews External Credentials (the modern auth half of Named Credentials) for
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class FailedLoginCheck implements SecurityCheck {
4
4
  readonly id = "failed-login-detection";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class FieldHistoryTrackingCheck implements SecurityCheck {
4
4
  readonly id = "field-history-tracking";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class FieldLevelSecurityCheck implements SecurityCheck {
4
4
  readonly id = "field-level-security";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class FlowsWithoutSharingCheck implements SecurityCheck {
4
4
  readonly id = "flows-without-sharing";
@@ -1,3 +1,4 @@
1
+ import { FlowRepository } from '@cclabsnz/sf-core';
1
2
  export class FlowsWithoutSharingCheck {
2
3
  id = 'flows-without-sharing';
3
4
  name = 'Flows Without Sharing Context';
@@ -6,12 +7,12 @@ export class FlowsWithoutSharingCheck {
6
7
  async run(ctx) {
7
8
  const findings = [];
8
9
  const baseUrl = ctx.orgInfo.instanceUrl;
9
- const flows = await ctx.tooling.query("SELECT Id, MasterLabel, ProcessType, Status, RunInMode FROM Flow WHERE Status = 'Active'");
10
+ const flows = await new FlowRepository(ctx.soql, ctx.tooling).listActiveVersions();
10
11
  const total = flows.length;
11
- const autolaunchedWithoutSharing = flows.filter((f) => f.ProcessType === 'AutoLaunchedFlow' &&
12
- (f.RunInMode === 'DefaultMode' || f.RunInMode === null));
13
- const screenWithoutSharing = flows.filter((f) => f.ProcessType === 'Flow' &&
14
- (f.RunInMode === 'DefaultMode' || f.RunInMode === null));
12
+ const autolaunchedWithoutSharing = flows.filter((f) => f.processType === 'AutoLaunchedFlow' &&
13
+ (f.runInMode === 'DefaultMode' || f.runInMode === null));
14
+ const screenWithoutSharing = flows.filter((f) => f.processType === 'Flow' &&
15
+ (f.runInMode === 'DefaultMode' || f.runInMode === null));
15
16
  if (autolaunchedWithoutSharing.length > 0) {
16
17
  const count = autolaunchedWithoutSharing.length;
17
18
  findings.push({
@@ -20,8 +21,8 @@ export class FlowsWithoutSharingCheck {
20
21
  riskLevel: 'HIGH',
21
22
  title: `${count} autolaunched flow(s) run without user sharing context`,
22
23
  affectedItems: autolaunchedWithoutSharing.map((f) => ({
23
- label: f.MasterLabel,
24
- url: `${baseUrl}/builder_platform_interaction/flowBuilder.app?flowId=${f.Id}`,
24
+ label: f.masterLabel,
25
+ url: `${baseUrl}/builder_platform_interaction/flowBuilder.app?flowId=${f.id}`,
25
26
  note: 'Set "Run Flow As" to "User" or document why system context is required',
26
27
  })),
27
28
  detail: "Autolaunched flows running in Default Mode execute with system-level data access, ignoring the triggering user's record visibility.",
@@ -36,8 +37,8 @@ export class FlowsWithoutSharingCheck {
36
37
  riskLevel: 'MEDIUM',
37
38
  title: `${count} screen flow(s) run without user sharing context`,
38
39
  affectedItems: screenWithoutSharing.map((f) => ({
39
- label: f.MasterLabel,
40
- url: `${baseUrl}/builder_platform_interaction/flowBuilder.app?flowId=${f.Id}`,
40
+ label: f.masterLabel,
41
+ url: `${baseUrl}/builder_platform_interaction/flowBuilder.app?flowId=${f.id}`,
41
42
  note: 'Review and set "Run Flow As" to "User" where appropriate',
42
43
  })),
43
44
  detail: "Screen flows in Default Mode may allow users to view or modify records they wouldn't normally have access to.",
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Flags guest (unauthenticated) users whose profile/permission-sets grant API or
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class GuestExecutableApexCheck implements SecurityCheck {
4
4
  readonly id = "guest-executable-apex";
@@ -1,3 +1,4 @@
1
+ import { ApexRepository } from '@cclabsnz/sf-core';
1
2
  const WITHOUT_SHARING = /\bwithout\s+sharing\b/i;
2
3
  const WITH_SHARING = /\bwith\s+sharing\b/i;
3
4
  export class GuestExecutableApexCheck {
@@ -40,9 +41,9 @@ export class GuestExecutableApexCheck {
40
41
  });
41
42
  return { findings };
42
43
  }
43
- const idList = classIds.map((id) => `'${id}'`).join(', ');
44
- const names = await ctx.tooling.query(`SELECT Id, Name FROM ApexClass WHERE Id IN (${idList})`);
45
- const nameById = new Map(names.map((n) => [n.Id, n.Name]));
44
+ // Ids are validated inside the repository: one malformed value in an IN(...) clause
45
+ // fails the whole query with "invalid ID field", losing every good row with it.
46
+ const nameById = await new ApexRepository(ctx.tooling).namesByIds(classIds);
46
47
  const bodies = ctx.cache.apexBodies ?? [];
47
48
  const bodyByName = new Map(bodies.map((b) => [b.name, b.body]));
48
49
  const unprotected = [];
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Detects every object an unauthenticated guest can READ IN BULK. Unlike
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Verifies the PREVENTIVE guardrail that stops the guest-ownership-defeats-OWD
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Flags two Experience Cloud Network settings that widen the unauthenticated
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class GuestTrafficAnomalyCheck implements SecurityCheck {
4
4
  readonly id = "guest-traffic-anomaly";
@@ -1,4 +1,4 @@
1
- import { classifyEventLogAccessError } from '../eventLogAccess.js';
1
+ import { classifyEventLogAccessError } from '@cclabsnz/sf-core';
2
2
  // EventLogFile types that carry unauthenticated guest request traffic. Sites is
3
3
  // the primary guest-page channel; AuraRequest and GraphQlQueryExecution are the
4
4
  // data-access vectors abused for recon and bulk read.
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class GuestUserAccessCheck implements SecurityCheck {
4
4
  readonly id = "guest-user-access";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class HardcodedCredentialsCheck implements SecurityCheck {
4
4
  readonly id = "hardcoded-credentials";
@@ -1,3 +1,4 @@
1
+ import { ApexRepository } from '@cclabsnz/sf-core';
1
2
  const HIGH_RISK_PATTERNS = [
2
3
  /Bearer\s+[A-Za-z0-9\-_.~+/]{20,}=*/gi, // Bearer tokens (min length to avoid test stubs)
3
4
  /Basic\s+[A-Za-z0-9+/]{20,}=*/gi, // Basic auth (min length)
@@ -31,7 +32,13 @@ export class HardcodedCredentialsCheck {
31
32
  const findings = [];
32
33
  const baseUrl = ctx.orgInfo.instanceUrl;
33
34
  const apexClassesUrl = `${baseUrl}/lightning/setup/ApexClasses/home`;
34
- const records = await ctx.tooling.query('SELECT Id, Name, Body, LengthWithoutComments, NamespacePrefix FROM ApexClass WHERE NamespacePrefix = null');
35
+ const records = (await new ApexRepository(ctx.tooling).listClasses({ excludeManaged: true })).map((c) => ({
36
+ Id: c.name,
37
+ Name: c.name,
38
+ Body: c.body ?? '',
39
+ LengthWithoutComments: (c.body ?? '').length,
40
+ NamespacePrefix: c.namespace,
41
+ }));
35
42
  // Cache apex bodies for downstream checks — exclude test classes and filter null bodies
36
43
  const nonTestRecords = records.filter((r) => !IS_TEST_CLASS.test(r.Body ?? ''));
37
44
  ctx.cache.apexBodies = nonTestRecords.map((r) => ({ name: r.Name, body: r.Body ?? '' }));
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class HealthCheckCheck implements SecurityCheck {
4
4
  readonly id = "health-check";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class HighAssuranceSessionCheck implements SecurityCheck {
4
4
  readonly id = "high-assurance-session";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class InactiveUsersCheck implements SecurityCheck {
4
4
  readonly id = "inactive-users";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class InstalledPackagesCheck implements SecurityCheck {
4
4
  readonly id = "installed-packages";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class IntegrationUsersCheck implements SecurityCheck {
4
4
  readonly id = "integration-users";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class InternalUserMfaCheck implements SecurityCheck {
4
4
  readonly id = "internal-user-mfa";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class IpRestrictionsCheck implements SecurityCheck {
4
4
  readonly id = "ip-restrictions";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class LegacyApiVersionCheck implements SecurityCheck {
4
4
  readonly id = "legacy-api-version";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Surfaces impersonation / delegated-administration paths that bypass a user's
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Complements `failed-login-detection` (which only sees failures) by looking at
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class LoginSessionCheck implements SecurityCheck {
4
4
  readonly id = "login-session";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class MfaEnforcementCheck implements SecurityCheck {
4
4
  readonly id = "mfa-enforcement";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class MfaMethodStrengthCheck implements SecurityCheck {
4
4
  readonly id = "mfa-method-strength";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class MfaRegistrationCheck implements SecurityCheck {
4
4
  readonly id = "mfa-registration";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class MyDomainLoginPolicyCheck implements SecurityCheck {
4
4
  readonly id = "my-domain-login-policy";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class NamedCredentialsCheck implements SecurityCheck {
4
4
  readonly id = "named-credentials";
@@ -1,3 +1,5 @@
1
+ import { ApexRepository } from '@cclabsnz/sf-core';
2
+ import { referencesCallout } from '../../lib/apexRefs.js';
1
3
  export class NamedCredentialsCheck {
2
4
  id = 'named-credentials';
3
5
  name = 'Named Credentials';
@@ -12,7 +14,7 @@ export class NamedCredentialsCheck {
12
14
  const records = await ctx.tooling.query('SELECT Id, MasterLabel, DeveloperName, Endpoint, PrincipalType FROM NamedCredential');
13
15
  const count = records.length;
14
16
  // Cache the endpoints for use by HardcodedCredentialsCheck
15
- ctx.cache.namedCredentialEndpoints = records.map((r) => r.Endpoint);
17
+ ctx.cache.namedCredentialEndpoints = records.map((r) => r.Endpoint).filter((e) => !!e);
16
18
  if (count === 0) {
17
19
  findings.push({
18
20
  id: 'named-credentials-none',
@@ -29,8 +31,8 @@ export class NamedCredentialsCheck {
29
31
  let apexBodies = ctx.cache.apexBodies ?? [];
30
32
  if (apexBodies.length === 0) {
31
33
  try {
32
- const apexRecords = await ctx.tooling.query('SELECT Name, Body FROM ApexClass WHERE NamespacePrefix = null');
33
- apexBodies = apexRecords.map((r) => ({ name: r.Name, body: r.Body ?? '' }));
34
+ const apexRecords = await new ApexRepository(ctx.tooling).listClasses({ excludeManaged: true });
35
+ apexBodies = apexRecords.map((r) => ({ name: r.name, body: r.body ?? '' }));
34
36
  }
35
37
  catch {
36
38
  // If we can't scan Apex, emit inventory only
@@ -44,7 +46,7 @@ export class NamedCredentialsCheck {
44
46
  affectedItems: records.map((r) => ({
45
47
  label: r.MasterLabel,
46
48
  url: setupUrl,
47
- note: r.Endpoint,
49
+ note: r.Endpoint ?? '(no endpoint — External Credential)',
48
50
  })),
49
51
  });
50
52
  return { findings, metrics: { namedCredentialsCount: count, unusedNamedCredentialsCount: 0 } };
@@ -53,9 +55,11 @@ export class NamedCredentialsCheck {
53
55
  const combinedApexSource = apexBodies.map((c) => c.body).join('\n');
54
56
  const unusedCredentials = records.filter((r) => {
55
57
  // Named credentials are referenced as callout:DeveloperName or callout:MasterLabel
56
- const refPatternDev = new RegExp(`callout:${r.DeveloperName}\\b`, 'i');
57
- const refPatternLabel = new RegExp(`callout:${r.MasterLabel.replace(/\s+/g, '_')}\\b`, 'i');
58
- return !refPatternDev.test(combinedApexSource) && !refPatternLabel.test(combinedApexSource);
58
+ // Literal search, not a pattern built from the credential's own name: MasterLabel is free
59
+ // text from Setup, and a bracket in it used to crash the check while a quantifier quietly
60
+ // matched the wrong thing.
61
+ return (!referencesCallout(combinedApexSource, r.DeveloperName) &&
62
+ !referencesCallout(combinedApexSource, r.MasterLabel.replace(/\s+/g, '_')));
59
63
  });
60
64
  const usedCredentials = records.filter((r) => !unusedCredentials.includes(r));
61
65
  // Inventory finding
@@ -69,7 +73,7 @@ export class NamedCredentialsCheck {
69
73
  affectedItems: records.map((r) => ({
70
74
  label: r.MasterLabel,
71
75
  url: setupUrl,
72
- note: r.Endpoint,
76
+ note: r.Endpoint ?? '(no endpoint — External Credential)',
73
77
  })),
74
78
  });
75
79
  // Flag unused credentials
@@ -89,7 +93,7 @@ export class NamedCredentialsCheck {
89
93
  });
90
94
  }
91
95
  // SBS-INT-003: flag plaintext HTTP endpoints — credentials transmitted unencrypted in transit.
92
- const httpEndpoints = records.filter((r) => r.Endpoint.startsWith('http://'));
96
+ const httpEndpoints = records.filter((r) => r.Endpoint?.startsWith('http://') ?? false);
93
97
  if (httpEndpoints.length > 0) {
94
98
  findings.push({
95
99
  id: 'named-credentials-http-endpoint',
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class OutboundMessagesCheck implements SecurityCheck {
4
4
  readonly id = "outbound-messages";
@@ -1,6 +1,6 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
- import type { AuditCache } from '../../context/AuditCache.js';
3
+ import type { AuditCache } from '@cclabsnz/sf-core';
4
4
  export declare class PasswordSessionPolicyCheck implements SecurityCheck {
5
5
  readonly id = "password-session-policy";
6
6
  readonly name = "Password and Session Policy";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class PermissionsCheck implements SecurityCheck {
4
4
  readonly id = "permissions";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class PrivilegedAccessCheck implements SecurityCheck {
4
4
  readonly id = "privileged-access";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class PublicContentExposureCheck implements SecurityCheck {
4
4
  readonly id = "public-content-exposure";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class PublicGroupSharingCheck implements SecurityCheck {
4
4
  readonly id = "public-group-sharing";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class ReleaseUpdatesCheck implements SecurityCheck {
4
4
  readonly id = "release-updates";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class RemoteSitesCheck implements SecurityCheck {
4
4
  readonly id = "remote-sites";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class ReportFolderAccessCheck implements SecurityCheck {
4
4
  readonly id = "report-folder-access";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Advisory for sandboxes: production data copied into a sandbox and left unmasked
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class ScheduledApexCheck implements SecurityCheck {
4
4
  readonly id = "scheduled-apex";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class SeparationOfDutiesCheck implements SecurityCheck {
4
4
  readonly id = "separation-of-duties";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  /**
4
4
  * Re-slices the Health Check risk set (populated by HealthCheckCheck, so no extra
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class SharingModelCheck implements SecurityCheck {
4
4
  readonly id = "sharing-model";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class SiemIntegrationCheck implements SecurityCheck {
4
4
  readonly id = "siem-integration";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class SsoEnforcementCheck implements SecurityCheck {
4
4
  readonly id = "sso-enforcement";
@@ -1,4 +1,4 @@
1
- import type { AuditContext } from '../../context/AuditContext.js';
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
2
  import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
3
  export declare class StandardProfilesCheck implements SecurityCheck {
4
4
  readonly id = "standard-profiles";