Sub topic 11
Common over-privilege mistakes
This chapter assumes you can create a permission set, assign it to a user, and read a basic SOQL query. It also assumes you know how a connected app issues OAuth tokens. The earlier chapters showed how to build an integration user correctly. This chapter covers how the same user ends up with more access than it needs, how to spot each mistake, and how to fix it.
Over-privilege rarely comes from one big decision. It builds up from small shortcuts: "just clone the admin profile for now", "add View All so the sync stops failing", "we'll tighten it after go-live". Each shortcut works, which is why it stays in place.
Where over-privilege comes from
An integration user's effective access is the combination of several layers. A mistake in any one layer can undo careful work in the others.
The sections below follow these layers in order.
Mistake 1: Starting from an administrator profile
The most common mistake is giving the integration the System Administrator profile, or a clone of it. It is quick, and every "insufficient access" error disappears. The cost is that the integration now holds permissions such as Modify All Data, Customize Application, Author Apex, and Manage Users. A leaked token or key can then change your org's configuration, not only read data.
Cloning does not help. A clone keeps every permission of the original until you remove each one, and you will miss some.
Start from the minimal profile instead. For API-only integrations, that is the Minimum Access - API Only Integrations profile where your org has it, or Minimum Access - Salesforce. Add capabilities only through permission sets. Profile-owned permissions are hard to audit, and they can't be reused or removed cleanly.
Mistake 2: View All Data and Modify All Data
Two system permissions override almost everything else:
- View All Data grants read access to every record of every object, and ignores sharing.
- Modify All Data grants create, edit, and delete on every record of every object.
Both bypass sharing rules and, in effect, object permissions. They are often added to fix a missing-records problem. Adding them hides the real cause, which is usually a sharing setting or a missing field permission.
The object-level equivalents are View All Records and Modify All Records. They apply to one object, so they do less damage, but they still ignore sharing for that object. Use them only when the integration truly must see every record of that object, for example a data warehouse extract of all Accounts. Grant them on that object alone, never as a general fix.
Mistake 3: Granting more CRUD than the integration uses
Object permissions come in four parts: read, create, edit, and delete. A read-only reporting feed needs only read. A sync that inserts Leads needs read and create, and probably not delete.
Delete is the permission teams most often grant without thinking. A bug that loops over the wrong records, or a stolen credential, can then destroy data. A deleted record can often be restored from the recycle bin, but only for a limited time, and cascade deletes of child records make recovery messy.
A least-privilege permission set sets each flag deliberately to false unless the integration needs it. The permission set from earlier in this tutorial shows the pattern:
<objectPermissions>
<allowCreate>false</allowCreate>
<allowDelete>false</allowDelete>
<allowEdit>false</allowEdit>
<allowRead>true</allowRead>
<modifyAllRecords>false</modifyAllRecords>
<object>Account</object>
<viewAllRecords>false</viewAllRecords>
</objectPermissions>Mistake 4: Field-level security left wide open
Object access does not mean every field. Field-level security decides which fields the user can read and edit. A common mistake is granting read and edit on every field of an object because listing the needed fields felt tedious.
Three problems follow:
- The integration can read sensitive fields it never uses, such as personal data, contract values, or internal notes.
- The integration can overwrite fields it should never touch, such as an owner, a status, or a field set by a validation process.
- Newly added fields may be exposed automatically if an automation or a broad permission set grants access to all fields.
Grant access field by field. Give read-only access to fields the integration only consumes, and give edit access only to fields it writes. Keep fields that hold sensitive data outside the integration's permission sets entirely.
Mistake 5: Ignoring the role and sharing model
Permissions say which objects and fields the user can use. Sharing says which records. Over-privilege here is quieter, because the integration user has no unusual permission. It simply sees too many records.
Watch for these causes:
- A high position in the role hierarchy. With Grant Access Using Hierarchies enabled, a user sees the records owned by users below it. An integration user placed near the top sees almost everything. Leave the role empty, or place it low and narrow.
- Open org-wide defaults. If an object is Public Read/Write, every user, including the integration, can edit every record, whatever its permission sets say.
- Ownership of many records. If the integration owns the records it creates, its role and sharing rules affect who else sees them. Check that the owner does not give broad visibility by accident.
- Broad sharing rules. A criteria-based rule that includes the integration user's role or group extends access without any permission change.
The right fix is rarely to add View All. Decide which records the integration needs, then use sharing rules or the role to provide exactly those.
Mistake 6: Accumulated permission sets and groups
Permission sets pile up. An integration starts with a read-only set. Someone adds a "temporary" set for a bug, and a second integration is later pointed at the same user. A year on, nobody knows why the user has six sets.
Permission set groups make this harder to see. A group bundles several sets, and muting permission sets inside the group can remove some permissions. If you rely on muting, confirm it actually removes what you meant it to. List the permission sets assigned to the integration user and read each one. The verification chapter's query does this:
SELECT PermissionSet.Name, PermissionSet.Label, PermissionSet.IsOwnedByProfile
FROM PermissionSetAssignment
WHERE AssigneeId = '005XXXXXXXXXXXXXXX'Then check the system-level flags across everything assigned. This query shows any assigned set or profile that carries the dangerous permissions:
SELECT Name, Profile.Name, PermissionsViewAllData, PermissionsModifyAllData,
PermissionsAuthorApex, PermissionsCustomizeApplication, PermissionsManageUsers
FROM PermissionSet
WHERE Id IN (
SELECT PermissionSetId FROM PermissionSetAssignment
WHERE AssigneeId = '005XXXXXXXXXXXXXXX'
)
AND (PermissionsViewAllData = true OR PermissionsModifyAllData = true
OR PermissionsAuthorApex = true OR PermissionsCustomizeApplication = true
OR PermissionsManageUsers = true)The query should return no rows. Any row names the set to fix. A row with a value in Profile.Name means the permission comes from the profile.
To see write access that is wider than intended, query field permissions:
SELECT SobjectType, Field, PermissionsRead, PermissionsEdit
FROM FieldPermissions
WHERE Parent.Name = 'Integration_Account_Read'
AND PermissionsEdit = trueFor a read-only integration this should also return no rows.
Mistake 7: Over-broad OAuth setup
Authentication settings can widen access even when the user's permissions are tight.
- The
fullscope. ThefullOAuth scope lets the token do everything the user can do, including through the UI. Requestapiinstead, andrefresh_tokenonly if the flow needs it. A scope can never give a token more than the user has, but it can give it more than the integration needs. - Self-authorization. If the connected app allows all users to self-authorize, any user with the client credentials can get a token. Set the policy to admin-approved users are pre-authorized, and assign the app through a permission set or profile.
- Password flows. The username-password flow keeps a password that works for logins. Prefer the JWT bearer flow with a certificate, so no one holds a password.
- A shared human account. Running the integration as a person's account gives it that person's access, and the integration stops working when the person leaves. It also makes the audit trail unreadable.
Mistake 8: No network or session limits
A user restricted to API access can still be abused if the credential leaks. Without login IP ranges, anyone with a valid key can log in from anywhere. If the integration comes from fixed addresses, restrict login to them. Remember that login IP ranges on a profile apply to the user's logins, while the connected app's IP relaxation setting decides whether IP restrictions are enforced for that app. Setting "Relax IP restrictions" on the connected app can silently cancel the limit you set on the profile. Check both.
A summary of mistakes, symptoms, and fixes
| Mistake | How to detect it | Fix |
|---|---|---|
| Admin profile or clone | Profile name, or system flags set to true | Move to a minimal profile and use permission sets |
| View All or Modify All Data | The system-flag query above | Remove it, then find the real cause of the access error |
| Delete or edit not needed | `ObjectPermissions` query | Set the flags to false |
| Every field granted | `FieldPermissions` query | Grant fields one by one |
| High role or open defaults | User role and org-wide defaults | Clear the role and narrow sharing |
| Leftover permission sets | `PermissionSetAssignment` query | Remove unused sets and review groups |
| `full` scope, self-authorization | Connected app settings | Use `api`, pre-authorize, use JWT |
| No IP limits | Profile and connected app settings | Set IP ranges and check relaxation |
Fixing a failure without over-granting
When the integration returns an error, resist the quick fix. Find out which layer is responsible:
- Read the error.
INSUFFICIENT_ACCESS_OR_READONLYandINVALID_FIELDpoint to different layers. A missing field usually means field-level security. A missing record usually means sharing. - Log in as the integration user in a sandbox, using the JWT flow shown earlier, and repeat the failing call.
- Add the single permission that fixes it, in the integration's own permission set.
- Repeat the call, and confirm that an unrelated object is still denied.
Step 4 matters. A least-privilege setup is verified by what it refuses as well as by what it allows.
Exercise
Exercise
An integration reads Account records over the API, and some Accounts are missing from its results. A colleague suggests assigning View All Data. Why is that a poor first step, and what should you check instead?
Show answer
View All Data would make the Accounts visible, but it also lets the integration read every record of every object and ignores sharing, so it hides the real cause and gives far too much access. Check which layer hides the records: the org-wide default for Account, the integration user's role and the sharing rules that apply to it, and the integration user's Read permission on the object. If the integration needs all Accounts, grant View All Records on Account only, or add a narrow sharing rule.
Exercise
You run the system-flag query against your integration user and it returns one row, with a value in the Profile.Name column. What does that tell you, and where do you fix it?
Show answer
The dangerous permission (such as Modify All Data) comes from the user's profile, not from a standalone permission set. Fix it by moving the user to a minimal profile and granting the needed access through a permission set, since changing a shared profile may affect other users.