@cclabsnz/sf-audit 1.8.1 → 1.9.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 (77) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/README.md +138 -758
  3. package/lib/chains/CapabilityRegistry.d.ts +6 -2
  4. package/lib/chains/CapabilityRegistry.js +48 -2
  5. package/lib/chains/namedChains.js +140 -7
  6. package/lib/checks/impl/AgentActionSurfaceCheck.d.ts +1 -1
  7. package/lib/checks/impl/AgentChannelExposureCheck.d.ts +1 -1
  8. package/lib/checks/impl/AgentChannelExposureCheck.js +52 -10
  9. package/lib/checks/impl/AgentInventoryCheck.d.ts +1 -1
  10. package/lib/checks/impl/AgentMonitoringCoverageCheck.d.ts +1 -1
  11. package/lib/checks/impl/AgentUserPrivilegeCheck.d.ts +1 -1
  12. package/lib/checks/impl/ApexCrudFLSCheck.d.ts +1 -1
  13. package/lib/checks/impl/ApexCrudFLSCheck.js +3 -3
  14. package/lib/checks/impl/ApexLoggingCheck.d.ts +1 -1
  15. package/lib/checks/impl/ApexRestEndpointCheck.d.ts +1 -1
  16. package/lib/checks/impl/ApexRestEndpointCheck.js +0 -3
  17. package/lib/checks/impl/ApexSharingCheck.d.ts +1 -1
  18. package/lib/checks/impl/CodeSecurityCheck.d.ts +1 -1
  19. package/lib/checks/impl/ConnectedAppInactivityCheck.d.ts +1 -1
  20. package/lib/checks/impl/ConnectedAppsCheck.d.ts +1 -1
  21. package/lib/checks/impl/CspTrustedSitesCheck.d.ts +1 -1
  22. package/lib/checks/impl/CustomLabelsCredentialCheck.js +1 -1
  23. package/lib/checks/impl/DataClassificationCheck.js +15 -1
  24. package/lib/checks/impl/DeploymentIdentityCheck.d.ts +1 -1
  25. package/lib/checks/impl/EventMonitoringCheck.d.ts +1 -1
  26. package/lib/checks/impl/FailedLoginCheck.js +16 -1
  27. package/lib/checks/impl/FieldLevelSecurityCheck.js +29 -16
  28. package/lib/checks/impl/GuestExecutableApexCheck.d.ts +1 -1
  29. package/lib/checks/impl/GuestTrafficAnomalyCheck.d.ts +1 -1
  30. package/lib/checks/impl/GuestUserAccessCheck.d.ts +1 -1
  31. package/lib/checks/impl/GuestUserVisibilityCheck.d.ts +35 -0
  32. package/lib/checks/impl/GuestUserVisibilityCheck.js +168 -0
  33. package/lib/checks/impl/HardcodedCredentialsCheck.d.ts +2 -2
  34. package/lib/checks/impl/HardcodedCredentialsCheck.js +0 -1
  35. package/lib/checks/impl/HealthCheckCheck.d.ts +1 -1
  36. package/lib/checks/impl/HealthCheckCheck.js +1 -3
  37. package/lib/checks/impl/IntegrationLeastPrivilegeCheck.d.ts +42 -0
  38. package/lib/checks/impl/IntegrationLeastPrivilegeCheck.js +467 -0
  39. package/lib/checks/impl/IntegrationUsersCheck.js +48 -52
  40. package/lib/checks/impl/InternalUserMfaCheck.js +0 -1
  41. package/lib/checks/impl/IpRestrictionsCheck.js +39 -5
  42. package/lib/checks/impl/MfaMethodStrengthCheck.d.ts +1 -1
  43. package/lib/checks/impl/MfaRegistrationCheck.d.ts +1 -1
  44. package/lib/checks/impl/NamedCredentialsCheck.d.ts +1 -1
  45. package/lib/checks/impl/PrivilegedAccessCheck.d.ts +1 -1
  46. package/lib/checks/impl/PublicGroupSharingCheck.d.ts +1 -1
  47. package/lib/checks/impl/PublicGroupSharingCheck.js +21 -2
  48. package/lib/checks/impl/RemoteSitesCheck.d.ts +1 -1
  49. package/lib/checks/impl/ScheduledApexCheck.d.ts +1 -1
  50. package/lib/checks/impl/ScheduledApexCheck.js +0 -1
  51. package/lib/checks/impl/SeparationOfDutiesCheck.d.ts +1 -1
  52. package/lib/checks/impl/SessionHardeningCheck.d.ts +1 -1
  53. package/lib/checks/impl/SiemIntegrationCheck.d.ts +1 -1
  54. package/lib/checks/impl/SoapLoginApiAuthCheck.d.ts +10 -0
  55. package/lib/checks/impl/SoapLoginApiAuthCheck.js +151 -0
  56. package/lib/checks/impl/SsoEnforcementCheck.js +0 -1
  57. package/lib/checks/impl/TrustedUrlHygieneCheck.d.ts +1 -1
  58. package/lib/checks/impl/TrustedUrlHygieneCheck.js +3 -1
  59. package/lib/checks/impl/VisualforceXssCheck.d.ts +1 -1
  60. package/lib/checks/registry.js +4 -0
  61. package/lib/checks/support/integrationAccounts.d.ts +35 -0
  62. package/lib/checks/support/integrationAccounts.js +209 -0
  63. package/lib/commands/audit/security.d.ts +12 -1
  64. package/lib/commands/audit/security.js +32 -9
  65. package/lib/compliance/catalogs/gdpr.d.ts +3 -0
  66. package/lib/compliance/catalogs/gdpr.js +54 -0
  67. package/lib/compliance/catalogs/hipaa.d.ts +3 -0
  68. package/lib/compliance/catalogs/hipaa.js +97 -0
  69. package/lib/compliance/catalogs/index.js +4 -0
  70. package/lib/compliance/mapping.js +111 -36
  71. package/lib/findings/CheckMeta.js +2 -0
  72. package/lib/findings/exitCode.d.ts +28 -0
  73. package/lib/findings/exitCode.js +46 -0
  74. package/lib/findings/loadScoringConfig.js +5 -5
  75. package/lib/renderers/HtmlRenderer.js +1 -1
  76. package/messages/audit.security.md +6 -0
  77. package/package.json +16 -11
@@ -33,13 +33,16 @@ export class DataClassificationCheck {
33
33
  // EncryptionKey records indicate Shield is licensed and active.
34
34
  let encryptionEnabled = false;
35
35
  let encryptionKeyCount = 0;
36
+ let encryptionQueryFailed = false;
36
37
  try {
37
38
  const encResult = await ctx.soql.query('SELECT Id, DeveloperName FROM EncryptionKey LIMIT 10');
38
39
  encryptionKeyCount = encResult.records.length;
39
40
  encryptionEnabled = encryptionKeyCount > 0;
40
41
  }
41
42
  catch {
42
- // EncryptionKey inaccessible — Shield not licensed or no permission to read keys
43
+ // Unreadable is not the same as absent: an org may hold Shield keys the audit user
44
+ // cannot see, and "not detected" would assert something this query never established.
45
+ encryptionQueryFailed = true;
43
46
  }
44
47
  // SBS-DATA-001/002: data classification coverage
45
48
  if (classificationQueryFailed) {
@@ -96,6 +99,17 @@ export class DataClassificationCheck {
96
99
  remediation: 'Verify encryption is applied to all fields classified as sensitive or PII. Review the Encryption Statistics page in Setup → Security → Platform Encryption to confirm field-level coverage.',
97
100
  });
98
101
  }
102
+ else if (encryptionQueryFailed) {
103
+ findings.push({
104
+ id: 'data-encryption-inconclusive',
105
+ category: this.category,
106
+ riskLevel: 'INFO',
107
+ inconclusive: true,
108
+ title: 'Shield Platform Encryption status could not be determined: SBS-DATA-003',
109
+ detail: 'The EncryptionKey object was not readable, so whether Shield Platform Encryption is configured is unknown. This is distinct from Shield being absent: an org may hold encryption keys that the audit user cannot see.',
110
+ remediation: 'Grant the audit user read access to EncryptionKey and re-run, or confirm encryption coverage manually in Setup → Security → Platform Encryption.',
111
+ });
112
+ }
99
113
  else {
100
114
  findings.push({
101
115
  id: 'data-encryption-not-detected',
@@ -5,7 +5,7 @@ export declare class DeploymentIdentityCheck implements SecurityCheck {
5
5
  readonly name = "Deployment Identity";
6
6
  readonly category = "Deployments";
7
7
  readonly description = "SBS-DEP-001/003: checks for a designated deployment identity and monitors for uncontrolled deployment activity";
8
- readonly dependsOnCache: readonly ["connectedAppNames"];
8
+ readonly dependsOnCache: readonly ['connectedAppNames'];
9
9
  run(ctx: AuditContext): Promise<CheckResult>;
10
10
  }
11
11
  //# sourceMappingURL=DeploymentIdentityCheck.d.ts.map
@@ -5,7 +5,7 @@ export declare class EventMonitoringCheck implements SecurityCheck {
5
5
  readonly name = "Event Monitoring Storage";
6
6
  readonly category = "Event Monitoring";
7
7
  readonly description = "SBS-MON-001 / SBS-INT-004: verifies Event Monitoring is enabled and logs cover at least 30 days";
8
- readonly populatesCache: readonly ["eventLogSummary"];
8
+ readonly populatesCache: readonly ['eventLogSummary'];
9
9
  run(ctx: AuditContext): Promise<CheckResult>;
10
10
  }
11
11
  //# sourceMappingURL=EventMonitoringCheck.d.ts.map
@@ -43,6 +43,7 @@ export class FailedLoginCheck {
43
43
  }
44
44
  // Query 2: per-user aggregation to detect targeted brute force
45
45
  let perUserCounts = [];
46
+ let perUserUnavailable = false;
46
47
  try {
47
48
  const aggResult = await ctx.soql.query(`SELECT Username, COUNT(Id)
48
49
  FROM LoginHistory
@@ -53,7 +54,9 @@ export class FailedLoginCheck {
53
54
  perUserCounts = aggResult.records;
54
55
  }
55
56
  catch {
56
- // Per-user breakdown unavailable — still emit org-level finding
57
+ // Recorded: without the per-user breakdown, "no brute-force pattern" is not a
58
+ // conclusion this check can reach, only a question it could not answer.
59
+ perUserUnavailable = true;
57
60
  }
58
61
  const bruteForceTargets = perUserCounts.filter((r) => r.expr0 >= BRUTE_FORCE_PER_USER);
59
62
  const heavyTargets = bruteForceTargets.filter((r) => r.expr0 >= BULK_THRESHOLD_PER_USER);
@@ -105,6 +108,18 @@ export class FailedLoginCheck {
105
108
  ],
106
109
  });
107
110
  }
111
+ else if (totalFailures > 0 && bruteForceTargets.length === 0 && perUserUnavailable) {
112
+ findings.push({
113
+ id: 'failed-login-per-user-unavailable',
114
+ category: this.category,
115
+ riskLevel: 'INFO',
116
+ inconclusive: true,
117
+ title: `${totalFailures} failed login(s) in 7 days, but the per-account breakdown could not be read`,
118
+ detail: `${totalFailures} failed login attempts were recorded org-wide in the last 7 days. The per-username aggregation was not available, so whether any single account is under a brute-force attack could not be determined. The total alone does not distinguish widespread user error from a concentrated attack on one account.`,
119
+ remediation: 'Grant the audit user access to aggregate LoginHistory queries and re-run, or review Login History grouped by username manually in Setup.',
120
+ affectedItems: [{ label: 'Org-wide login activity', url: setupUrl, note: `${totalFailures} failures in 7 days` }],
121
+ });
122
+ }
108
123
  else if (totalFailures > 0 && bruteForceTargets.length === 0) {
109
124
  findings.push({
110
125
  id: 'failed-login-low-volume',
@@ -46,6 +46,7 @@ export class FieldLevelSecurityCheck {
46
46
  // - An API name string like 'Account' (standard objects) — use directly
47
47
  const sfIdPattern = /^[A-Za-z0-9]{15,18}$/;
48
48
  const objectApiNameById = new Map();
49
+ let entityLookupFailed = false;
49
50
  const customObjectIds = [];
50
51
  for (const field of sensitiveFields) {
51
52
  const teo = field.TableEnumOrId;
@@ -65,7 +66,9 @@ export class FieldLevelSecurityCheck {
65
66
  }
66
67
  }
67
68
  catch {
68
- // If entity lookup fails, custom object field names will be unresolvable
69
+ // Recorded, not swallowed: without these names the fields cannot be analysed, and a
70
+ // silent failure here previously surfaced as a clean pass.
71
+ entityLookupFailed = true;
69
72
  }
70
73
  }
71
74
  // Build field API names: {ObjectApiName}.{DeveloperName}__c
@@ -76,15 +79,18 @@ export class FieldLevelSecurityCheck {
76
79
  fieldApiNames.push(`${objectApiName}.${field.DeveloperName}__c`);
77
80
  }
78
81
  }
82
+ const unresolvedCount = sensitiveFields.length - fieldApiNames.length;
79
83
  if (fieldApiNames.length === 0) {
80
84
  findings.push({
81
- id: 'field-level-security-ok',
85
+ id: 'field-level-security-unresolved',
82
86
  category: this.category,
83
- riskLevel: 'LOW',
84
- passed: true,
85
- title: 'Sensitive custom fields appear appropriately restricted',
86
- detail: 'No sensitive custom fields with excessive permission set access were found.',
87
- remediation: 'Continue to apply restrictive field-level security to any new sensitive fields.',
87
+ riskLevel: 'INFO',
88
+ inconclusive: true,
89
+ title: `Field-level security could not be evaluated for ${sensitiveFields.length} sensitive field(s)`,
90
+ detail: `${sensitiveFields.length} sensitive custom field(s) were found, but their object API names could not be resolved` +
91
+ `${entityLookupFailed ? ' because the EntityDefinition lookup was not accessible' : ''}. ` +
92
+ 'Field-level security was therefore not evaluated for any of them. This is an incomplete result, not a clean one.',
93
+ remediation: 'Grant the audit user access to the Tooling API EntityDefinition object and re-run, then review field-level security on the reported fields.',
88
94
  });
89
95
  return { findings };
90
96
  }
@@ -98,13 +104,15 @@ export class FieldLevelSecurityCheck {
98
104
  }
99
105
  catch {
100
106
  findings.push({
101
- id: 'field-level-security-ok',
107
+ id: 'field-level-security-inaccessible',
102
108
  category: this.category,
103
- riskLevel: 'LOW',
104
- passed: true,
105
- title: 'Sensitive custom fields appear appropriately restricted',
106
- detail: 'No sensitive custom fields with excessive permission set access were found.',
107
- remediation: 'Continue to apply restrictive field-level security to any new sensitive fields.',
109
+ riskLevel: 'INFO',
110
+ inconclusive: true,
111
+ title: `Field-level security could not be evaluated for ${fieldApiNames.length} sensitive field(s)`,
112
+ detail: 'The FieldPermissions query was not accessible, so how widely these sensitive fields are readable could not be determined. ' +
113
+ 'The fields themselves were found; only their exposure is unknown.',
114
+ remediation: 'Grant the audit user access to FieldPermissions and re-run. Until then, review field-level security manually for the fields listed.',
115
+ affectedItems: fieldApiNames.map((f) => ({ label: f })),
108
116
  });
109
117
  return { findings };
110
118
  }
@@ -151,9 +159,14 @@ export class FieldLevelSecurityCheck {
151
159
  id: 'field-level-security-ok',
152
160
  category: this.category,
153
161
  riskLevel: 'LOW',
154
- passed: true,
155
- title: 'Sensitive custom fields appear appropriately restricted',
156
- detail: 'No sensitive custom fields with excessive permission set access were found.',
162
+ // A pass only where the analysis actually covered everything found.
163
+ ...(unresolvedCount > 0 ? { inconclusive: true } : { passed: true }),
164
+ title: unresolvedCount > 0
165
+ ? `Sensitive custom fields appear restricted, but ${unresolvedCount} could not be evaluated`
166
+ : 'Sensitive custom fields appear appropriately restricted',
167
+ detail: unresolvedCount > 0
168
+ ? `No excessive permission-set access was found among the ${fieldApiNames.length} field(s) that could be evaluated, but ${unresolvedCount} sensitive field(s) could not be resolved to an object and were not checked.`
169
+ : 'No sensitive custom fields with excessive permission set access were found.',
157
170
  remediation: 'Continue to apply restrictive field-level security to any new sensitive fields.',
158
171
  });
159
172
  }
@@ -5,7 +5,7 @@ export declare class GuestExecutableApexCheck implements SecurityCheck {
5
5
  readonly name = "Guest-Executable Apex";
6
6
  readonly category = "Access Control";
7
7
  readonly description = "Finds Apex classes that unauthenticated guest profiles can execute, flagging those that run without sharing: the classic unauthenticated data-exfiltration vector";
8
- readonly dependsOnCache: readonly ["apexBodies"];
8
+ readonly dependsOnCache: readonly ['apexBodies'];
9
9
  run(ctx: AuditContext): Promise<CheckResult>;
10
10
  }
11
11
  //# sourceMappingURL=GuestExecutableApexCheck.d.ts.map
@@ -5,7 +5,7 @@ export declare class GuestTrafficAnomalyCheck implements SecurityCheck {
5
5
  readonly name = "Guest Traffic Anomaly";
6
6
  readonly category = "Threat Detection";
7
7
  readonly description = "Scans recent EventLogFile guest requests for anonymizer/hosting source IPs, single-IP bursts, and GraphQL totalCount reconnaissance sweeps";
8
- readonly dependsOnCache: readonly ["eventLogSummary"];
8
+ readonly dependsOnCache: readonly ['eventLogSummary'];
9
9
  run(ctx: AuditContext): Promise<CheckResult>;
10
10
  /** Parse an EventLogFile CSV, pushing guest-attributed rows into `out`. */
11
11
  private parseGuestRows;
@@ -5,7 +5,7 @@ export declare class GuestUserAccessCheck implements SecurityCheck {
5
5
  readonly name = "Guest User Access";
6
6
  readonly category = "Access Control";
7
7
  readonly description = "Audits object permissions and sharing rules granted to unauthenticated guest users";
8
- readonly dependsOnCache: readonly ["healthCloudInstalled"];
8
+ readonly dependsOnCache: readonly ['healthCloudInstalled'];
9
9
  run(ctx: AuditContext): Promise<CheckResult>;
10
10
  }
11
11
  //# sourceMappingURL=GuestUserAccessCheck.d.ts.map
@@ -0,0 +1,35 @@
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ /**
4
+ * Detects whether unauthenticated guests can see OTHER USERS — the identity-
5
+ * enumeration surface that the object-level guest checks miss, because `User` is
6
+ * not in their fixed object lists and is rarely surfaced by a guest profile's
7
+ * ObjectPermissions.
8
+ *
9
+ * Three independent paths reach the same outcome, so all three are graded:
10
+ * - "View All Users" on a guest profile/permission set: total bypass of User
11
+ * sharing, every User record readable regardless of OWD (CRITICAL).
12
+ * - A public EXTERNAL org-wide default on `User` (Read/ReadWrite): every User
13
+ * record is visible to portal and guest users by sharing alone (HIGH).
14
+ * - An explicit Read grant on `User` in a guest permission set, which combined
15
+ * with any sharing path turns the roster into a queryable directory (HIGH).
16
+ *
17
+ * The INTERNAL sharing model is reported for context but never graded: `User`
18
+ * ships as Public Read Only in every org, so grading it would fire on every audit.
19
+ *
20
+ * One leg is deliberately not asserted: the "Portal User Visibility" / "Community
21
+ * User Visibility" checkboxes in Setup → Sharing Settings are not exposed to any
22
+ * read API this plugin uses, so a clean result carries an explicit manual-
23
+ * verification note rather than claiming more certainty than the data supports.
24
+ * The Experience Cloud per-site equivalent ("Let guest users see other members")
25
+ * IS API-readable and is covered by `guest-site-options`.
26
+ */
27
+ export declare class GuestUserVisibilityCheck implements SecurityCheck {
28
+ readonly id = "guest-user-visibility";
29
+ readonly name = "Guest Visibility of Other Users";
30
+ readonly category = "Access Control";
31
+ readonly description = "Checks whether unauthenticated guests can see other User records \u2014 via View All Users, a public external OWD on User, or a guest Read grant on the User object";
32
+ run(ctx: AuditContext): Promise<CheckResult>;
33
+ private inconclusive;
34
+ }
35
+ //# sourceMappingURL=GuestUserVisibilityCheck.d.ts.map
@@ -0,0 +1,168 @@
1
+ // External sharing models that expose every User record to external (portal/guest) users.
2
+ const PUBLIC_OWD = new Set(['Read', 'ReadWrite', 'ReadSelect']);
3
+ /**
4
+ * Detects whether unauthenticated guests can see OTHER USERS — the identity-
5
+ * enumeration surface that the object-level guest checks miss, because `User` is
6
+ * not in their fixed object lists and is rarely surfaced by a guest profile's
7
+ * ObjectPermissions.
8
+ *
9
+ * Three independent paths reach the same outcome, so all three are graded:
10
+ * - "View All Users" on a guest profile/permission set: total bypass of User
11
+ * sharing, every User record readable regardless of OWD (CRITICAL).
12
+ * - A public EXTERNAL org-wide default on `User` (Read/ReadWrite): every User
13
+ * record is visible to portal and guest users by sharing alone (HIGH).
14
+ * - An explicit Read grant on `User` in a guest permission set, which combined
15
+ * with any sharing path turns the roster into a queryable directory (HIGH).
16
+ *
17
+ * The INTERNAL sharing model is reported for context but never graded: `User`
18
+ * ships as Public Read Only in every org, so grading it would fire on every audit.
19
+ *
20
+ * One leg is deliberately not asserted: the "Portal User Visibility" / "Community
21
+ * User Visibility" checkboxes in Setup → Sharing Settings are not exposed to any
22
+ * read API this plugin uses, so a clean result carries an explicit manual-
23
+ * verification note rather than claiming more certainty than the data supports.
24
+ * The Experience Cloud per-site equivalent ("Let guest users see other members")
25
+ * IS API-readable and is covered by `guest-site-options`.
26
+ */
27
+ export class GuestUserVisibilityCheck {
28
+ id = 'guest-user-visibility';
29
+ name = 'Guest Visibility of Other Users';
30
+ category = 'Access Control';
31
+ description = 'Checks whether unauthenticated guests can see other User records — via View All Users, a public external OWD on User, or a guest Read grant on the User object';
32
+ async run(ctx) {
33
+ const findings = [];
34
+ const baseUrl = ctx.orgInfo.instanceUrl;
35
+ const sharingUrl = `${baseUrl}/lightning/setup/SecuritySharing/page`;
36
+ const permSetUrl = `${baseUrl}/lightning/setup/PermSets/home`;
37
+ let guests;
38
+ try {
39
+ guests = await ctx.soql.queryAll("SELECT Id, Username FROM User WHERE UserType = 'Guest' AND IsActive = true");
40
+ }
41
+ catch {
42
+ findings.push(this.inconclusive('guest-user-visibility-inaccessible', 'Guest users could not be queried'));
43
+ return { findings };
44
+ }
45
+ if (guests.length === 0) {
46
+ findings.push({
47
+ id: 'guest-user-visibility-none',
48
+ category: this.category,
49
+ riskLevel: 'LOW',
50
+ passed: true,
51
+ title: 'No active guest users',
52
+ detail: 'There are no active guest users, so no unauthenticated visitor can enumerate the org\'s User records.',
53
+ remediation: 'If an Experience Cloud or Sites site is added later, keep the external org-wide default on User set to Private and keep "View All Users" off every guest profile.',
54
+ });
55
+ return { findings };
56
+ }
57
+ const inIds = guests.map((g) => `'${g.Id}'`).join(', ');
58
+ let psa;
59
+ try {
60
+ psa = await ctx.soql.queryAll(`SELECT AssigneeId, PermissionSetId, PermissionSet.Label, PermissionSet.PermissionsViewAllUsers
61
+ FROM PermissionSetAssignment WHERE AssigneeId IN (${inIds})`);
62
+ }
63
+ catch {
64
+ findings.push(this.inconclusive('guest-user-visibility-perms-inaccessible', 'Guest permission sets could not be queried'));
65
+ return { findings };
66
+ }
67
+ const guestById = new Map(guests.map((g) => [g.Id, g]));
68
+ const labelById = new Map(psa.filter((p) => p.PermissionSet).map((p) => [p.PermissionSetId, p.PermissionSet.Label]));
69
+ // 1. "View All Users" — bypasses User sharing entirely.
70
+ const viewAll = psa.filter((p) => p.PermissionSet?.PermissionsViewAllUsers);
71
+ if (viewAll.length > 0) {
72
+ findings.push({
73
+ id: 'guest-user-visibility-view-all-users',
74
+ category: this.category,
75
+ riskLevel: 'CRITICAL',
76
+ title: `${viewAll.length} guest permission grant(s) include "View All Users"`,
77
+ detail: '"View All Users" lets the holder read every User record in the org regardless of the sharing model. On a guest user this hands an unauthenticated visitor the full staff roster — usernames, email addresses, roles, manager relationships and phone numbers — which is a ready-made target list for credential stuffing, phishing and social engineering against named administrators.',
78
+ remediation: 'Remove "View All Users" from the guest profile and from every permission set assigned to a guest user. Guests must never hold org-wide user visibility.',
79
+ affectedItems: viewAll.slice(0, 30).map((p) => ({
80
+ label: `${guestById.get(p.AssigneeId)?.Username ?? p.AssigneeId} — via ${p.PermissionSet.Label}`,
81
+ url: permSetUrl,
82
+ note: 'View All Users granted: remove immediately',
83
+ })),
84
+ });
85
+ }
86
+ // 2. External org-wide default on User.
87
+ let userEntity;
88
+ try {
89
+ const defs = await ctx.soql.queryAll("SELECT QualifiedApiName, InternalSharingModel, ExternalSharingModel FROM EntityDefinition WHERE QualifiedApiName = 'User'");
90
+ userEntity = defs.find((d) => d.QualifiedApiName === 'User');
91
+ }
92
+ catch {
93
+ // OWD unreadable — the other two signals are still graded below.
94
+ }
95
+ const external = userEntity?.ExternalSharingModel ?? null;
96
+ const internal = userEntity?.InternalSharingModel ?? null;
97
+ if (external && PUBLIC_OWD.has(external)) {
98
+ findings.push({
99
+ id: 'guest-user-visibility-owd',
100
+ category: this.category,
101
+ riskLevel: 'HIGH',
102
+ title: `The User object has a public external org-wide default (${external})`,
103
+ detail: 'The external org-wide default on User controls what portal and guest users can see of other users. Set to Read or Read/Write, every User record in the org is visible to any external or unauthenticated visitor by sharing alone — no permission grant required — turning the site into a directory of internal staff.',
104
+ remediation: 'Set the User object\'s Default External Access to Private in Setup → Sharing Settings. Where portal users legitimately need to see each other, grant it narrowly with sharing sets or user sharing rules rather than an open default.',
105
+ affectedItems: [
106
+ {
107
+ label: 'User',
108
+ url: sharingUrl,
109
+ note: `External OWD: ${external}${internal ? ` (internal: ${internal})` : ''} — ${guests.length} active guest user(s)`,
110
+ },
111
+ ],
112
+ });
113
+ }
114
+ // 3. Explicit Read grant on the User object in a guest permission set.
115
+ const psIds = [...new Set(psa.map((p) => p.PermissionSetId))];
116
+ let userRead = [];
117
+ if (psIds.length > 0) {
118
+ try {
119
+ const psIn = psIds.map((i) => `'${i}'`).join(', ');
120
+ userRead = await ctx.soql.queryAll(`SELECT ParentId, SobjectType, PermissionsRead FROM ObjectPermissions
121
+ WHERE ParentId IN (${psIn}) AND SobjectType = 'User' AND PermissionsRead = true`);
122
+ }
123
+ catch {
124
+ // Object permissions unreadable — the other two signals still stand.
125
+ }
126
+ }
127
+ if (userRead.length > 0) {
128
+ findings.push({
129
+ id: 'guest-user-visibility-object-read',
130
+ category: this.category,
131
+ riskLevel: 'HIGH',
132
+ title: `${userRead.length} guest permission grant(s) give Read access to the User object`,
133
+ detail: 'A guest permission set or profile grants Read on the User object. Object-level read is what makes User queryable at all for a guest; combined with any sharing path that exposes records — a public external OWD, a user sharing rule, or guest member visibility on an Experience site — it turns the User table into an enumerable directory reachable over the UI API.',
134
+ remediation: 'Remove Read on the User object from guest profiles and guest permission sets. Where site components must show a name, expose it through Apex that returns only the specific fields required.',
135
+ affectedItems: userRead.slice(0, 30).map((p) => ({
136
+ label: labelById.get(p.ParentId) ?? p.ParentId,
137
+ url: permSetUrl,
138
+ note: 'Read on User granted: remove from guest permissions',
139
+ })),
140
+ });
141
+ }
142
+ if (findings.length === 0) {
143
+ findings.push({
144
+ id: 'guest-user-visibility-ok',
145
+ category: this.category,
146
+ riskLevel: 'LOW',
147
+ passed: true,
148
+ title: `${guests.length} active guest user(s); no user-enumeration path found`,
149
+ detail: `No guest holds "View All Users", the User object's external org-wide default is ${external ?? 'not publicly readable'}, and no guest permission set grants Read on User.${internal ? ` The internal model is ${internal}, which is the platform default and is not graded here.` : ''} One control is not API-readable: the "Portal User Visibility" and "Community User Visibility" checkboxes in Sharing Settings are exposed to no read API this plugin uses, so that leg needs manual confirmation.`,
150
+ remediation: 'In Setup → Sharing Settings, confirm the portal/community user visibility checkboxes are off unless a member directory is intended, and keep the User external default Private as sites are added. The per-site equivalent ("Let guest users see other members") is covered by the Experience Cloud Guest Site Options check.',
151
+ affectedItems: [{ label: 'Sharing Settings', url: sharingUrl, note: 'Manual verification of user visibility checkboxes' }],
152
+ });
153
+ }
154
+ return { findings };
155
+ }
156
+ inconclusive(id, what) {
157
+ return {
158
+ id,
159
+ category: this.category,
160
+ riskLevel: 'INFO',
161
+ inconclusive: true,
162
+ title: `${what} (insufficient access)`,
163
+ detail: 'The audit user could not gather the data needed to evaluate guest visibility of other users.',
164
+ remediation: 'Grant the audit user View Setup and Configuration and re-run.',
165
+ };
166
+ }
167
+ }
168
+ //# sourceMappingURL=GuestUserVisibilityCheck.js.map
@@ -5,8 +5,8 @@ export declare class HardcodedCredentialsCheck implements SecurityCheck {
5
5
  readonly name = "Hardcoded Credentials";
6
6
  readonly category = "Code Security";
7
7
  readonly description = "Scans Apex code for hardcoded Bearer tokens, Basic auth, API keys, and raw callout URLs";
8
- readonly dependsOnCache: readonly ["namedCredentialEndpoints", "remoteSiteUrls"];
9
- readonly populatesCache: readonly ["apexBodies"];
8
+ readonly dependsOnCache: readonly ['namedCredentialEndpoints', 'remoteSiteUrls'];
9
+ readonly populatesCache: readonly ['apexBodies'];
10
10
  run(ctx: AuditContext): Promise<CheckResult>;
11
11
  }
12
12
  //# sourceMappingURL=HardcodedCredentialsCheck.d.ts.map
@@ -44,7 +44,6 @@ export class HardcodedCredentialsCheck {
44
44
  ctx.cache.apexBodies = nonTestRecords.map((r) => ({ name: r.Name, body: r.Body ?? '' }));
45
45
  const namedCredentialEndpoints = (ctx.cache.namedCredentialEndpoints ?? []).filter(Boolean);
46
46
  const remoteSiteUrls = (ctx.cache.remoteSiteUrls ?? []).filter(Boolean);
47
- const allCoveredEndpoints = [...namedCredentialEndpoints, ...remoteSiteUrls];
48
47
  const classesWithCredentials = [];
49
48
  const classesWithRawEndpointsUncovered = [];
50
49
  const classesWithRawEndpointsCoveredOnly = [];
@@ -5,7 +5,7 @@ export declare class HealthCheckCheck implements SecurityCheck {
5
5
  readonly name = "Security Health Check";
6
6
  readonly category = "Health Check";
7
7
  readonly description = "Reads the Salesforce Health Check score and flags individual risk items";
8
- readonly populatesCache: readonly ["healthCheckRisks", "healthCloudInstalled"];
8
+ readonly populatesCache: readonly ['healthCheckRisks', 'healthCloudInstalled'];
9
9
  run(ctx: AuditContext): Promise<CheckResult>;
10
10
  }
11
11
  //# sourceMappingURL=HealthCheckCheck.d.ts.map
@@ -25,9 +25,7 @@ export class HealthCheckCheck {
25
25
  });
26
26
  // HIGH_RISK items
27
27
  const highRisks = await ctx.tooling.query("SELECT RiskType, Setting, SettingGroup, OrgValue, StandardValue FROM SecurityHealthCheckRisks WHERE RiskType='HIGH_RISK'");
28
- ctx.cache.healthCheckRisks = [
29
- ...highRisks.map((r) => ({ setting: r.Setting, riskType: r.RiskType, value: r.OrgValue, score: 10 })),
30
- ];
28
+ ctx.cache.healthCheckRisks = highRisks.map((r) => ({ setting: r.Setting, riskType: r.RiskType, value: r.OrgValue, score: 10 }));
31
29
  if (highRisks.length > 0) {
32
30
  findings.push({
33
31
  id: 'health-check-high-risk',
@@ -0,0 +1,42 @@
1
+ import type { AuditContext } from '@cclabsnz/sf-core';
2
+ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
3
+ export declare class IntegrationLeastPrivilegeCheck implements SecurityCheck {
4
+ readonly id = "integration-least-privilege";
5
+ readonly name = "Integration Account Least Privilege";
6
+ readonly category = "Permissions";
7
+ readonly description = "Reports permissions held by integration and service accounts that the account is not using \u2014 escalation-grade permissions, bulk-data permissions, and standing-credential settings";
8
+ run(ctx: AuditContext): Promise<CheckResult>;
9
+ /** The degraded-signal qualification, agreeing in number with what was actually degraded. */
10
+ private degradedNote;
11
+ /**
12
+ * Whether the audit user itself can see every record in the org, which is what makes the write
13
+ * probe conclusive (see WRITE_VISIBILITY_CAVEAT).
14
+ *
15
+ * `AuditContext` carries the org, not the running user, and there is no SOQL expression for
16
+ * "the current user". The Connect API's `/chatter/users/me` is the one identity resource reachable
17
+ * through the existing read-only REST client; orgs with Chatter disabled, or any unexpected
18
+ * response, resolve as unknown. Every failure path returns a non-conclusive answer, so the worst
19
+ * outcome is that write evidence is reported as ungathered — never that it is reported as clean.
20
+ */
21
+ private recordVisibility;
22
+ /**
23
+ * Assignees of each granting permission set that are NOT in the resolved integration set.
24
+ *
25
+ * A grant reached through a profile, or through an org-wide permission set, is held by everyone
26
+ * assigned to it. "Remove this object permission" is safe advice on a dedicated integration set
27
+ * and destructive on a shared one, so the finding has to say which it is. Null when the count
28
+ * could not be established — an unknown breadth is reported as unknown, not as exclusive.
29
+ */
30
+ private assigneesOutsideSet;
31
+ /** Names the profile or permission set that grants write on `object`, and how widely it is held. */
32
+ private grantPathNote;
33
+ /**
34
+ * True if the account wrote any record of this object, false if none, null if unprobeable.
35
+ * Null must never be read as false — an object we could not query is not an unused grant.
36
+ */
37
+ private hasEverWritten;
38
+ /** Emits one finding for a permission class, or nothing when the class has no grants. */
39
+ private emit;
40
+ private inconclusive;
41
+ }
42
+ //# sourceMappingURL=IntegrationLeastPrivilegeCheck.d.ts.map