A stolen token never sees the MFA prompt: a checklist for apps that hold CRM access

A post-incident checklist for third-party apps holding Salesforce OAuth tokens: inventory them, name an owner, cut scopes, limit IPs and block anything unreviewed.

Org tokens Inventory job Review Limits Block and revoke Allow-list Usage alerts runs weekly owner, scopes, last used scopes, IP ranges unused or unowned unreviewed apps blocked new app, new IP
Tokens feed an inventory and a review queue; apps get limits or get revoked, and only allow-listed apps connect.
On this page
  1. 1. List every app that holds a live token
  2. 2. Put a name in the owner column
  3. 3. Cut access to what the app does
  4. 4. Limit where the token works from
  5. 5. Block whatever hasn’t been reviewed
  6. 6. Rerun the inventory and alert on the difference
  7. Sixty-three apps, one forgotten widget

The consent screen takes about two seconds. There’s a list of permissions, an Allow button, and a rep with a demo in ten minutes. After that click the app holds a token, and nobody gets asked for a password or an MFA code again.

In August, attackers took OAuth tokens from a sales-engagement vendor’s chat integration and used them to pull data out of hundreds of Salesforce orgs. As far as the public write-ups go, no customer’s password was phished, and plenty of those orgs had MFA switched on. The tokens worked anyway, because a token is what an app holds after the login is over.

Salesforce’s MFA requirement covers people signing in through the UI. A refresh token, the long-lived credential in OAuth 2.0 that lets an app keep asking for new access tokens, lives on a vendor’s servers. In Salesforce its default policy is “valid until revoked”. Whoever holds it has the access of the user who clicked Allow until somebody revokes it, and unless the app’s policies restrict IPs, it works from any network.

In the weeks after news like that, I’d work through six steps on an org, in order, because step 5 breaks things if you skip step 1.

1. List every app that holds a live token

Setup has a page for this, Connected Apps OAuth Usage, and it’s fine for a first look. For a review I want rows I can sort and join, so I’d pull them with SOQL. One row per token, which means one per user per app:

SELECT AppName, UserId, CreatedDate, LastUsedDate, UseCount
FROM OAuthToken
ORDER BY AppName

Then the users, so each token can be matched to a person and a profile:

SELECT Id, Username, IsActive, Profile.Name, LastLoginDate
FROM User
WHERE UserType = 'Standard'

And where the token traffic comes from. OAuth logins show up in login history with their own login type:

SELECT UserId, Application, SourceIp, LoginTime, Status
FROM LoginHistory
WHERE LoginType = 'Remote Access 2.0'
AND LoginTime = LAST_N_DAYS:90
ORDER BY LoginTime DESC

Login history only goes back six months, so “unused for a year” has to come from LastUsedDate on the token.

Join the three on user ID and app name and you get the sheet, one row per app:

Column Filled from
App OAuthToken.AppName
Vendor Looked up by hand, once
Owner A named person inside the company
Scopes granted The app’s OAuth settings, or the vendor’s docs if the app isn’t installed
Scopes used Objects the app touches, from API event logs or the vendor
Users holding tokens Count of UserId, with profile names
Last used Newest LastUsedDate
IP ranges Distinct SourceIp values, checked against the vendor’s published ranges
Decision Keep, limit, or block and revoke

Some of those columns can’t be queried, and I’d keep them anyway. If nobody can fill in Owner, you have your answer about the app.

2. Put a name in the owner column

One person’s name goes here. A team alias doesn’t count. The owner is whoever gets asked “do we still use this?” and has to answer within a week. They also get the call when the vendor announces a breach.

I’d make this a hard rule: an app with no owner after two weeks goes to block and revoke. Blocking an app from the OAuth usage page ends its sessions and stops new ones. If someone turns up to complain, you’ve found the owner.

3. Cut access to what the app does

You can’t edit the scopes a vendor’s app requests. What you control is the user it runs as. A token with the full scope held by a System Administrator is the whole org. The same scope held by a dedicated integration user, with a permission set covering two objects, is two objects.

So for each kept app: move it off personal admin accounts onto its own integration user, grant that user only the objects in the “scopes used” column, and revoke the old tokens. This is slow work, and vendors’ setup guides push the other way, since “connect as an admin” produces fewer support tickets.

While you’re there, change the refresh token policy on apps that don’t need to live forever. Expiring a token that hasn’t been used for 30 or 90 days cleans up abandoned grants without anyone having to remember.

4. Limit where the token works from

Install the app in the org so it has policies you can edit, set IP relaxation to enforce IP restrictions, and put the vendor’s published ranges in the login IP ranges on the integration user’s profile. A stolen token replayed from somewhere else then fails.

This control is weaker than it sounds for some vendors. If they run on shared cloud address space and won’t commit to a range, write that in the sheet and count it against them at renewal. And expect one bad morning when a vendor adds a region without telling you.

5. Block whatever hasn’t been reviewed

Steps 1 to 4 deal with the apps you have. This one deals with the next app a well-meaning rep approves on a Tuesday afternoon.

Since September, Salesforce stops most users from authorizing connected apps that aren’t installed in the org, unless they hold the “Approve Uninstalled Connected Apps” permission. Give that permission to almost nobody. The stricter option is the org’s API Access Control setting, which lets only allow-listed connected apps reach the API at all, with users pre-authorized by profile or permission set.

Turn it on last. On day one it will stop every data loader and developer tool nobody listed. That’s its job, but I’d want the inventory finished first.

6. Rerun the inventory and alert on the difference

The sheet goes stale the day after the review. Schedule the three queries as a weekly inventory job and alert on changes: an app name that wasn’t there last week, a source IP outside the recorded ranges, a token on a kept app that has gone unused for 90 days.

Sixty-three apps, one forgotten widget

Tallowmere Robotics is invented, with numbers picked to be plausible. Its first inventory lists 63 apps with live tokens. Twenty-one haven’t been used in a year. Nine hold full access through an admin’s account for a job that reads two objects. One is a website chat widget approved by a former admin, whose user was left active because scheduled jobs ran under it. That token still worked.

The 21 stale apps are revoked, along with the widget and three more that nobody would put a name to. That leaves 38. Each has an owner and an integration user, most have IP limits, and anything unreviewed is blocked by default.

I’d expect most of the effort to go into step 3 and most of the arguments into step 5. The row I’d look for first is the widget’s: an app nobody remembers, approved by an account nobody watches.