Source: https://www.vtfriday.com/2026/12/salesforce-guest-user-security-model.html
Private, guests cannot own records, and record visibility requires explicit, read-only Guest User Sharing Rules paired with stripped-down profile permissions.
Whenever you publish an Experience Cloud site, a Salesforce Site, or a public Visualforce page, visitors who have not signed in still need a technical user context to load pages, browse a product catalog, or submit a form. Salesforce handles that by giving every public site a dedicated Guest User license and its own Guest User Profile. Getting this profile right is one of the highest-stakes security checks you will ever do on a public Salesforce org.
📌 Key Points
- Every anonymous visitor hitting a public Experience Cloud site operates under the exact same Guest User record and profile.
- Salesforce permanently enforces Secure guest user record access, locking external Organization-Wide Defaults (OWD) for the guest user to
Private. - Guest users cannot get access through the Role Hierarchy, public groups, queues, or manual sharing. The only declarative way to let a guest read records is a criteria-based Guest User Sharing Rule, which is strictly
Read Only. - Guests cannot own records. Anything a guest creates is automatically handed over to a designated default internal owner.
- Salesforce blocks
View All,Modify All,Edit, andDeleteobject permissions on Guest User profiles for standard and custom objects.
Read on a custom Invoice__c object plus a broad sharing rule left over from an early demo. Because the guest user needs no login, any stranger inspecting network traffic or calling the Experience Cloud Aura/LWR endpoints can pull those invoice records straight out of the org.
🔍 Understanding the Guest User Security Model
For internal Salesforce users, you set baseline access with OWD, open vertical visibility with the Role Hierarchy, and handle exceptions with Sharing Rules. Unauthenticated traffic works by a stricter set of rules.
An anonymous visitor has not proved who they are. There is no session tied to an employee or a verified customer. If one visitor can read a record through the Guest User profile, every person and automated script on the internet can read that same record through the site's underlying endpoints. You do not need a table on the screen for data to leak. If the Guest User profile has object and field access and a sharing rule (or an unsafe Apex controller) returns those rows, the platform APIs behind Experience Cloud will hand them over.
How Salesforce Hardened the Guest Model
Years ago, admins could leave external OWD at Public Read/Write or flip on View All on a Guest User profile to make a page work quickly. After a wave of public portal misconfigurations leaked real customer records, Salesforce permanently locked down the guest model across several releases (culminating in mandatory enforcement in Winter '21 and Spring '21):
- Enforced Private OWD: Under Setup > Sharing Settings, Secure guest user record access is locked on. Even if your internal or external OWD is
Public Read OnlyorPublic Read/Write, the effective OWD for any guest user staysPrivate. - Removed from Role Hierarchy and groups: Guest users cannot hold a Role, cannot join Public Groups or Queues, and cannot receive records through Owner-based sharing rules or manual sharing.
- Guest User Sharing Rules only: To expose records to a guest, you create a criteria-based Guest User Sharing Rule (for example,
Is_Active__c = TRUE). It grantsRead Onlyaccess to that site's Guest User and never allowsRead/Write. - Default Owner for guest-created records: In the old model, when an anonymous visitor submitted a form creating a
LeadorCase, the Guest User became theOwnerId. Because owners have full access to their own records, the next anonymous visitor (sharing that exact same Guest User account) could read records created by previous visitors. Today, guests cannot own records. Under Workspaces > Administration > Preferences, you assign an active internal user as the Default Owner for anything a guest inserts.
🎬 Example Scenario: Leaving Read on Invoice "For a Demo"
The Context: A team is building a public Experience Cloud product catalog. Right before a stakeholder demo, a developer temporarily gives the Guest User profile Read on Invoice__c and adds a catch-all sharing rule (Id != null) to debug a component.
The Bad Pattern: Nobody tracks the temporary permission in a ticket or removes it after the demo. Three weeks later, the site launches publicly with both still turned on.
Why It Fails: Because every anonymous visitor shares the Guest User identity, anyone querying the Experience Cloud site's standard record endpoints can pull Invoice__c rows directly, even after the UI component is removed from the homepage.
The Fix: Strip the Guest User profile down to zero unnecessary objects. Grant Read only on the catalog object, enable Field-Level Security (FLS) strictly on public display fields (like Name, SKU, and Public Price), and write a Guest User Sharing Rule filtering specifically for Status__c = 'Published'.
The Result: The public catalog loads cleanly, draft products stay hidden in Salesforce, and internal billing objects remain completely unreachable without a login.
🛠️ Worked Implementation: Securing a Public Catalog
Locking down a public catalog takes both declarative setup and disciplined Apex. A single sloppy controller can punch right through a tight sharing rule.
Step 1: Declarative Configuration Checklist
Set up the declarative boundaries in Setup before writing any Lightning Web Component (LWC) or Apex:
// Declarative Guest Access Checklist (Setup Configuration): // 1. Sharing Settings: Confirm 'Secure guest user record access' is ON (enforced by platform). // 2. Guest User Profile: Grant 'Read' ONLY on the target object (e.g., Catalog_Item__c). // 3. Field-Level Security (FLS): Grant 'Read' only on public fields (Name, Public_Description__c). // Keep internal fields (Wholesale_Cost__c, Internal_Notes__c) unchecked. // 4. Sharing Settings -> Catalog_Item__c Sharing Rules: // - Rule Type: Guest user access, based on criteria // - Criteria: Status__c EQUALS 'Published' AND Is_Public__c EQUALS True // - Share with: [Your Site Name] Site Guest User // - Access Level: Read Only // 5. Experience Workspaces -> Administration -> Preferences: // - Set an active internal user for 'Assign new records created by guest users to the default owner'.
Step 2: Safe vs. Unsafe Apex Controllers
Even with a tight Guest User Sharing Rule, an Apex class marked without sharing bypasses those rules completely.
Prerequisites and context: These excerpts assume a custom object Catalog_Item__c with Public_Price__c (Currency), Status__c (Picklist), and Wholesale_Margin__c (Percent), called from an LWC on an Experience Cloud page. Test and adapt them in a sandbox before deploying.
// EDUCATIONAL EXAMPLE ONLY -- DO NOT DEPLOY
// Vulnerability: Runs 'without sharing' and skips FLS enforcement and status filtering.
public without sharing class UnsafeCatalogController {
@AuraEnabled(cacheable=true)
public static List<Catalog_Item__c> getItems(String searchTerm) {
String key = '%' + (searchTerm == null ? '' : searchTerm.trim()) + '%';
// Because of 'without sharing', this returns Draft and Internal items
// even though the Guest User Sharing Rule only shares 'Published' items.
return [
SELECT Id, Name, Public_Price__c, Status__c, Wholesale_Margin__c
FROM Catalog_Item__c
WHERE Name LIKE :key
LIMIT 50
];
}
}
The class above is dangerous for two reasons. Marking it without sharing tells Salesforce to ignore both the Private OWD and your Guest User Sharing Rule. Standard SOQL also ignores Field-Level Security unless you enforce user mode. Any anonymous visitor calling getItems('') through the site's Aura/LWR endpoint gets unreleased draft products and internal Wholesale_Margin__c values right in the JSON response.
Here is the safer version:
// RECOMMENDED PATTERN -- Test in your sandbox environment before deployment
// Enforces sharing rules ('with sharing') and user-mode FLS/CRUD ('WITH USER_MODE').
public with sharing class SafeCatalogController {
@AuraEnabled(cacheable=true)
public static List<Catalog_Item__c> getPublishedItems(String searchTerm) {
String cleanTerm = (searchTerm == null) ? '' : searchTerm.trim();
String searchPattern = '%' + cleanTerm + '%';
// 1. 'with sharing' enforces the Guest User Sharing Rule.
// 2. Static SOQL bind variable (:searchPattern) prevents SOQL injection.
// 3. Explicit WHERE Status__c filter adds defense in depth.
// 4. 'WITH USER_MODE' (GA in API v57.0 / Spring '23) enforces CRUD, FLS, and sharing.
return [
SELECT Id, Name, Public_Price__c
FROM Catalog_Item__c
WHERE Status__c = 'Published'
AND Name LIKE :searchPattern
WITH USER_MODE
ORDER BY Name ASC
LIMIT 50
];
}
}
What this solves and where its limits sit:
- Declaring
with sharingenforces the Guest User Sharing Rule, so even if someone changes theWHEREclause later, Salesforce will not return rows outside that rule. - Adding
WITH USER_MODE(generally available in API version 57.0 / Spring '23) makes SOQL check the Guest User profile's object permissions and FLS. If a developer accidentally addsWholesale_Margin__cto the query without granting the guest FLS, Salesforce throws aSystem.QueryExceptioninstead of leaking the field. - Code-level checks still cannot save you if your Guest User profile is over-permissioned and your sharing rule is too wide (like
Status__c != null). Both Setup and Apex have to stay tight.
⚠️ Common Mistakes and How to Verify Your Setup
🪤 Common Mistakes to Avoid:
- Trying to update a record right after a Guest User inserts it. This happens all the time in multi-step public forms: Step 1 inserts a
LeadorApplication__c, and Step 2 tries toupdatethat same record ID. Because the Guest User cannot own the record and hasPrivateOWD, they lose access to the row the instant the insert commits. Never create a Guest User Sharing Rule onLeadorCaseto work around this, or you expose customer leads to the public. Collect all steps on the client and do one insert at the end, or use a narrowly scoped, encrypted token checked inside a tightly controlled Apex method that accepts specific updates without returning record data. - Assuming a hidden UI component means hidden data. Pulling a field or Related List off an Experience Builder page never revokes Guest User profile access. Remove the object permission and FLS on the profile itself.
- Granting
@AuraEnabledApex classes too broadly. Only assign the exact Apex classes your public pages need to the Guest User profile, and audit every one of them forwithout sharingorinherited sharingcalled from an unshared entry point.
How to Validate Your Configuration
Do not stop at previewing the site as a System Administrator in Experience Builder. Builder preview often hides guest permission mistakes. Test in a sandbox like this:
- Open a separate browser in an Incognito / Private window with no active Salesforce login, and load the published sandbox site URL.
- Check the positive path: confirm records matching your Guest User Sharing Rule (
Status__c = 'Published') load normally. - Check the negative path: create a record with
Status__c = 'Draft', copy its 18-character Record ID, and open its detail URL on the public site (/s/detail/a01...). Confirm you get an error or empty page rather than the draft record. - Run the Guest User Access Report (from AppExchange or Setup audit tools) to review every object, field, sharing rule, and Apex class currently open to your Guest User profile.
🧭 360 Card: Guest User Security Model
Rule: Start the Guest User profile with zero object access and grant only the minimum Read (or Create for intake forms) permissions paired with narrow, criteria-based Guest User Sharing Rules.
Benefit: Public visitors see only explicitly published catalog or knowledge records while internal CRM data stays unreachable at the database layer.
Tradeoff: Multi-step unauthenticated workflows (like saving and resuming a public application or reading back a submitted case) cannot rely on standard ownership or sharing and require custom token patterns or authenticated Experience Cloud licenses.
Limits: Guest OWD is locked to Private, Guest User Sharing Rules are criteria-based and Read Only, guests cannot own records or join groups/roles, and a single without sharing Apex method can bypass every declarative guardrail if exposed.
❓ Core Q&A and Scenario Walkthroughs
Read on the product object and public fields on the Guest User profile, keep guest OWD locked to Private, and create a criteria-based Guest User Sharing Rule sharing only records where Status = 'Published'.
A: Layer three controls together:
- Open the site's Guest User profile and grant
Readonly on the Product object, with Read FLS strictly on customer-facing fields. Leave every other object turned off (Salesforce already blocksView AllandModify Allfor guests). - Because guest OWD is forced to
Private, profileReadalone exposes zero rows. In Setup > Sharing Settings, add a Guest User Sharing Rule on the Product object with criteriaStatus EQUALS 'Published'to grantRead Onlyaccess to that exact subset. - Audit every custom LWC or Visualforce controller assigned to the Guest User profile to confirm it runs
with sharingand enforces FLS (such asWITH USER_MODE).
A1: Check these four places in order:
- An Apex controller running
without sharing(orinherited sharingcalled from an unshared context). Any@AuraEnabledmethod or Visualforce controller runningwithout sharingignores bothPrivateOWD and Guest User Sharing Rules. - An overly broad Guest User Sharing Rule in Setup > Sharing Settings, such as catch-all criteria like
CreatedDate != nullorName != ''that accidentally shares draft or internal rows. - An over-permissioned Guest User Profile or Permission Set with
Readturned on for sensitive objects or internal fields. - A public Screen Flow or Autolaunched Flow embedded on the site configured to run in System Context Without Sharing (Access All Data), which can query and display records regardless of guest sharing rules.
A2: Misconfigured public portals were a major source of accidental CRM data exposure. Admins often left external OWD set to Public Read/Write or let the shared Guest User own newly created records, letting anyone calling the site's APIs pull internal data.
Salesforce fixed this at the platform level with four permanent changes:
- Secure guest user record access was permanently locked on, forcing guest OWD to
Privateacross standard and custom objects. - Guest users were removed from Role Hierarchies, Public Groups, Queues, and manual sharing.
- Standard owner-based sharing rules can no longer target guests; only criteria-based, read-only Guest User Sharing Rules can grant record read access.
- Guest users lost record ownership (new records automatically route to a default internal owner) along with
Edit,Delete,View All, andModify Allobject permissions.
🧪 Self-Check Question: An admin grants Read and Create on Case to the Guest User profile for a public "Contact Us" form. Right after insert newCase; runs in a with sharing controller, the code queries [SELECT Id, CaseNumber FROM Case WHERE Id = :newCase.Id] to show the Case Number on the confirmation screen. What happens, and why?
Answer & Explanation: The query returns zero rows (or throws a List has no rows for assignment to SObject error if assigned to a single variable). Even though the Guest User just created the Case, ownership immediately transferred to the site's Default Owner on commit, and guest OWD on Case is Private. Without a Guest User Sharing Rule on Case (which you should never add for customer cases), the guest user cannot read the row back in with sharing mode.
🔗 Next Concept Follow-Up: Controlled System Operations for Guests
Answer: Use narrowly scoped elevation with explicit DTOs (Data Transfer Objects). Keep your main entry controller with sharing instead of opening a Guest User Sharing Rule on Case or making the whole controller without sharing. Delegate only the insert and immediate CaseNumber lookup to a private inner helper class marked without sharing that accepts the newly inserted Id created inside that exact same transaction (never an Id passed from the browser) and returns only the non-sensitive CaseNumber string. Because the client cannot pass an arbitrary Id into that private helper, anonymous visitors cannot use it to enumerate other customers' cases.
Comments
Questions, corrections and your own experience are all welcome.
Post a Comment