Introduction
The Spring 21 release of Salesforce includes an update that may change the behaviour of your Apex classes that are used as controllers for Aura or Lighting Web Components. If your org was created after the Spring 18 Salesforce release, or you activated the (now retired) update
Use without sharing
for @AuraEnabled
Apex Controllers with Implicit Sharing
then by default your controllers run as without sharing, which means that they don't take into account sharing settings for the user making the request and allow access to all records.
Once Spring 21 goes live, the
Use with sharing
for @AuraEnabled
Apex Controllers with Implicit Sharing (Update, Enforced)
will be applied and this behaviour will be reversed - the default will be with sharing and access will only be allowed for records owned by, or shared with, the user making the request.
Why the Change
In a word, security. This update makes your components secure by default - if you forget to specify with sharing or without sharing, the principle of least privilege is applied and the most restrictive option is chosen.
The absence of a sharing keyword can also be considered a sharing keyword
I'm really not a fan of acts of omission driving behaviour, especially when that behaviour isn't guaranteed. Prior to the Spring 21 release, if you don't specify the type of sharing, there's no way to tell by inspecting the code itself what will happen. Anyone debugging an issue around sharing would have to know when the org was provisioned, or find out whether the earlier update had been applied, always assuming they could get access to production to find out!
Historically, one reason to omit the sharing was to allow the code to inherit the sharing from it's calling Apex. This allowed a class to execute as though :
- with sharing is defined, if called from a class defined as with sharing
- without sharing is defined, if called from a class defined as without sharing
No comments:
Post a Comment