@cclabsnz/sf-audit 1.23.0 → 1.24.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 (34) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/PERMISSIONS.md +16 -2
  3. package/docs/permissionset/SF_Audit_MFA.permissionset-meta.xml +36 -0
  4. package/lib/chains/CapabilityRegistry.js +15 -7
  5. package/lib/chains/ChainEngine.js +10 -2
  6. package/lib/chains/namedChains.d.ts +1 -0
  7. package/lib/chains/namedChains.js +47 -20
  8. package/lib/checks/impl/ApexCrudFLSCheck.js +11 -2
  9. package/lib/checks/impl/ApexRestEndpointCheck.js +15 -7
  10. package/lib/checks/impl/ApexSharingCheck.js +19 -8
  11. package/lib/checks/impl/FlowsWithoutSharingCheck.d.ts +1 -1
  12. package/lib/checks/impl/FlowsWithoutSharingCheck.js +17 -12
  13. package/lib/checks/impl/GuestExecutableApexCheck.js +18 -9
  14. package/lib/checks/impl/GuestObjectExposureCheck.d.ts +6 -7
  15. package/lib/checks/impl/GuestObjectExposureCheck.js +123 -38
  16. package/lib/checks/impl/GuestSiteOptionsCheck.js +40 -6
  17. package/lib/checks/impl/GuestUserAccessCheck.d.ts +1 -0
  18. package/lib/checks/impl/GuestUserAccessCheck.js +88 -57
  19. package/lib/checks/impl/GuestUserVisibilityCheck.d.ts +9 -6
  20. package/lib/checks/impl/GuestUserVisibilityCheck.js +59 -66
  21. package/lib/checks/impl/MfaMethodStrengthCheck.js +2 -2
  22. package/lib/checks/impl/MfaRegistrationCheck.d.ts +1 -1
  23. package/lib/checks/impl/MfaRegistrationCheck.js +52 -18
  24. package/lib/checks/impl/PublicGroupSharingCheck.js +7 -2
  25. package/lib/checks/impl/ReleaseUpdatesCheck.js +1 -1
  26. package/lib/checks/impl/SsoEnforcementCheck.js +6 -4
  27. package/lib/checks/support/apexAccess.d.ts +21 -1
  28. package/lib/checks/support/apexAccess.js +55 -0
  29. package/lib/checks/support/guestShares.d.ts +39 -0
  30. package/lib/checks/support/guestShares.js +113 -0
  31. package/lib/findings/CheckMeta.js +2 -2
  32. package/lib/preflight/permissions.d.ts +1 -1
  33. package/lib/preflight/permissions.js +10 -2
  34. package/package.json +3 -2
@@ -1,18 +1,23 @@
1
1
  import { FlowRepository } from '@cclabsnz/sf-core';
2
+ const WITHOUT_SHARING = 'SystemModeWithoutSharing';
2
3
  export class FlowsWithoutSharingCheck {
3
4
  id = 'flows-without-sharing';
4
5
  name = 'Flows Without Sharing Context';
5
6
  category = 'Flow Security';
6
- description = 'Identifies active flows running in system context without sharing enforcement';
7
+ description = 'Identifies active autolaunched and screen flows set to run in system context without sharing';
7
8
  async run(ctx) {
8
9
  const findings = [];
9
10
  const baseUrl = ctx.orgInfo.instanceUrl;
10
11
  const flows = await new FlowRepository(ctx.soql, ctx.tooling).listActiveVersions();
11
12
  const total = flows.length;
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));
13
+ // Only "System Context Without Sharing—Access All Data" skips sharing by the flow's own setting.
14
+ // Default Mode is not flagged: a screen flow then runs as the user, and an autolaunched flow
15
+ // started by a user runs as that user (from Apex or other automation it inherits the caller's
16
+ // context). Record-, schedule- and platform-event-triggered flows always run in system context
17
+ // without sharing and have no setting to change, so they are out of scope here.
18
+ const withoutSharing = (f) => f.runInMode === WITHOUT_SHARING;
19
+ const autolaunchedWithoutSharing = flows.filter((f) => f.processType === 'AutoLaunchedFlow' && withoutSharing(f));
20
+ const screenWithoutSharing = flows.filter((f) => f.processType === 'Flow' && withoutSharing(f));
16
21
  if (autolaunchedWithoutSharing.length > 0) {
17
22
  const count = autolaunchedWithoutSharing.length;
18
23
  findings.push({
@@ -23,10 +28,10 @@ export class FlowsWithoutSharingCheck {
23
28
  affectedItems: autolaunchedWithoutSharing.map((f) => ({
24
29
  label: f.masterLabel,
25
30
  url: `${baseUrl}/builder_platform_interaction/flowBuilder.app?flowId=${f.id}`,
26
- note: 'Set "Run Flow As" to "User" or document why system context is required',
31
+ note: 'Runs in system context without sharing',
27
32
  })),
28
- detail: "Autolaunched flows running in Default Mode execute with system-level data access, ignoring the triggering user's record visibility.",
29
- remediation: 'Set "Run Flow As" to "User" for autolaunched flows that access sensitive data, or explicitly document why system context is required.',
33
+ detail: "These autolaunched flows are set to run in system context without sharing, so they read and change records whatever the running user's sharing allows.",
34
+ remediation: 'Set each flow to System Context With Sharing, which applies the running user\'s record access whoever starts it. Default Mode applies sharing only when a user starts the flow directly; it inherits the context of Apex or automation that calls it. Keep without-sharing only where the flow must reach records its callers cannot see, document why, and check that its inputs cannot choose which records it touches.',
30
35
  });
31
36
  }
32
37
  if (screenWithoutSharing.length > 0) {
@@ -39,10 +44,10 @@ export class FlowsWithoutSharingCheck {
39
44
  affectedItems: screenWithoutSharing.map((f) => ({
40
45
  label: f.masterLabel,
41
46
  url: `${baseUrl}/builder_platform_interaction/flowBuilder.app?flowId=${f.id}`,
42
- note: 'Review and set "Run Flow As" to "User" where appropriate',
47
+ note: 'Runs in system context without sharing',
43
48
  })),
44
- detail: "Screen flows in Default Mode may allow users to view or modify records they wouldn't normally have access to.",
45
- remediation: 'Review each screen flow and set "Run Flow As" to "User" where appropriate to enforce record-level security.',
49
+ detail: "These screen flows are set to run in system context without sharing, so whoever can run them may view or change records their own sharing would not show them.",
50
+ remediation: 'Set each screen flow to run in Default Mode (user context) or system context with sharing, unless it must reach records its users cannot see; for those, check that no screen input chooses which records it reads or changes.',
46
51
  });
47
52
  }
48
53
  if (autolaunchedWithoutSharing.length === 0 && screenWithoutSharing.length === 0) {
@@ -52,7 +57,7 @@ export class FlowsWithoutSharingCheck {
52
57
  riskLevel: 'LOW',
53
58
  passed: true,
54
59
  title: 'No active flows running without sharing context identified',
55
- detail: `All ${total} active flows either enforce user sharing context or are not autolaunched/screen flow types.`,
60
+ detail: `None of the ${total} active autolaunched or screen flows is set to run in system context without sharing.`,
56
61
  remediation: 'Continue to review flow settings when new flows are activated.',
57
62
  });
58
63
  }
@@ -1,5 +1,5 @@
1
1
  import { ApexRepository } from '@cclabsnz/sf-core';
2
- import { declaresWithoutSharing, effectiveSharing, parentClass, usesSystemMode } from '../support/apexAccess.js';
2
+ import { apexApiVersions, declaresWithoutSharing, effectiveSharing, enteredOnlyThroughAura, omittedSharingEnforced, parentClass, usesSystemMode, } from '../support/apexAccess.js';
3
3
  /**
4
4
  * The org-local classes a class calls, as its compiled SymbolTable records them. A reference with a
5
5
  * namespace is to packaged code, which the audit does not read, so it never resolves to a local
@@ -40,10 +40,13 @@ export class GuestExecutableApexCheck {
40
40
  });
41
41
  return { findings };
42
42
  }
43
- const profileIds = [...new Set(guests.map((g) => g.ProfileId))];
44
- const profileList = profileIds.map((id) => `'${id}'`).join(', ');
45
- const access = await ctx.soql.queryAll(`SELECT SetupEntityId, ParentId FROM SetupEntityAccess
46
- WHERE SetupEntityType = 'ApexClass' AND ParentId IN (${profileList})`);
43
+ // SetupEntityAccess.ParentId is a permission set Id, never a profile Id: a profile's class access
44
+ // sits on the permission set it owns. The guests' assignments cover that one and any assigned set.
45
+ const guestList = guests.map((g) => `'${g.Id}'`).join(', ');
46
+ const assignments = await ctx.soql.queryAll(`SELECT PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId IN (${guestList})`);
47
+ const permSetIds = [...new Set(assignments.map((a) => a.PermissionSetId))];
48
+ const access = permSetIds.length === 0 ? [] : await ctx.soql.queryAll(`SELECT SetupEntityId, ParentId FROM SetupEntityAccess
49
+ WHERE SetupEntityType = 'ApexClass' AND ParentId IN (${permSetIds.map((id) => `'${id}'`).join(', ')})`);
47
50
  const classIds = [...new Set(access.map((a) => a.SetupEntityId))];
48
51
  if (classIds.length === 0) {
49
52
  findings.push({
@@ -69,6 +72,8 @@ export class GuestExecutableApexCheck {
69
72
  * anywhere on the path lifts CRUD/FLS for the guest (RULE-003).
70
73
  */
71
74
  const bodyOf = (n) => byName.get(n.toLowerCase())?.body;
75
+ const versions = await apexApiVersions(ctx);
76
+ const versionOf = (n) => versions.get(n.toLowerCase());
72
77
  // A class reaches what its SymbolTable references, and the class it extends: inherited methods
73
78
  // run with the parent's own sharing.
74
79
  const neighbours = (n) => {
@@ -96,8 +101,9 @@ export class GuestExecutableApexCheck {
96
101
  }
97
102
  return { systemMode: systemModeAt };
98
103
  };
99
- // spec/apex-access-mode.md. A guest call is an entry point: no keyword means without sharing,
100
- // and inherited sharing means with sharing. SYSTEM_MODE bypasses CRUD/FLS only (RULE-003); a
104
+ // spec/apex-access-mode.md. A guest call is an entry point: no keyword means without sharing
105
+ // before API 67.0 and with sharing from it (RULE-007), or when only Aura/LWC calls can enter it
106
+ // (RULE-008), and inherited sharing means with sharing. SYSTEM_MODE bypasses CRUD/FLS only (RULE-003); a
101
107
  // helper declared without sharing bypasses sharing for whatever it does (RULE-004).
102
108
  const unprotected = [];
103
109
  const systemMode = [];
@@ -115,8 +121,11 @@ export class GuestExecutableApexCheck {
115
121
  });
116
122
  continue;
117
123
  }
118
- if (keyword === 'none') {
119
- unprotected.push({ name, note: 'No sharing declaration: runs without sharing when a guest calls it' });
124
+ if (keyword === 'none' && body && !omittedSharingEnforced(name, body, bodyOf, versionOf) && !enteredOnlyThroughAura(body)) {
125
+ unprotected.push({
126
+ name,
127
+ note: 'No sharing declaration, and not shown to be saved at API 67.0 or later (it and any keyword-less parent): runs without sharing when a guest enters it through REST, SOAP, remoting, a flow action or a Visualforce page',
128
+ });
120
129
  continue;
121
130
  }
122
131
  if (keyword === null || !body) {
@@ -5,9 +5,13 @@ import type { SecurityCheck, CheckResult } from '../SecurityCheck.js';
5
5
  * GuestUserAccessCheck (a fixed list of standard objects + sharing rules), this
6
6
  * auto-discovers ALL objects the guest profile/permission-sets can read, then
7
7
  * decides whether records are actually reachable:
8
- * - public external OWD (Read/ReadWrite) => every record is readable, OR
8
+ * - public external OWD (Read/ReadWrite) AND UserRecordAccess confirms the guest reads a
9
+ * live record (secure guest record access means the OWD alone grants guests nothing), OR
9
10
  * - Private OWD but the guest OWNS records (public-form submissions) => those
10
- * records are still readable, because an owner can always read its own records.
11
+ * records are still readable, because an owner can always read its own records, OR
12
+ * - Private OWD but records are shared with guests (a guest user sharing rule, or a legacy
13
+ * manual, Apex or group share), read from the object's share table and, when it shows none or
14
+ * cannot be read, from UserRecordAccess on a sample.
11
15
  *
12
16
  * Sharing-model readability is necessary but not sufficient: the Experience Cloud
13
17
  * UI API (GraphQL) can only return objects it MODELS. Objects like Calendar,
@@ -32,11 +36,6 @@ export declare class GuestObjectExposureCheck implements SecurityCheck {
32
36
  * not modelled, or null if the probe could not be performed at all.
33
37
  */
34
38
  private isUiApiModeled;
35
- /**
36
- * Ground-truth read confirmation via UserRecordAccess for a single sample
37
- * record. Returns null when there is no record to test or the probe fails.
38
- */
39
- private confirmGuestRead;
40
39
  private evidenceNote;
41
40
  private ok;
42
41
  private inconclusive;
@@ -1,13 +1,24 @@
1
- // External sharing models that expose ALL records of an object to external (guest) users.
1
+ import { guestPrincipals, guestReadsSample, guestShareCount } from '../support/guestShares.js';
2
+ // Objects whose guest shares GuestUserAccessCheck already reports as guest-user-sharing-exposure.
3
+ const REPORTED_BY_GUEST_ACCESS = new Set(['Account', 'Case', 'Contact', 'Opportunity']);
4
+ // Public external sharing models. Since Winter '21 secure guest record access is always enforced,
5
+ // so these open records to logged-in external users but not to guests: record sharing gives a guest
6
+ // a record only through a guest sharing rule or ownership. (Guest-callable Apex or Flow running
7
+ // without sharing bypasses sharing; their own checks report that.) A public external OWD plus guest Read is therefore
8
+ // a lead to confirm with UserRecordAccess, not an exposure on its own.
2
9
  const PUBLIC_OWD = new Set(['Read', 'ReadWrite', 'ReadSelect']);
3
10
  /**
4
11
  * Detects every object an unauthenticated guest can READ IN BULK. Unlike
5
12
  * GuestUserAccessCheck (a fixed list of standard objects + sharing rules), this
6
13
  * auto-discovers ALL objects the guest profile/permission-sets can read, then
7
14
  * decides whether records are actually reachable:
8
- * - public external OWD (Read/ReadWrite) => every record is readable, OR
15
+ * - public external OWD (Read/ReadWrite) AND UserRecordAccess confirms the guest reads a
16
+ * live record (secure guest record access means the OWD alone grants guests nothing), OR
9
17
  * - Private OWD but the guest OWNS records (public-form submissions) => those
10
- * records are still readable, because an owner can always read its own records.
18
+ * records are still readable, because an owner can always read its own records, OR
19
+ * - Private OWD but records are shared with guests (a guest user sharing rule, or a legacy
20
+ * manual, Apex or group share), read from the object's share table and, when it shows none or
21
+ * cannot be read, from UserRecordAccess on a sample.
11
22
  *
12
23
  * Sharing-model readability is necessary but not sufficient: the Experience Cloud
13
24
  * UI API (GraphQL) can only return objects it MODELS. Objects like Calendar,
@@ -75,7 +86,8 @@ export class GuestObjectExposureCheck {
75
86
  findings.push(this.inconclusive('guest-object-exposure-objperms-inaccessible', 'Guest object permissions could not be queried'));
76
87
  return { findings };
77
88
  }
78
- const writable = new Set(perms.filter((p) => p.PermissionsCreate || p.PermissionsEdit || p.PermissionsDelete).map((p) => p.SobjectType));
89
+ // Guests can hold only Read and Create object permissions since Winter '21.
90
+ const writable = new Set(perms.filter((p) => p.PermissionsCreate).map((p) => p.SobjectType));
79
91
  const readable = [...new Set(perms.map((p) => p.SobjectType))];
80
92
  if (readable.length === 0) {
81
93
  findings.push(this.ok(guests.length, 0));
@@ -92,9 +104,24 @@ export class GuestObjectExposureCheck {
92
104
  catch {
93
105
  // Proceed without OWD: objects fall through to the ownership check below.
94
106
  }
107
+ const principals = await guestPrincipals(ctx, guestIds);
95
108
  const exposed = [];
96
109
  for (const obj of readable) {
97
110
  const model = owd.get(obj) ?? 'Unknown';
111
+ // GuestUserAccessCheck owns guest reads on these four (guest-user-sharing-exposure: share
112
+ // rows, or UserRecordAccess when there are none), whatever their OWD, so they are not graded
113
+ // twice. Guest-owned records on them are reported here, and only here.
114
+ if (REPORTED_BY_GUEST_ACCESS.has(obj)) {
115
+ try {
116
+ const r = await ctx.soql.query(`SELECT COUNT() FROM ${obj} WHERE OwnerId IN (${inIds})`);
117
+ if (r.totalSize > 0)
118
+ exposed.push({ obj, count: r.totalSize, write: writable.has(obj), kind: 'owned', uiApi: null, confirmed: null });
119
+ }
120
+ catch {
121
+ // No OwnerId: ownership cannot expose it.
122
+ }
123
+ continue;
124
+ }
98
125
  if (PUBLIC_OWD.has(model)) {
99
126
  exposed.push({ obj, owd: model, write: writable.has(obj), kind: 'public', uiApi: null, confirmed: null });
100
127
  continue;
@@ -102,35 +129,88 @@ export class GuestObjectExposureCheck {
102
129
  // Private or Unknown OWD: records are still exposed if the guest OWNS them.
103
130
  try {
104
131
  const r = await ctx.soql.query(`SELECT COUNT() FROM ${obj} WHERE OwnerId IN (${inIds})`);
105
- if (r.totalSize > 0)
132
+ if (r.totalSize > 0) {
106
133
  exposed.push({ obj, count: r.totalSize, write: writable.has(obj), kind: 'owned', uiApi: null, confirmed: null });
134
+ continue;
135
+ }
107
136
  }
108
137
  catch {
109
138
  // Object has no OwnerId / does not support COUNT — not an ownership-bypass surface.
110
139
  }
140
+ // Or if they are shared with guests: a guest sharing rule is what secure guest record access
141
+ // leaves as the guest's way to a record it does not own, and legacy shares persist.
142
+ const shared = await guestShareCount(ctx, obj, principals);
143
+ if (shared !== null && shared > 0) {
144
+ exposed.push({ obj, count: shared, write: writable.has(obj), kind: 'shared', uiApi: null, confirmed: true });
145
+ }
146
+ else if ((await guestReadsSample(ctx, obj, guestIds)) === true) {
147
+ // No share row seen (no share table, a parent-controlled object, or a path the table does
148
+ // not show), but the guest reads a sampled record.
149
+ exposed.push({ obj, write: writable.has(obj), kind: 'shared', uiApi: null, confirmed: true });
150
+ }
111
151
  }
112
152
  // Grade each sharing-readable object by ACTUAL UI-API reachability + ground-truth read.
113
153
  for (const e of exposed) {
114
154
  e.uiApi = await this.isUiApiModeled(ctx, e.obj);
115
- e.confirmed = await this.confirmGuestRead(ctx, e.obj, guestIds[0]);
155
+ if (e.kind === 'shared')
156
+ continue;
157
+ // The external OWD does not reach guests, so on a public-OWD object a guest reads records the
158
+ // same way as under a Private one: through shares. Those are graded as shared records.
159
+ const shared = e.kind === 'public' ? await guestShareCount(ctx, e.obj, principals) : null;
160
+ if (shared !== null && shared > 0) {
161
+ Object.assign(e, { kind: 'shared', count: shared, confirmed: true });
162
+ continue;
163
+ }
164
+ e.confirmed = await guestReadsSample(ctx, e.obj, guestIds);
165
+ // An unconfirmed public-OWD object can still hold records the guest owns, which it always reads.
166
+ if (e.kind === 'public' && e.confirmed !== true) {
167
+ try {
168
+ const r = await ctx.soql.query(`SELECT COUNT() FROM ${e.obj} WHERE OwnerId IN (${inIds})`);
169
+ if (r.totalSize > 0)
170
+ Object.assign(e, { kind: 'owned', count: r.totalSize });
171
+ }
172
+ catch {
173
+ // No OwnerId: ownership cannot expose it.
174
+ }
175
+ }
116
176
  }
117
177
  // uiApi === false is the ONLY signal that de-escalates (object-info explicitly said
118
178
  // "not modeled"). true and null (couldn't probe) both stay in the reachable tier.
119
- const reachablePublic = exposed.filter((e) => e.kind === 'public' && e.uiApi !== false);
179
+ const publicOwd = exposed.filter((e) => e.kind === 'public' && e.uiApi !== false);
180
+ const reachablePublic = publicOwd.filter((e) => e.confirmed === true);
181
+ const unconfirmedPublic = publicOwd.filter((e) => e.confirmed !== true);
120
182
  const reachableOwned = exposed.filter((e) => e.kind === 'owned' && e.uiApi !== false);
183
+ const reachableShared = exposed.filter((e) => e.kind === 'shared' && e.uiApi !== false);
121
184
  const sharingOnly = exposed.filter((e) => e.uiApi === false);
122
185
  const uiApiNote = 'Reachable unauthenticated via the Experience Cloud UI API (GraphQL) through aura://RecordUiController/ACTION$executeGraphQL on /s/sfsites/aura (aura.token=null).';
123
186
  if (reachablePublic.length > 0) {
124
187
  findings.push({
125
188
  id: 'guest-object-exposure-public-owd',
126
189
  category: this.category,
127
- riskLevel: 'CRITICAL',
128
- title: `${reachablePublic.length} object(s) fully readable by unauthenticated guests (public external OWD)`,
129
- detail: 'These objects have an external org-wide default of Read or ReadWrite, are readable by the guest profile, and are modelled by the UI API, so every record is reachable by any unauthenticated visitor who can enumerate counts and page through records in bulk. ' +
190
+ // Graded like guest-object-exposure-guest-shared: the external OWD does not reach guests, so
191
+ // these records reach them through sharing, which a site may intend.
192
+ riskLevel: 'HIGH',
193
+ title: `${reachablePublic.length} object(s) with records confirmed readable by unauthenticated guests`,
194
+ detail: 'The guest profile can read these objects, their external org-wide default is Read or ReadWrite, the UI API models them, and UserRecordAccess confirms the guest user can read live records. Secure guest record access means the OWD alone does not grant guests access, so something shares these records with guests that the share table does not show (or could not be read for). Any unauthenticated visitor can page through the records it reaches. That is the intent when the records are a public dataset; confirm they are. ' +
130
195
  uiApiNote,
131
- remediation: 'Set external OWD to Private for these objects, and remove Read from the guest profile/permission sets unless a specific public dataset is intended. Then verify no guest-accessible Apex returns the data.',
196
+ remediation: 'Confirm the records guests can read are meant to be public. If not, find what shares them (guest sharing rules, manual or Apex shares, public group membership) and remove it, and remove Read from the guest profile/permission sets unless a specific public dataset is intended.',
132
197
  affectedItems: reachablePublic.map((e) => ({
133
- label: `${e.obj} (external OWD: ${e.owd}${e.write ? ', guest WRITE too' : ''})`,
198
+ label: `${e.obj} (external OWD: ${e.owd}${e.write ? ', guest Create permission too' : ''})`,
199
+ url: `${baseUrl}/lightning/setup/SecuritySharing/page`,
200
+ note: this.evidenceNote(e),
201
+ })),
202
+ });
203
+ }
204
+ if (unconfirmedPublic.length > 0) {
205
+ findings.push({
206
+ id: 'guest-object-exposure-public-owd-unconfirmed',
207
+ category: this.category,
208
+ riskLevel: 'MEDIUM',
209
+ title: `${unconfirmedPublic.length} object(s) readable by the guest profile with a public external OWD; guest record access not confirmed`,
210
+ detail: 'The guest profile can read these objects and their external org-wide default is Read or ReadWrite. Since Winter \'21 secure guest record access is always enforced, so that default opens records to logged-in external users but not to guests: record sharing gives a guest a record only through a guest sharing rule or ownership. UserRecordAccess did not confirm that any guest user can read any of up to 200 sampled records, and no guest user owns any (each item\'s note says whether the probe ran). A guest sharing rule whose criteria no sampled record met can still expose other records, so confirm in the org.',
211
+ remediation: 'Remove Read from the guest profile/permission sets unless a specific public dataset is intended, and review the guest sharing rules on these objects. Setting the external OWD to Private also limits what logged-in external users see.',
212
+ affectedItems: unconfirmedPublic.map((e) => ({
213
+ label: `${e.obj} (external OWD: ${e.owd}${e.write ? ', guest Create permission too' : ''})`,
134
214
  url: `${baseUrl}/lightning/setup/SecuritySharing/page`,
135
215
  note: this.evidenceNote(e),
136
216
  })),
@@ -141,27 +221,47 @@ export class GuestObjectExposureCheck {
141
221
  id: 'guest-object-exposure-guest-owned',
142
222
  category: this.category,
143
223
  riskLevel: 'CRITICAL',
144
- title: `${reachableOwned.length} object(s) expose guest-owned records despite a Private OWD`,
145
- detail: 'These objects have a Private external OWD, but the guest user OWNS records in them (typically public-form submissions created as the guest user). An owner can always read its own records, so Private OWD does not protect them, and the UI API models the object, so all guest-owned records are readable unauthenticated in bulk. ' +
224
+ title: `${reachableOwned.length} object(s) expose records the guest user owns`,
225
+ detail: 'The guest user OWNS records in these objects (typically public-form submissions created as the guest user). An owner can always read its own records, so neither a Private OWD nor secure guest record access protects them, and the UI API models the object, so all guest-owned records are readable unauthenticated in bulk. ' +
146
226
  uiApiNote,
147
- remediation: 'Reparent guest-created records to a default or integration owner (enable "Assign records created by guest users to the default owner" and "Secure guest user record access"), and remove Read on these objects from the guest profile.',
227
+ remediation: 'Reassign the records the guest user owns to an internal user or queue, and remove Read on these objects from the guest profile. Since Winter \'21 the platform assigns new guest-created records to the site\'s default record owner, so most of these predate that; Web-to-Case can still leave the site guest user as case owner, so check that an assignment rule or flow reassigns new cases.',
148
228
  affectedItems: reachableOwned.map((e) => ({
149
- label: `${e.obj}: ${e.count} guest-owned record(s)${e.write ? ' (guest WRITE too)' : ''}`,
229
+ label: `${e.obj}: ${e.count} guest-owned record(s)${e.write ? ' (guest Create permission too)' : ''}`,
150
230
  url: `${baseUrl}/${e.obj}`,
151
231
  note: this.evidenceNote(e),
152
232
  })),
153
233
  });
154
234
  }
235
+ if (reachableShared.length > 0) {
236
+ findings.push({
237
+ id: 'guest-object-exposure-guest-shared',
238
+ category: this.category,
239
+ // HIGH, not CRITICAL: a guest sharing rule is the platform's documented way to publish
240
+ // records to a site, and nothing here says whether the records are meant to be public.
241
+ riskLevel: 'HIGH',
242
+ title: `${reachableShared.length} object(s) share records with unauthenticated guests`,
243
+ detail: 'The guest profile can read these objects, their external org-wide default is not public, and records are still shared with guests: the object\'s share table holds guest user sharing rule rows, or legacy manual, Apex or group shares naming a guest user (access granted before Winter \'21 was not removed), or UserRecordAccess confirms the guest reads a sampled record. The UI API models the object, so any unauthenticated visitor can page through the shared records. That is the intent when the records are a public dataset; confirm they are. ' +
244
+ uiApiNote,
245
+ remediation: 'Confirm each object\'s shared records are meant to be public. If not, narrow or remove the guest user sharing rules (Setup → Sharing Settings), delete manual and Apex shares to the guest user, and remove the guest user from public groups and queues. Remove Read from the guest profile/permission sets unless a public dataset is intended.',
246
+ affectedItems: reachableShared.map((e) => ({
247
+ label: `${e.obj}${e.count !== undefined ? `: ${e.count} guest share row(s)` : ''}${e.write ? ' (guest Create permission too)' : ''}`,
248
+ url: `${baseUrl}/lightning/setup/SecuritySharing/page`,
249
+ note: e.count !== undefined
250
+ ? 'Share rows giving guests access found in the share table; UI-API-modelled (GraphQL-reachable)'
251
+ : this.evidenceNote(e),
252
+ })),
253
+ });
254
+ }
155
255
  if (sharingOnly.length > 0) {
156
256
  findings.push({
157
257
  id: 'guest-object-exposure-sharing-only',
158
258
  category: this.category,
159
259
  riskLevel: 'MEDIUM',
160
260
  title: `${sharingOnly.length} object(s) readable in the sharing model but NOT reachable via the UI API`,
161
- detail: 'The guest can read these objects in the sharing model (object permission + public OWD or guest ownership), but the UI API `object-info` endpoint does not model them, so they are NOT pullable through the guest GraphQL vector (this is the tier that Calendar, AuthSession, OauthToken and similar system objects fall into). This is a defense-in-depth grant to tighten, not an active bulk-exfiltration surface.',
261
+ detail: 'The guest can read these objects in the sharing model (object permission plus guest ownership, records shared with guests, or a public OWD), but the UI API `object-info` endpoint does not model them, so they are NOT pullable through the guest GraphQL vector (this is the tier that Calendar, AuthSession, OauthToken and similar system objects fall into). This is a defense-in-depth grant to tighten, not an active bulk-exfiltration surface.',
162
262
  remediation: 'Remove Read from the guest profile/permission sets for these objects unless specifically required. Because they are not UI-API-modelled they are lower priority than the CRITICAL findings, but a stripped guest profile should not hold these grants at all.',
163
263
  affectedItems: sharingOnly.map((e) => ({
164
- label: `${e.obj} (${e.kind === 'public' ? `external OWD: ${e.owd}` : `${e.count} guest-owned`}${e.write ? ', guest WRITE too' : ''})`,
264
+ label: `${e.obj} (${e.kind === 'public' ? `external OWD: ${e.owd}` : e.kind === 'owned' ? `${e.count} guest-owned` : 'records shared with guests'}${e.write ? ', guest Create permission too' : ''})`,
165
265
  url: `${baseUrl}/lightning/setup/SecuritySharing/page`,
166
266
  note: 'Sharing-readable; UI API object-info = not modelled (not GraphQL-reachable)',
167
267
  })),
@@ -189,29 +289,14 @@ export class GuestObjectExposureCheck {
189
289
  return false;
190
290
  }
191
291
  }
192
- /**
193
- * Ground-truth read confirmation via UserRecordAccess for a single sample
194
- * record. Returns null when there is no record to test or the probe fails.
195
- */
196
- async confirmGuestRead(ctx, obj, guestId) {
197
- try {
198
- const sample = await ctx.soql.query(`SELECT Id FROM ${obj} LIMIT 1`);
199
- const recId = sample.records?.[0]?.Id;
200
- if (!recId)
201
- return null;
202
- const access = await ctx.soql.queryAll(`SELECT RecordId, HasReadAccess FROM UserRecordAccess WHERE UserId = '${guestId}' AND RecordId = '${recId}'`);
203
- return access[0]?.HasReadAccess === true;
204
- }
205
- catch {
206
- return null;
207
- }
208
- }
209
292
  evidenceNote(e) {
210
293
  if (e.confirmed === true)
211
294
  return 'Read CONFIRMED via UserRecordAccess; UI-API-modelled (GraphQL-reachable)';
212
295
  if (e.confirmed === false)
213
- return 'UI-API-modelled, but UserRecordAccess did not confirm read on the sampled record';
214
- return 'UI-API-modelled (GraphQL-reachable); no sample record available to confirm read';
296
+ return 'UI-API-modelled, but UserRecordAccess shows no guest user can read any sampled record (up to 200)';
297
+ if (e.confirmed === 'failed')
298
+ return 'UI-API-modelled (GraphQL-reachable); UserRecordAccess could not be queried, so guest read is unconfirmed';
299
+ return 'UI-API-modelled (GraphQL-reachable); no record available to confirm guest read';
215
300
  }
216
301
  ok(guestCount, readableCount) {
217
302
  return {
@@ -222,7 +307,7 @@ export class GuestObjectExposureCheck {
222
307
  title: `${guestCount} active guest user(s); no objects bulk-exposed`,
223
308
  detail: readableCount === 0
224
309
  ? 'Guest profiles grant Read on no business objects, so there is no UI-API bulk-read surface.'
225
- : `Guest profiles can read ${readableCount} object(s), but all have a Private external OWD with no guest-owned records, so no records are bulk-readable.`,
310
+ : `Guest profiles can read ${readableCount} object(s), but all have a Private external OWD with no guest-owned records and no records shared with guests, so no records are bulk-readable.`,
226
311
  remediation: 'Continue to review guest object permissions and record ownership as forms and sites change.',
227
312
  };
228
313
  }
@@ -43,14 +43,18 @@ export class GuestSiteOptionsCheck {
43
43
  });
44
44
  return { findings };
45
45
  }
46
- const fileSites = networks.filter((n) => n.OptionsGuestFileAccessEnabled);
47
- const memberSites = networks.filter((n) => n.OptionsGuestMemberVisibility);
46
+ // Only a live site serves guests; on a site under construction or taken down a setting waits
47
+ // for go-live, so it is reported apart and feeds no attack chain.
48
+ const fileSites = networks.filter((n) => n.OptionsGuestFileAccessEnabled && n.Status === 'Live');
49
+ const idleFileSites = networks.filter((n) => n.OptionsGuestFileAccessEnabled && n.Status !== 'Live');
50
+ const memberSites = networks.filter((n) => n.OptionsGuestMemberVisibility && n.Status === 'Live');
51
+ const idleMemberSites = networks.filter((n) => n.OptionsGuestMemberVisibility && n.Status !== 'Live');
48
52
  if (fileSites.length > 0) {
49
53
  findings.push({
50
54
  id: 'guest-site-options-file-access',
51
55
  category: this.category,
52
56
  riskLevel: 'HIGH',
53
- title: `${fileSites.length} site(s) allow guest users to access files`,
57
+ title: `${fileSites.length} live site(s) allow guest users to access files`,
54
58
  detail: 'Guest file access lets unauthenticated visitors read public files (ContentVersion/ContentDocument/Attachment). Combined with the UI API, file IDs can be enumerated and content downloaded via the file servlet (/sfc/servlet.shepherd/version/download).',
55
59
  remediation: 'Disable guest file access (Network setting "Let guest users access public files") unless a specific public file library is intended.',
56
60
  affectedItems: fileSites.map((n) => ({
@@ -65,8 +69,8 @@ export class GuestSiteOptionsCheck {
65
69
  id: 'guest-site-options-member-visibility',
66
70
  category: this.category,
67
71
  riskLevel: 'MEDIUM',
68
- title: `${memberSites.length} site(s) let guest users see other members`,
69
- detail: 'Guest member visibility exposes other site members (User records, names, profile data) to unauthenticated visitors, leaking member identities and enabling enumeration.',
72
+ title: `${memberSites.length} live site(s) let guest users see other members`,
73
+ detail: 'Guest member visibility exposes the site\'s members (their User records: names and profile data) to unauthenticated visitors, leaking member identities and enabling enumeration. It reaches the site\'s members, not the org\'s business records. Since Winter \'21 it is the only way a guest sees other users: View All Users can no longer be granted to guests.',
70
74
  remediation: 'Disable "Let guest users see other members of this site" unless member directories must be public.',
71
75
  affectedItems: memberSites.map((n) => ({
72
76
  label: n.Name,
@@ -75,7 +79,37 @@ export class GuestSiteOptionsCheck {
75
79
  })),
76
80
  });
77
81
  }
78
- if (fileSites.length === 0 && memberSites.length === 0) {
82
+ if (idleFileSites.length > 0) {
83
+ findings.push({
84
+ id: 'guest-site-options-file-access-not-live',
85
+ category: this.category,
86
+ riskLevel: 'LOW',
87
+ title: `${idleFileSites.length} site(s) that are not live would let guest users access files`,
88
+ detail: 'Guest file access is on for these sites, but they are not live, so no guest reaches them yet. Going live would let unauthenticated visitors read the site\'s public files.',
89
+ remediation: 'Disable "Let guest users access public files" before the site goes live, unless a public file library is intended.',
90
+ affectedItems: idleFileSites.map((n) => ({
91
+ label: n.Name,
92
+ url: setupUrl,
93
+ note: `Status: ${n.Status}; guest file access enabled`,
94
+ })),
95
+ });
96
+ }
97
+ if (idleMemberSites.length > 0) {
98
+ findings.push({
99
+ id: 'guest-site-options-member-visibility-not-live',
100
+ category: this.category,
101
+ riskLevel: 'LOW',
102
+ title: `${idleMemberSites.length} site(s) that are not live would let guest users see other members`,
103
+ detail: 'Guest member visibility is on for these sites, but they are not live, so no guest reaches them yet. Going live would expose the site\'s members to unauthenticated visitors.',
104
+ remediation: 'Disable "Let guest users see other members of this site" before the site goes live, unless member directories must be public.',
105
+ affectedItems: idleMemberSites.map((n) => ({
106
+ label: n.Name,
107
+ url: setupUrl,
108
+ note: `Status: ${n.Status}; guest member visibility enabled`,
109
+ })),
110
+ });
111
+ }
112
+ if (fileSites.length === 0 && memberSites.length === 0 && idleFileSites.length === 0 && idleMemberSites.length === 0) {
79
113
  findings.push({
80
114
  id: 'guest-site-options-ok',
81
115
  category: this.category,
@@ -7,5 +7,6 @@ export declare class GuestUserAccessCheck implements SecurityCheck {
7
7
  readonly description = "Audits object permissions and sharing rules granted to unauthenticated guest users";
8
8
  readonly dependsOnCache: readonly ['healthCloudInstalled'];
9
9
  run(ctx: AuditContext): Promise<CheckResult>;
10
+ private guestOwns;
10
11
  }
11
12
  //# sourceMappingURL=GuestUserAccessCheck.d.ts.map