@cclabsnz/sf-audit 1.22.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 (37) hide show
  1. package/CHANGELOG.md +66 -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 +16 -8
  5. package/lib/chains/ChainEngine.js +10 -2
  6. package/lib/chains/namedChains.d.ts +1 -0
  7. package/lib/chains/namedChains.js +59 -26
  8. package/lib/checks/impl/ApexCrudFLSCheck.js +12 -3
  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/HardcodedCredentialsCheck.js +3 -1
  22. package/lib/checks/impl/MfaMethodStrengthCheck.js +6 -5
  23. package/lib/checks/impl/MfaRegistrationCheck.d.ts +1 -1
  24. package/lib/checks/impl/MfaRegistrationCheck.js +67 -18
  25. package/lib/checks/impl/PublicGroupSharingCheck.js +7 -2
  26. package/lib/checks/impl/ReleaseUpdatesCheck.js +1 -1
  27. package/lib/checks/impl/SsoEnforcementCheck.js +6 -4
  28. package/lib/checks/support/apexAccess.d.ts +21 -1
  29. package/lib/checks/support/apexAccess.js +55 -0
  30. package/lib/checks/support/guestShares.d.ts +39 -0
  31. package/lib/checks/support/guestShares.js +113 -0
  32. package/lib/findings/CheckMeta.js +2 -2
  33. package/lib/preflight/permissions.d.ts +1 -1
  34. package/lib/preflight/permissions.js +10 -2
  35. package/lib/renderers/ClientReportRenderer.d.ts +2 -0
  36. package/lib/renderers/ClientReportRenderer.js +18 -3
  37. package/package.json +3 -2
package/CHANGELOG.md CHANGED
@@ -9,6 +9,72 @@ published note and carries the signed provenance attestation and CycloneDX SBOM
9
9
 
10
10
  ## [Unreleased]
11
11
 
12
+ ## [v1.24.0](https://github.com/cclabsnz/sf-audit-plugin/releases/tag/v1.24.0) — 2026-10-30
13
+
14
+ Several checks were filtering on values the platform never writes, so they found nothing; they now
15
+ find what they look for. Guest exposure is graded one way, Apex follows the API 67.0 sharing and
16
+ user-mode defaults, and MFA registration reads every method. Some grades will fall where exposures
17
+ are newly found, and some will rise where findings were overstated.
18
+
19
+ ### Added
20
+
21
+ - **An optional permission set for MFA registration**, `docs/permissionset/SF_Audit_MFA.permissionset-meta.xml`, separate from the read-only one. Salesforce grants "Manage MFA in API" only with user-management permissions, so it is meant for an audit user who is already an administrator.
22
+
23
+ - **`docs/FEATURES.md` lists what sf-audit already does**: commands, checks, attack chains, renderers, shared helpers, framework mappings and test tooling, each with its file. Search it before building something. A test fails when a check, chain, command, shared helper, renderer or chain module is missing from it.
24
+ - **The schema guard catches filters that match nothing.** The schema snapshot now keeps picklist values (all but geography, locale, currency and encoding lists, and without custom or namespaced values), and a query that filters on a value the picklist does not have fails the guard. A new deep-path guard seeds a consistent org so checks get past their first empty result, and validates the queries behind it.
25
+
26
+ ### Security
27
+
28
+ - **deepmerge is pinned to 4.1.1 under jest.** GHSA-gcqx-w48m-w2h4 (prototype poisoning in `mergeObject()`, low) affects 4.2.0 to 4.3.1 and has no patched release. deepmerge reaches the project only through `jest-config`, a development dependency, and jest runs unchanged on 4.1.1, which is outside the affected range.
29
+
30
+ ### Fixed
31
+
32
+ - **Guest-executable Apex is found again.** The check read Apex class access by filtering `SetupEntityAccess.ParentId` on the guest profile Ids. That field holds permission set Ids, so in a real org it matched nothing and reported "Guest profiles cannot execute any Apex classes". It now reads the guest users' permission sets, both the one each guest profile owns and any assigned to the guest. Some orgs will see new `guest-executable-apex-*` findings and the unauthenticated bulk-exfiltration chain they open, so some grades may fall.
33
+ - **The unauthenticated bulk-exfiltration chain needs the guest to reach the data itself.** The bulk read, write or code execution must now come from one of its guest-side steps. Before, an internal user's View All Data or an admin's Author Apex, together with any guest exposure, was enough to fire it. The potential-chain pass no longer pairs a guest foothold with those internal grants either.
34
+ - **The same chain no longer counts Apex or Flow that is only shown to run without sharing.** `portal-exposed-apex-without-sharing` flags classes with `@AuraEnabled`, `@RemoteAction` or `@RestResource` methods that lack sharing enforcement, and `flows-*-without-sharing` flags flows by run mode. Neither shows that a guest can call them. Guest-callable Apex is counted through `guest-executable-apex-*`.
35
+ - **A public external OWD on a guest-readable object no longer makes it CRITICAL.** Secure guest record access has been enforced since Winter '21, so the external OWD alone gives guests nothing: record sharing gives a guest a record only through sharing or ownership. `guest-object-exposure-public-owd` now needs `UserRecordAccess` to show that a guest user (every site's guest user is checked) can read one of up to 200 sampled records, and it is HIGH, like every other way records are shared with guests (see below). An object whose records a guest user owns stays CRITICAL as `guest-object-exposure-guest-owned`. Otherwise the check reports the new MEDIUM finding `guest-object-exposure-public-owd-unconfirmed`, which feeds no attack chain and notes whether the probe ran.
36
+ - **The unauthenticated bulk-exfiltration chain needs a step that reaches records.** Guest API access, guest object permissions, or guest-callable Apex not shown to bypass sharing reach nothing on their own under secure guest record access, yet any one of them, beside a guest user existing, fired a CRITICAL chain. The potential-chain pass does not report them as a guest path either. One step must now show the guest reaching records: a guest sharing rule, guest-owned or confirmed-readable records, the whole User roster, guest-callable Apex that runs without sharing, or secure guest record access not being enforced.
37
+ - **The flows-without-sharing check flags the flows it names.** It flagged autolaunched and screen flows in Default Mode, where a screen flow runs as the user, and missed flows explicitly set to run in system context without sharing. It now flags autolaunched and screen flows explicitly set that way, so most orgs will see fewer of these findings and some will see new ones. Record-, schedule- and platform-event-triggered flows always run that way, have no setting to change, and are not flagged.
38
+ - **Guest exposure findings say what a guest can do.** Affected items read "guest Create permission" instead of "guest WRITE": guests cannot hold Edit or Delete since Winter '21. The guest-owned remediation now says to reassign existing records, instead of enabling two settings the platform has enforced since Winter '21.
39
+ - **Guest sharing rules are found.** The guest-access and public-group sharing checks counted share rows with `RowCause = 'SharingRule'`, a value the platform never writes, so they found no sharing rule at all. They now count `Rule`, and the guest check also counts `GuestRule`, the value guest user sharing rules write. Orgs with guest or public-group sharing rules will see new findings, and some grades may fall.
40
+ - **MFA registration covers the same users as the count.** Frozen users are now dropped from the registrations, as they already were from the count, and the 2000-row cap is gone.
41
+ - **Apex classes saved at API 67.0 or later are no longer reported for a missing sharing keyword.** From Summer '26 an Apex class compiled at API 67.0 or later that declares no sharing keyword runs with sharing. The guest-executable Apex, Apex sharing and Apex REST endpoint checks now read each class's API version. They report a keyword-less class only when it, or a keyword-less parent it inherits from, is below 67.0, or when its version cannot be read. A keyword-less guest-callable class at 67.0 drops from CRITICAL to the HIGH "executable by guests" finding, so some grades may rise. The REST check now also follows inheritance: an endpoint that extends a `without sharing` class is reported as without sharing.
42
+ - **A keyword-less class reached only from Aura or LWC is no longer reported as running without sharing.** Since Winter '21 an `@AuraEnabled` call into a class with no sharing keyword runs with sharing. A class whose only way in is `@AuraEnabled` (no REST, SOAP, remoting or Visualforce use) leaves the guest CRITICAL finding and the portal-exposed list. The Apex sharing check still lists it below API 67.0 as missing a keyword.
43
+ - **Apex saved at API 67.0 or later is no longer reported for missing CRUD/FLS checks.** From that version queries and DML run in user mode by default, which enforces object and field permissions. SYSTEM_MODE in such a class is still reported.
44
+ - **Records shared with guests are found, whatever the object's OWD.** The guest object exposure check looked only for guest-owned records when an object's external OWD was Private, so it missed guest user sharing rules, the main way a guest reaches records under secure guest record access. The guest-access check looked only at sharing-rule rows naming the guest user. Both now read share tables the same way. A row gives guests access when it comes from a guest sharing rule, or from the parent or person-account access one implies, whoever it names. It also counts when it is a manual, Apex or group share naming a guest user or a public group or queue a guest belongs to. Winter '21 did not remove those. The guest-access check reports Account, Case, Contact and Opportunity (`guest-user-sharing-exposure`). The guest object exposure check reports every other guest-readable object as the new HIGH finding `guest-object-exposure-guest-shared`, falling back to `UserRecordAccess` on a sample when the share table shows nothing or cannot be read. Shares to a site's guest user group count too, and group membership is followed through nested groups. The guest-access check also asks `UserRecordAccess` on a sample when Account, Case, Contact or Opportunity show no share row, or the share table cannot be read: for example a Contact controlled by its parent. It asks only where a guest can read the object and owns none of its records. The guest object exposure check leaves those four objects to it, except for guest-owned records, so each exposure is reported once.
45
+ - **Guest object access is found again.** The guest-access check filtered `ObjectPermissions.ParentId` on the guest profile Ids. That field holds permission set Ids, so it never found a guest Read, Create, Edit or Delete on Account, Contact, Case, Lead or Opportunity, and `guest-user-read-access` and `guest-user-write-access` could not fire. It now reads the guest users' permission sets: the one each guest profile owns, and any assigned to a guest. Some orgs will see these findings for the first time, and some grades may fall. It is HIGH, not CRITICAL, because a guest sharing rule is how a site publishes records on purpose: the finding asks the org to confirm they are meant to be public. Share rows on a public-OWD object are graded the same way, since the external OWD does not reach guests. All of these count as the guest reaching records in the unauthenticated bulk-exfiltration chain, which still needs a guest step that reads in bulk, writes or runs code (guest API access, guest-owned records, guest-callable Apex without sharing). Guest-owned records remain the CRITICAL bulk sink. Some grades may fall.
46
+ - **A public external OWD on User no longer counts as a guest exposure.** Secure guest record access keeps the guest OWD Private on every object, User included, so `guest-user-visibility-owd` shows the staff roster to logged-in portal and community users, not to guests. It is now MEDIUM instead of HIGH, says who it reaches, is reported whether or not the org has a guest user (but only when it has an active external user or an Experience Cloud site, so someone can be reached), and feeds the low-trust chains (such as self-registration) instead of the unauthenticated one.
47
+ - **Guest member visibility counts only on live sites, and as a read.** "Let guest users see other members of this site" shows a live site's members to guests. It now joins the unauthenticated chain as a step when that chain fires, but it opens no chain, unauthenticated or low-trust, since it shows members, not business records. On a site that is not live it is reported apart, at LOW, as `guest-site-options-member-visibility-not-live`.
48
+ - **MFA registration reads every method.** The check read `TwoFactorInfo`, whose `Type` can only be `TOTP`, so users registered with Salesforce Authenticator, a security key or a built-in authenticator counted as unregistered (`TwoFactorInfo.Type` has `TOTP` as its only picklist value). It now reads `TwoFactorMethodsInfo`. An authenticator app, Salesforce Authenticator, a security key or a built-in authenticator counts as registered. A verified phone number or email address, or a temporary code, does not: those are sign-in fallbacks. Only registered users go to the method strength check, with every method they hold. A user with just a phone number or email address is reported as unregistered, not graded as having weak MFA, so an admin who verified an email address no longer rates worse than one who did nothing. Preflight now reports the permission as optional. The object needs "Manage MFA in API", which Salesforce grants only with user-management permissions. It is therefore optional and not in the read-only permission set; see PERMISSIONS.md.
49
+ - **The guest User visibility check no longer looks for a Read grant on User.** User takes no object permissions, so `ObjectPermissions` never holds a User row (a Developer Edition org had none across all its permission sets, against 141 for Account), and `guest-user-visibility-object-read` could never fire. The leg and its finding are removed. Guest access to the roster is still reported through View All Users and a site's guest member visibility.
50
+ - **The guest read probe samples both ends of an object's history.** It took the first 200 records in no order, so a share matching only recent records could read as no guest access. It now samples the 100 most and 100 least recently changed records, and falls back to an unordered sample when the object cannot be ordered.
51
+ - **Guest file access counts only on live sites.** As with member visibility, a site that is not live is reported apart, at LOW, as `guest-site-options-file-access-not-live`, and feeds no chain.
52
+ - **The Apex REST check reads `without sharing` from code.** A comment or string containing the words no longer marks an endpoint as running without sharing. An inner class declared `without sharing` still counts.
53
+ - **Three checks filtered on values the platform never writes, so they found nothing.** Salesforce accepts a filter on a picklist value that does not exist and matches no rows, so these checks passed in every org:
54
+ - **SSO enforcement** looked for `LoginType = 'Username-Password'`. Credential logins are recorded in `LoginSubType` (`UI Username-Password`, `OAuth Username-Password`), which the check now reads. Orgs where users still log in with Salesforce credentials will see the finding.
55
+ - **Public group sharing** looked for the All Internal Users group as `Group.Type = 'AllInternal'`. That group's type is `Organization`. Orgs that share records to All Internal Users through sharing rules will see the finding.
56
+ - **Release updates** also asked for a `Revoked` status, which does not exist. The check's results do not change.
57
+ Some grades may fall.
58
+
59
+ ## [v1.23.0](https://github.com/cclabsnz/sf-audit-plugin/releases/tag/v1.23.0) — 2026-10-29
60
+
61
+ Attack chains and checks now match what the platform does. One chain is re-rated, so some grades may
62
+ rise.
63
+
64
+ ### Changed
65
+
66
+ - **`cred-theft-pivot` is rated HIGH, not CRITICAL.** Its secret is found by pattern match. Its egress steps are mostly the org's own registered endpoints, which give an attacker who holds the secret nothing new. Orgs where this chain fires no longer count it as a critical chain in the grade.
67
+
68
+ ### Fixed
69
+
70
+ - **The unauthenticated bulk-exfiltration chain no longer counts external sharing defaults as an unauthenticated step.** Guest record access has been secured since Winter '21, so the external OWD reaches logged-in portal users, not guests. Those findings stay in the low-trust chains, such as self-registration.
71
+ - **The hardcoded-credential check no longer flags a value read at run time.** A credential parameter built from a stored value, such as `'client_secret=' + EncodingUtil.urlEncode(cfg.Secret__c, 'UTF-8')`, was matched as a hardcoded secret.
72
+ - **The CRUD/FLS finding gives the CRUD/FLS remedy.** It now leads with `WITH USER_MODE` or `Security.stripInaccessible()`. Before, it led with "with sharing", which enforces record sharing only and duplicated the sharing finding's advice.
73
+ - **The self-registration chain tells one story.** It no longer calls self-registration "not a finding" while making it the break point. Its remediation leads with turning self-registration off, or with a custom registration handler that approves accounts.
74
+ - **Each attack-scenario slide states its chain's rating against its steps.** This covers a chain rated above its steps, and a chain whose critical step is also counted on its own in the grade.
75
+ - **MFA results no longer read as assurance about nobody.** When no active standard user is visible, the registration check is now inconclusive instead of "All 0 users have registered". The audit user is itself one, so a count of 0 means the users could not be seen. When no one has registered a method, the method-strength check reports an informational "not graded" finding instead of a pass, and notes that this is expected with single sign-on.
76
+ - **The executive scope statement matches what the audit reads.** It reads configuration, metadata, selected records and event logs, including pattern-based static checks of Apex and Flow. It is not a penetration test or a code review. Readers are asked to confirm each finding in the org.
77
+
12
78
  ## [v1.22.0](https://github.com/cclabsnz/sf-audit-plugin/releases/tag/v1.22.0) — 2026-10-29
13
79
 
14
80
  The executive report is now a consulting-style deck that leads with what to do, with the threat
package/PERMISSIONS.md CHANGED
@@ -38,7 +38,7 @@ permissions below, and nothing else. A starter permission-set definition is in
38
38
  | **API Enabled** | `ApiEnabled` | All access is via SOQL/Tooling/REST over the API | Audit cannot run at all |
39
39
  | **View Setup and Configuration** | `ViewSetup` | Reads the bulk of the surface: `SetupAuditTrail`, `TraceFlag`, `ConnectedApplication`, `RemoteProxy`, `CorsWhitelistEntry`, `CspTrustedSite`, `NamedCredential`, `AuthConfig`, `CriticalUpdate`/release updates, `Network` (Experience sites), `ProfileLoginIpRange`, `NetworkAccess`, `Certificate`, `ExternalString` (Custom Labels), `OrgWideEmailAddress`, `EmailServicesFunction`/`EmailServicesAddress`, and Tooling metadata (`ApexClass`, `Flow`, `CustomObject`/`CustomField`, `EntityDefinition`, `FieldDefinition`, `FieldPermissions`, `ObjectPermissions`, `SetupEntityAccess`, `WorkflowOutboundMessage`, `StaticResource`) | Most setup/config checks return **inconclusive** |
40
40
  | **Read `OauthToken`** | n/a (object read) | Standing OAuth authorisations per app, for `oauth-token-inventory`. Read separately from `ConnectedApplication`: a refresh token is exchanged without producing a login, so this is the only surface that shows an app which can still act | `oauth-token-inventory` returns **inconclusive** rather than reporting an org with no standing tokens |
41
- | **View All Users** | `ViewAllUsers` | Enumerate every `User`, `UserLogin`, `PermissionSetAssignment`, and `TwoFactorInfo` record org-wide (not just role-hierarchy-visible users) | User/admin/MFA checks under-count and miss accounts |
41
+ | **View All Users** | `ViewAllUsers` | Enumerate every `User`, `UserLogin` and `PermissionSetAssignment` record org-wide (not just role-hierarchy-visible users) | User/admin/MFA checks under-count and miss accounts |
42
42
  | **View Health Check** | `ViewHealthCheckScreen` | Read `SecurityHealthCheck` and `SecurityHealthCheckRisks` (Tooling) | Health Check + Password/Session checks inconclusive |
43
43
  | **Author Apex** | `AuthorApex` | **Read-only use:** the only standard gate that exposes `ApexClass`/`ApexTrigger`/`ApexPage` **`Body`** via the Tooling API. Used by the ~9 Apex/Visualforce code-security checks. Grants *no* ability to modify org data | The 9 code-security checks return **inconclusive**; rest of the audit is unaffected |
44
44
  | **View Event Log Files** | `ViewEventLogFiles` | Read `EventLogFile` for the Event Monitoring check | Event Monitoring check inconclusive |
@@ -49,6 +49,20 @@ permissions below, and nothing else. A starter permission-set definition is in
49
49
  |---|---|---|
50
50
  | **View Roles and Role Hierarchy** | `ViewRoles` | Complete visibility of role-based sharing context |
51
51
 
52
+ ### Optional, and not in the read-only set: MFA registration
53
+
54
+ `mfa-registration` reads `TwoFactorMethodsInfo`, which records each user's MFA methods. The
55
+ object is hidden without **Manage MFA in API** (`ManageTwoFactor`), and Salesforce will not grant
56
+ that permission without user-management permissions alongside it: Manage Users, Manage Internal
57
+ Users, Manage Sharing, Manage Roles, Reset Passwords, Freeze Users, Manage Profiles and Permission
58
+ Sets, Assign Permission Sets and others. That is far more than a read-only audit needs, so it is
59
+ not in `SF_Audit_ReadOnly`. Without it the check returns **inconclusive** and says why, and
60
+ `mfa-method-strength` has nothing to grade. Grant it only where the audit runs as an
61
+ administrator who already holds those permissions, using the separate
62
+ [`SF_Audit_MFA`](docs/permissionset/SF_Audit_MFA.permissionset-meta.xml) permission set: on a
63
+ System Administrator it adds just Manage MFA in API. Otherwise review MFA registration in Setup →
64
+ Identity → Identity Verification. Preflight lists it as optional.
65
+
52
66
  - **View Event Log Files**, **View Setup and Configuration**: required by `sf audit incident collect`.
53
67
  - **Query All Files**: lets `incident collect` see files owned by guest users. Without it the report states the gap.
54
68
 
@@ -67,7 +81,7 @@ security team is right to refuse them:
67
81
  - **`Manage Users`** / **`Manage Internal Users`**
68
82
  - Any **Create / Edit / Delete (DML)** permission on any object
69
83
  - **Metadata API** deploy/retrieve (`deployMetadata`, `modifyMetadata`)
70
- - Password, MFA, or session **management** permissions (the tool *reads* MFA/session config, it does not change it)
84
+ - Password, MFA, or session **management** permissions (the tool *reads* MFA/session config, it does not change it). The one exception is optional: see "MFA registration" above
71
85
 
72
86
  ## Important caveats
73
87
 
@@ -0,0 +1,36 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ SF Audit (MFA registration) permission set: optional, and separate from SF_Audit_ReadOnly.
4
+
5
+ `mfa-registration` reads TwoFactorMethodsInfo, which Salesforce hides without "Manage MFA in
6
+ API" (ManageTwoFactor). Salesforce refuses that permission unless the permission set also holds
7
+ the user-management permissions below, so this set is NOT read-only: it lets the holder manage
8
+ users, roles, sharing and passwords. Assign it only to an audit user who is already a System
9
+ Administrator (who holds all of these), where it adds just Manage MFA in API. Otherwise leave it
10
+ out: the check reports inconclusive and says why. See ../../PERMISSIONS.md.
11
+
12
+ Deploy it with the Salesforce CLI (metadata PermissionSet:SF_Audit_MFA), then assign it with
13
+ `sf org assign permset -n SF_Audit_MFA -o <orgAlias>`.
14
+ -->
15
+ <PermissionSet xmlns="http://soap.sforce.com/2006/04/metadata">
16
+ <description>Optional: Manage MFA in API for the sf-audit MFA registration check, with the user-management permissions Salesforce requires alongside it. Assign only to an audit user who is already a System Administrator.</description>
17
+ <hasActivationRequired>false</hasActivationRequired>
18
+ <label>SF Audit (MFA registration)</label>
19
+ <userPermissions><enabled>true</enabled><name>ManageTwoFactor</name></userPermissions>
20
+ <userPermissions><enabled>true</enabled><name>AssignPermissionSets</name></userPermissions>
21
+ <userPermissions><enabled>true</enabled><name>DelegatedTwoFactor</name></userPermissions>
22
+ <userPermissions><enabled>true</enabled><name>FreezeUsers</name></userPermissions>
23
+ <userPermissions><enabled>true</enabled><name>ManageInternalUsers</name></userPermissions>
24
+ <userPermissions><enabled>true</enabled><name>ManageIpAddresses</name></userPermissions>
25
+ <userPermissions><enabled>true</enabled><name>ManageLoginAccessPolicies</name></userPermissions>
26
+ <userPermissions><enabled>true</enabled><name>ManagePasswordPolicies</name></userPermissions>
27
+ <userPermissions><enabled>true</enabled><name>ManageProfilesPermissionsets</name></userPermissions>
28
+ <userPermissions><enabled>true</enabled><name>ManageRoles</name></userPermissions>
29
+ <userPermissions><enabled>true</enabled><name>ManageSharing</name></userPermissions>
30
+ <userPermissions><enabled>true</enabled><name>ManageUsers</name></userPermissions>
31
+ <userPermissions><enabled>true</enabled><name>MonitorLoginHistory</name></userPermissions>
32
+ <userPermissions><enabled>true</enabled><name>ResetPasswords</name></userPermissions>
33
+ <userPermissions><enabled>true</enabled><name>ViewAllUsers</name></userPermissions>
34
+ <userPermissions><enabled>true</enabled><name>ViewRoles</name></userPermissions>
35
+ <userPermissions><enabled>true</enabled><name>ViewSetup</name></userPermissions>
36
+ </PermissionSet>
@@ -46,9 +46,13 @@ export const CAPABILITY_REGISTRY = {
46
46
  // control of a matching origin and a logged-in victim visiting it, and yields at most that user's
47
47
  // own session-scoped access.
48
48
  'escalation-perms-found': { grants: ['priv-esc'], techniques: { 'priv-esc': ['T1098'] } },
49
- // Guest bulk-read surface (UI-API reachable) — the confirmed exfiltration sink
50
- 'guest-object-exposure-public-owd': { grants: ['unauth-foothold', 'data-read-bulk'] },
49
+ // Guest-owned records (UI-API reachable) are the confirmed bulk sink: form submissions nobody
50
+ // chose to publish. Records shared with guests are reach, not bulk: a guest sharing rule is how a
51
+ // site publishes records on purpose, so like 'guest-user-sharing-exposure' they need a step that
52
+ // reads in bulk, writes or runs code before the unauthenticated chain fires.
51
53
  'guest-object-exposure-guest-owned': { grants: ['unauth-foothold', 'data-read-bulk'] },
54
+ 'guest-object-exposure-public-owd': { grants: ['unauth-foothold', 'data-read'] },
55
+ 'guest-object-exposure-guest-shared': { grants: ['unauth-foothold', 'data-read'] },
52
56
  // Observed guest recon in EventLogFile — an active unauthenticated foothold
53
57
  'guest-traffic-anomaly-recon': { grants: ['unauth-foothold'], techniques: { 'unauth-foothold': [] } },
54
58
  'guest-traffic-anomaly-anonymizer': { grants: ['unauth-foothold'], techniques: { 'unauth-foothold': [] } },
@@ -56,12 +60,16 @@ export const CAPABILITY_REGISTRY = {
56
60
  'guest-api-access-enabled': { grants: ['unauth-foothold', 'data-read-bulk'] },
57
61
  'guest-api-hard-delete': { grants: ['unauth-foothold', 'data-write'], techniques: { 'data-write': ['T1485'] } },
58
62
  // Guest enumeration of other USERS. The staff roster is the targeting asset behind credential
59
- // stuffing and phishing at named admins, and both of the first two paths expose every User record
60
- // on their own, so both are bulk reads. The object-level Read grant is not: it makes User
61
- // queryable but still needs a sharing path before it returns anyone else's record.
63
+ // stuffing and phishing at named admins. View All Users exposes every User record, so it is a bulk
64
+ // read; it can no longer be granted to guests since Winter '21, so it is found only where an old
65
+ // grant survived. A live site's guest member visibility exposes that site's members, not the org's
66
+ // records: a read, not a bulk read.
62
67
  'guest-user-visibility-view-all-users': { grants: ['unauth-foothold', 'data-read-bulk'], techniques: { 'data-read-bulk': ['T1087.004', 'T1213.004'] } },
63
- 'guest-user-visibility-owd': { grants: ['unauth-foothold', 'data-read-bulk'], techniques: { 'data-read-bulk': ['T1087.004', 'T1213.004'] } },
64
- 'guest-user-visibility-object-read': { grants: ['unauth-foothold', 'data-read'], techniques: { 'data-read': ['T1087.004', 'T1213.004'] } },
68
+ 'guest-site-options-member-visibility': { grants: ['unauth-foothold', 'data-read'], techniques: { 'data-read': ['T1087.004'] } },
69
+ // The User external OWD reaches logged-in external users, not guests: secure guest record access
70
+ // keeps the guest OWD Private on every object. Like 'sharing-model-external-read', it is what an
71
+ // external account is worth.
72
+ 'guest-user-visibility-owd': { grants: ['low-trust-authenticated', 'data-read-bulk'], techniques: { 'data-read-bulk': ['T1087.004', 'T1213.004'] } },
65
73
  // Classic Visualforce sites — a second unauthenticated foothold surface
66
74
  'classic-sites-active': { grants: ['unauth-foothold'], techniques: { 'unauth-foothold': [] } },
67
75
  // Mass data-export capability — a bulk-read sink for an authenticated actor
@@ -142,7 +150,7 @@ export const CAPABILITY_REGISTRY = {
142
150
  'content-links-no-expiry': { grants: ['data-read'] },
143
151
  'content-links-no-password': { grants: ['data-read'] },
144
152
  // Self-registration is how an attacker obtains the account that every external-sharing finding
145
- // already assumes they have. On its own it is a supported feature and harmless; it earns a
153
+ // already assumes they have. On its own it gives an account only its own records; it earns a
146
154
  // capability because 'sharing-model-external-*' grants reach to whoever holds an account, and
147
155
  // this is the finding that says anyone may hold one.
148
156
  'experience-cloud-site-self-registration': { grants: ['low-trust-authenticated'], techniques: { 'low-trust-authenticated': ['T1136.003', 'T1078.004'] } },
@@ -1,7 +1,7 @@
1
1
  import { SOURCE_CAPS, HIGH_IMPACT_SINKS } from './Capability.js';
2
2
  import { capabilitiesFor } from './CapabilityRegistry.js';
3
3
  import { orderStepsByTactic, techniquesForGrant } from '../threats/attack.js';
4
- import { NAMED_CHAINS, inGroup } from './namedChains.js';
4
+ import { NAMED_CHAINS, UNAUTH_EXFIL_STEPS, UNAUTH_RECORD_REACH, inGroup } from './namedChains.js';
5
5
  const SEVERITY_ORDER = {
6
6
  CRITICAL: 0, HIGH: 1, MEDIUM: 2, LOW: 3, INFO: 4,
7
7
  };
@@ -119,9 +119,17 @@ export class ChainEngine {
119
119
  const hasRealSource = active.some((f) => !SURFACE_ONLY.has(f.id) && (grantsByFinding.get(f) ?? []).includes(src));
120
120
  if (!hasRealSource)
121
121
  continue;
122
+ // A guest reaches only what the guest side grants: an internal user's View All Data or an
123
+ // admin's Author Apex is no sink for an unauthenticated foothold (as in unauth-bulk-exfil).
124
+ const reaches = (f) => src !== 'unauth-foothold' || UNAUTH_EXFIL_STEPS.includes(f.id);
125
+ // Nor is a guest path potential when no step shows the guest reaching a record.
126
+ if (src === 'unauth-foothold' && !active.some((f) => UNAUTH_RECORD_REACH.includes(f.id)))
127
+ continue;
122
128
  for (const sink of HIGH_IMPACT_SINKS) {
123
129
  if (!present.has(sink))
124
130
  continue;
131
+ if (!active.some((f) => reaches(f) && (grantsByFinding.get(f) ?? []).includes(sink)))
132
+ continue;
125
133
  const key = `${src}->${sink}`;
126
134
  if (covered.has(key) || seen.has(key))
127
135
  continue;
@@ -130,7 +138,7 @@ export class ChainEngine {
130
138
  const members = [];
131
139
  for (const f of active) {
132
140
  const g = grantsByFinding.get(f) ?? [];
133
- if (g.includes(src) || g.includes(sink) || g.includes('code-exec'))
141
+ if (g.includes(src) || (reaches(f) && (g.includes(sink) || g.includes('code-exec'))))
134
142
  members.push(f);
135
143
  if (members.length >= MAX_STEPS)
136
144
  break;
@@ -52,6 +52,7 @@ export declare const GUEST_EXPOSURE: string[];
52
52
  export declare const LOW_TRUST_ENTRY: string[];
53
53
  export declare const NON_ADMIN_ESCALATION: string[];
54
54
  export declare const UNAUTH_EXFIL_STEPS: string[];
55
+ export declare const UNAUTH_RECORD_REACH: string[];
55
56
  export declare const UNAUTH_EXFIL_WIDENERS: string[];
56
57
  export declare const GUEST_TRAFFIC: string[];
57
58
  export declare const GUEST_BULK_SURFACE: string[];
@@ -24,16 +24,19 @@ const byPrefixes = (active, prefixes) => active.filter((f) => prefixes.some((p)
24
24
  export const GUEST_EXPOSURE = [
25
25
  'guest-user-read-access', 'guest-user-write-access', 'guest-user-sharing-exposure',
26
26
  'guest-executable-apex-unprotected', 'guest-executable-apex-exposed', 'guest-executable-apex-system-mode',
27
- 'guest-object-exposure-public-owd', 'guest-object-exposure-guest-owned',
27
+ 'guest-object-exposure-public-owd', 'guest-object-exposure-guest-owned', 'guest-object-exposure-guest-shared',
28
28
  'guest-api-access-enabled', 'guest-api-hard-delete',
29
- 'guest-user-visibility-view-all-users', 'guest-user-visibility-owd', 'guest-user-visibility-object-read',
29
+ // Not 'guest-user-visibility-owd': the User external OWD reaches logged-in external users, not guests.
30
+ // Not 'guest-site-options-member-visibility': a site's member list is no foothold into org data,
31
+ // and this list also gates the low-trust chains (LOW_TRUST_ENTRY).
32
+ 'guest-user-visibility-view-all-users',
30
33
  'guest-record-access-policy-not-enforced',
31
34
  'inbound-email-handler-unauthenticated-execution',
32
35
  ];
33
36
  // Ways in for a low-trust principal: external users with public sharing, social sign-on,
34
37
  // self-registration, or a confirmed guest exposure. RULE-072.
35
38
  export const LOW_TRUST_ENTRY = [
36
- 'sharing-model-external-read', 'sharing-model-external-write',
39
+ 'sharing-model-external-read', 'sharing-model-external-write', 'guest-user-visibility-owd',
37
40
  'auth-providers-social', 'experience-cloud-site-self-registration',
38
41
  ...GUEST_EXPOSURE,
39
42
  ];
@@ -49,29 +52,49 @@ export const NON_ADMIN_ESCALATION = [
49
52
  export const UNAUTH_EXFIL_STEPS = [
50
53
  'guest-user-read-access', 'guest-user-write-access', 'guest-user-sharing-exposure', 'guest-user-baseline',
51
54
  'guest-executable-apex-unprotected', 'guest-executable-apex-exposed', 'guest-executable-apex-system-mode',
52
- 'guest-object-exposure-public-owd', 'guest-object-exposure-guest-owned',
55
+ 'guest-object-exposure-public-owd', 'guest-object-exposure-guest-owned', 'guest-object-exposure-guest-shared',
53
56
  'guest-api-access-enabled', 'guest-api-hard-delete', 'classic-sites-active',
54
- 'guest-user-visibility-view-all-users', 'guest-user-visibility-owd', 'guest-user-visibility-object-read',
55
- 'portal-exposed-apex-without-sharing', 'sharing-model-external-read', 'sharing-model-external-write',
57
+ 'guest-user-visibility-view-all-users', 'guest-site-options-member-visibility',
58
+ // Not 'sharing-model-external-*': since Winter '21 guest record access is always secured, so the
59
+ // external OWD reaches logged-in portal users, not guests. Those findings drive the low-trust chains.
60
+ // Not 'portal-exposed-apex-without-sharing' or 'flows-*-without-sharing' either: they flag any
61
+ // @AuraEnabled class or any Flow, which a logged-in user may be the only one able to call. The
62
+ // guest-side counterpart is 'guest-executable-apex-*', read from the guest profile's class access.
56
63
  'field-level-security-high', 'field-level-security-medium',
57
- // The guardrail whose absence lets guest-owned records defeat a Private OWD, and the Flow
58
- // analogue of portal-exposed Apex running without sharing.
64
+ // The guardrail whose absence lets guest-owned records defeat a Private OWD.
59
65
  'guest-record-access-policy-not-enforced',
60
- 'flows-autolaunched-without-sharing', 'flows-screen-without-sharing',
61
66
  // An open inbound email handler grants unauth-foothold, so it must appear whenever it
62
67
  // is what opened the gate.
63
68
  'inbound-email-handler-unauthenticated-execution',
64
69
  ];
70
+ // Steps that show a guest reaching records: a guest sharing rule, guest-owned or confirmed-readable
71
+ // records, the User roster, or guest-callable Apex that runs without sharing. Object permissions,
72
+ // API access, or guest-callable Apex not shown to bypass sharing (SYSTEM_MODE lifts CRUD/FLS only)
73
+ // reach no record on their own: secure guest record access leaves the guest nothing to read.
74
+ export const UNAUTH_RECORD_REACH = [
75
+ 'guest-user-sharing-exposure', 'guest-object-exposure-public-owd', 'guest-object-exposure-guest-owned',
76
+ 'guest-object-exposure-guest-shared',
77
+ // Not 'guest-user-visibility-owd': the guest OWD is Private on every object, User included.
78
+ // Not 'guest-site-options-member-visibility': it shows a site's members, not business records.
79
+ 'guest-user-visibility-view-all-users',
80
+ 'guest-executable-apex-unprotected',
81
+ // Secure guest record access is what makes the rest of this list necessary: with it off, legacy
82
+ // sharing and guest ownership reach records directly.
83
+ 'guest-record-access-policy-not-enforced',
84
+ ];
85
+ // What a guest-side step must grant for the visitor to reach data or run code.
86
+ const UNAUTH_EXFIL_REACH = ['code-exec', 'data-read-bulk', 'data-write'];
65
87
  // Internal-only weaknesses that widen what a foothold reaches. They join as evidence but
66
88
  // never count toward the floor: without a guest-side step they describe no unauthenticated path.
67
89
  export const UNAUTH_EXFIL_WIDENERS = ['data-cloud-data-space-default-overshared', 'restriction-rules-inactive'];
68
90
  export const GUEST_TRAFFIC = ['guest-traffic-anomaly-recon', 'guest-traffic-anomaly-anonymizer'];
69
91
  // A readable User roster counts as an exposed surface in its own right — recon against an org
70
- // that leaks its staff list is the same incident. The object-level Read grant is excluded: on
71
- // its own it is not a confirmed exposure, and this chain asserts one already in progress.
92
+ // that leaks its staff list is the same incident.
93
+ // Records shared with guests are left out: a site publishes those on purpose, and they are reads,
94
+ // not the bulk surface this chain needs.
72
95
  export const GUEST_BULK_SURFACE = [
73
- 'guest-object-exposure-public-owd', 'guest-object-exposure-guest-owned',
74
- 'guest-user-visibility-view-all-users', 'guest-user-visibility-owd',
96
+ 'guest-object-exposure-guest-owned',
97
+ 'guest-user-visibility-view-all-users',
75
98
  ];
76
99
  // Admin powers: they widen what a takeover reaches but are not themselves the escalation.
77
100
  export const TAKEOVER_ADMIN_EVIDENCE = [
@@ -173,6 +196,8 @@ export const SELF_REGISTRATION = ['experience-cloud-site-self-registration'];
173
196
  // licence, which generally has no report access at all, so including it would overstate reach.
174
197
  export const PORTAL_REACH = [
175
198
  'sharing-model-external-read', 'sharing-model-external-write',
199
+ // A public external OWD on User shows every logged-in external user the staff roster.
200
+ 'guest-user-visibility-owd',
176
201
  'portal-exposed-apex-without-sharing',
177
202
  'flows-autolaunched-without-sharing', 'flows-screen-without-sharing',
178
203
  'apex-rest-without-sharing',
@@ -233,22 +258,22 @@ export const NAMED_CHAINS = [
233
258
  id: 'unauth-bulk-exfil',
234
259
  title: 'Unauthenticated bulk exfiltration',
235
260
  severity: 'CRITICAL',
236
- narrative: 'An unauthenticated guest foothold combines with guest-reachable code execution or public ' +
237
- 'external sharing to read business data in bulk without any login. In practice this is ' +
261
+ narrative: 'An unauthenticated guest foothold combines with guest-reachable code execution or guest ' +
262
+ 'record access to read business data in bulk without any login. In practice this is ' +
238
263
  'reached over the site\'s Aura endpoint (/s/sfsites/aura) with aura.token=null: ' +
239
264
  'RecordUiController/ACTION$executeGraphQL returns record data the guest user can see, and ' +
240
265
  'aura.ApexAction.execute invokes @AuraEnabled Apex — which, in a class that runs without ' +
241
266
  'sharing, skips record-level access control entirely and will accept arbitrary record ids. ' +
242
267
  'No credentials are involved at any point, so login-based controls (MFA, IP ranges, SSO) ' +
243
268
  'never engage.',
244
- remediation: 'Remove guest object/sharing access, ensure no guest-invokable Apex runs without sharing, ' +
245
- 'and set external OWD to Private. Grant portal access only via sharing sets. Because the ' +
269
+ remediation: 'Remove guest object permissions and guest sharing rules, and ensure no guest-invokable Apex ' +
270
+ 'runs without sharing. Because the ' +
246
271
  'requests never reach a login page, tightening authentication does not mitigate this — the ' +
247
272
  'object permissions, sharing model and Apex sharing declarations are the controls that apply.',
248
273
  abuseCase: {
249
274
  actor: 'an unauthenticated site visitor',
250
275
  goal: 'read or change business data in bulk without logging in',
251
- preconditions: [{ ids: GUEST_EXPOSURE }, { ids: UNAUTH_EXFIL_STEPS }, { ids: UNAUTH_EXFIL_WIDENERS }, { capabilities: ['unauth-foothold'] }, { capabilities: ['code-exec', 'data-read-bulk', 'data-write'] }],
276
+ preconditions: [{ ids: GUEST_EXPOSURE }, { ids: UNAUTH_EXFIL_STEPS }, { ids: UNAUTH_EXFIL_WIDENERS }, { capabilities: ['unauth-foothold'] }, { capabilities: UNAUTH_EXFIL_REACH }, { ids: UNAUTH_RECORD_REACH }],
252
277
  breakPoint: 0,
253
278
  tactics: { entry: 'initial-access', goal: 'collection' },
254
279
  breakPointText: 'Close every confirmed guest exposure: guest object and record access, guest-callable Apex, guest API access, guest visibility of users, the guest record-access policy, and unauthenticated email handlers.',
@@ -256,8 +281,6 @@ export const NAMED_CHAINS = [
256
281
  match(present, active) {
257
282
  if (!has(present, 'unauth-foothold'))
258
283
  return null;
259
- if (!hasAny(present, 'code-exec', 'data-read-bulk', 'data-write'))
260
- return null;
261
284
  // A surface and internal weaknesses are not a path: an unauthenticated visitor must be shown
262
285
  // to reach something.
263
286
  if (byIds(active, GUEST_EXPOSURE).length === 0)
@@ -265,6 +288,12 @@ export const NAMED_CHAINS = [
265
288
  const steps = byIds(active, UNAUTH_EXFIL_STEPS);
266
289
  if (steps.length < 2)
267
290
  return null;
291
+ // The bulk read, write or code execution must be the guest's own. An internal user's
292
+ // Modify All Data or an admin's Author Apex says nothing about what a visitor reaches.
293
+ if (!steps.some((s) => capabilitiesFor(s).grants.some((c) => UNAUTH_EXFIL_REACH.includes(c))))
294
+ return null;
295
+ if (byIds(steps, UNAUTH_RECORD_REACH).length === 0)
296
+ return null;
268
297
  return [...steps, ...byIds(active, UNAUTH_EXFIL_WIDENERS)];
269
298
  },
270
299
  },
@@ -326,7 +355,9 @@ export const NAMED_CHAINS = [
326
355
  {
327
356
  id: 'cred-theft-pivot',
328
357
  title: 'Credential theft to external pivot',
329
- severity: 'CRITICAL',
358
+ // HIGH, not CRITICAL: the secret is found by pattern match, and the egress steps are mostly the
359
+ // org's own registered endpoints, which give an attacker holding the secret nothing they lack.
360
+ severity: 'HIGH',
330
361
  narrative: 'Exposed secrets (hardcoded credentials, credentials in custom labels or settings, or enabled device or password OAuth flows) ' +
331
362
  'combine with an external egress path (named credential, remote site or Flow callout) to exfiltrate data to attacker infrastructure.',
332
363
  remediation: 'Rotate and remove exposed secrets, and review external callout endpoints.',
@@ -635,11 +666,13 @@ export const NAMED_CHAINS = [
635
666
  'login IP ranges and SSO all behave exactly as configured and none of them object, because ' +
636
667
  'nothing here is a bypass. What the attacker gets is decided entirely by the external OWD, ' +
637
668
  'the portal profile and whether the Apex or Flow reachable from the site enforces sharing. ' +
638
- 'Self-registration alone is a supported feature and not a finding; the sharing model alone ' +
639
- 'assumes an account the attacker may never obtain. The pair is the path.',
640
- remediation: 'Decide which half to close, because either breaks the chain. Turning self-registration off, ' +
641
- 'or putting an approval step in front of it, restores the assumption every other control ' +
642
- 'depends on. Leaving it on means treating the self-registration profile as hostile input: ' +
669
+ 'Neither half makes the path on its own: a self-registered account with only its own records ' +
670
+ 'reaches nothing, and the sharing model assumes an account the attacker may never obtain. ' +
671
+ 'The pair is the path.',
672
+ remediation: 'Turn self-registration off, or route it through a custom registration handler that approves ' +
673
+ 'each account before it gets access: that restores the ' +
674
+ 'assumption every other control depends on. If the site must stay open, close the other half ' +
675
+ 'instead and treat the self-registration profile as hostile input: ' +
643
676
  'set external OWD to Private and grant through sharing sets rather than org-wide defaults, ' +
644
677
  'and make sure Apex and Flows reachable from the site run with sharing. Check what the ' +
645
678
  'self-registration handler assigns as the default profile and licence — the exposure is ' +
@@ -1,5 +1,5 @@
1
1
  import { testApexPattern } from '@cclabsnz/sf-core';
2
- import { apexCode, codeWithoutStrings, DML_AS_USER, usesSystemMode } from '../support/apexAccess.js';
2
+ import { apexApiVersions, apexCode, codeWithoutStrings, DML_AS_USER, OMITTED_SHARING_ENFORCED_FROM, usesSystemMode } from '../support/apexAccess.js';
3
3
  // Patterns that indicate DML or inline SOQL is being performed
4
4
  const HAS_DML = /\b(?:insert|update|delete|upsert|undelete|merge)\s+\w+|Database\.(?:insert|update|delete|upsert|undelete|merge)\w*\s*\(/i;
5
5
  // SOQL and SOSL, inline or dynamic.
@@ -39,6 +39,11 @@ export class ApexCrudFLSCheck {
39
39
  const withoutSharingNoFls = [];
40
40
  const withDmlNoFls = [];
41
41
  const systemMode = [];
42
+ // From API 67.0 (Summer '26) SOQL, SOSL, DML and Database methods run in user mode unless they
43
+ // say otherwise, so a class saved at 67.0 or later enforces CRUD/FLS by default (spec RULE-009).
44
+ // SYSTEM_MODE is still reported above that default.
45
+ const versions = await apexApiVersions(ctx);
46
+ let userModeByDefault = 0;
42
47
  // apexBodies is pre-filtered by HardcodedCredentialsCheck, which excludes @IsTest classes
43
48
  // before populating the cache. There is deliberately no second guard here: a cache miss
44
49
  // yields an empty array, not unfiltered bodies, so there is nothing for one to catch.
@@ -59,6 +64,10 @@ export class ApexCrudFLSCheck {
59
64
  continue;
60
65
  if (testApexPattern(body, IS_BATCH_OR_SCHEDULED))
61
66
  continue;
67
+ if ((versions.get(name.toLowerCase()) ?? 0) >= OMITTED_SHARING_ENFORCED_FROM) {
68
+ userModeByDefault++;
69
+ continue;
70
+ }
62
71
  // Enforcement must be code, not text: 'WITH USER_MODE' inside a debug string enforces nothing.
63
72
  const enforcementCode = codeWithoutStrings(raw);
64
73
  const hasFls = testApexPattern(enforcementCode, HAS_FLS) || testApexPattern(enforcementCode, DML_AS_USER);
@@ -78,7 +87,7 @@ export class ApexCrudFLSCheck {
78
87
  riskLevel: 'HIGH',
79
88
  title: `${withoutSharingNoFls.length} Apex class(es) run "without sharing" and perform DML/SOQL without CRUD/FLS checks`,
80
89
  detail: `Apex classes declared "without sharing" bypass record-level visibility AND have no field-level or object-level permission checks, meaning any user who triggers the code can read or write any record and field regardless of their assigned permissions. This is the most exploited Salesforce access control vulnerability. OWASP Salesforce Top 10 ranks CRUD/FLS bypass as the #1 risk.`,
81
- remediation: 'Refactor to use "with sharing" where possible. Add `Security.stripInaccessible()` before DML and `Schema.SObjectType.[Object].fields.[Field].isAccessible()` before displaying fields. Where "without sharing" is required for a technical reason, document the justification and tighten the scope.',
90
+ remediation: 'Enforce object and field permissions with `WITH USER_MODE`, or `Security.stripInaccessible()` before DML and `Schema.SObjectType.[Object].fields.[Field].isAccessible()` before displaying fields. "with sharing" alone does not do this: it enforces record sharing only. Declare "with sharing" too where possible, and where "without sharing" is required for a technical reason, document the justification and tighten the scope.',
82
91
  affectedItems: withoutSharingNoFls.slice(0, 30).map((n) => ({
83
92
  label: n,
84
93
  url: apexClassesUrl,
@@ -123,7 +132,7 @@ export class ApexCrudFLSCheck {
123
132
  riskLevel: 'LOW',
124
133
  passed: true,
125
134
  title: 'All scanned Apex classes with DML/SOQL include CRUD/FLS permission checks',
126
- detail: 'No Apex classes were found performing DML or SOQL without corresponding object-level or field-level security checks. This scan covers non-test, non-batch classes in the org namespace.',
135
+ detail: `No Apex classes were found performing DML or SOQL without corresponding object-level or field-level security checks. This scan covers non-test, non-batch classes in the org namespace.${userModeByDefault > 0 ? ` ${userModeByDefault} class(es) saved at API 67.0 or later rely on user mode, the default for their queries and DML from that version.` : ''}`,
127
136
  remediation: 'Continue monitoring as new Apex classes are developed.',
128
137
  });
129
138
  }
@@ -1,6 +1,5 @@
1
+ import { apexApiVersions, declaresWithoutSharing, effectiveSharing, omittedSharingEnforced } from '../support/apexAccess.js';
1
2
  const REST_RESOURCE_RE = /@RestResource\s*\(\s*urlMapping\s*=/i;
2
- const WITHOUT_SHARING_RE = /\bwithout\s+sharing\b/i;
3
- const NO_SHARING_DECLARED_RE = /\b(with|without|inherited)\s+sharing\b/i;
4
3
  const IS_TEST_RE = /@IsTest\b/i;
5
4
  export class ApexRestEndpointCheck {
6
5
  id = 'apex-rest-endpoint';
@@ -51,8 +50,14 @@ export class ApexRestEndpointCheck {
51
50
  note: 'Custom REST endpoint: review access controls',
52
51
  })),
53
52
  });
54
- // Flag endpoints declared without sharing — REST callers bypass record-level access
55
- const withoutSharing = restClasses.filter(({ body }) => WITHOUT_SHARING_RE.test(body));
53
+ // A class with no keyword takes its parent's sharing (spec MN-001).
54
+ const bodyByName = new Map(apexBodies.map((b) => [b.name.toLowerCase(), b.body ?? '']));
55
+ const lookup = (n) => bodyByName.get(n.toLowerCase());
56
+ const sharingOf = (c) => effectiveSharing(c.name, c.body, lookup);
57
+ // Flag endpoints declared (or inheriting) without sharing — REST callers bypass record-level access
58
+ // Read from code, not text: "without sharing" in a comment or string runs nothing. An inner class
59
+ // declared without sharing counts, as in the guest Apex check: the endpoint can call into it.
60
+ const withoutSharing = restClasses.filter((c) => declaresWithoutSharing(c.body) || sharingOf(c) === 'without');
56
61
  if (withoutSharing.length > 0) {
57
62
  findings.push({
58
63
  id: 'apex-rest-without-sharing',
@@ -68,15 +73,18 @@ export class ApexRestEndpointCheck {
68
73
  })),
69
74
  });
70
75
  }
71
- // Flag endpoints with no sharing declaration at all (inherits from caller — unpredictable)
72
- const noSharingDeclaration = restClasses.filter(({ body }) => !WITHOUT_SHARING_RE.test(body) && !NO_SHARING_DECLARED_RE.test(body));
76
+ // Flag endpoints with no sharing declaration at all, unless compiled at API 67.0 or later,
77
+ // where an omitted keyword means with sharing (spec RULE-007).
78
+ const undeclared = restClasses.filter((c) => !withoutSharing.includes(c) && sharingOf(c) === 'none');
79
+ const versions = undeclared.length > 0 ? await apexApiVersions(ctx) : new Map();
80
+ const noSharingDeclaration = undeclared.filter((c) => !omittedSharingEnforced(c.name, c.body, lookup, (n) => versions.get(n.toLowerCase())));
73
81
  if (noSharingDeclaration.length > 0) {
74
82
  findings.push({
75
83
  id: 'apex-rest-no-sharing-declaration',
76
84
  category: this.category,
77
85
  riskLevel: 'MEDIUM',
78
86
  title: `${noSharingDeclaration.length} REST endpoint class(es) have no sharing declaration`,
79
- detail: `Apex classes with no sharing declaration inherit sharing mode from their caller, which is non-deterministic for REST API calls. In REST API contexts the caller is typically the integration user, whose sharing context may be broader than intended. Explicit "with sharing" is required for predictable, secure behaviour.`,
87
+ detail: `These REST endpoint classes declare no sharing keyword and are not shown to be saved at API 67.0 or later (with every keyword-less parent; a version that could not be read counts as older). A REST call enters the class directly, so it runs without sharing, and every caller reaches records beyond its own sharing. From API 67.0 (Summer '26) an omitted keyword means with sharing, but only for classes saved at that version. Explicit "with sharing" is required for predictable, secure behaviour.`,
80
88
  remediation: 'Add "with sharing" to all @RestResource classes to make sharing enforcement explicit and predictable.',
81
89
  affectedItems: noSharingDeclaration.map(({ name }) => ({
82
90
  label: name,