SfSkills Domains Docs GitHub

Home / security / security-incident-response

security-incident-response

When to use: active or suspected Salesforce org compromise, unauthorized access investigation, attacker containment, forensic evidence collection from EventLogFile/LoginHistory, session revocation, OAuth token cleanup. NOT for general security setup, permission set design, or field-level security configuration — use admin/permission-sets-vs-profiles.

Open the skill folder on GitHub


Security Incident Response — Salesforce

Overview

This skill covers the complete lifecycle of responding to a suspected or confirmed Salesforce security incident: preserving forensic evidence, containing the attacker, eradicating persistence mechanisms, recovering to a known-good state, and verifying the attacker has been fully removed.

Salesforce incident response differs from traditional IR because evidence lives in platform objects (EventLogFile, LoginHistory, SetupAuditTrail, AuthSession), containment requires both UI and API actions, and evidence retention windows are critically short in free-tier orgs (1-day EventLogFile retention vs. 30-day with Event Monitoring add-on / Shield).

The cardinal rule: preserve evidence before containment. In free-tier orgs, beginning containment first risks permanently destroying EventLogFile records before they can be downloaded.

Key Platform Concepts

Forensic Evidence Sources

SourceRetentionLicenseWhat It Shows
EventLogFile1 day (free) / 30 days (add-on/Shield)Free tier: 7 event types only — see belowLogins, logouts, API total usage; report exports, data exports and URI/page-view detail require the add-on
LoginHistory6 monthsFreeLogin IP, geolocation, MFA used, login type, browser/client
SetupAuditTrail180 daysFreeSetup-UI config changes (not Metadata API deploys)
AuthSessionLive onlyFreeActive sessions — query and DELETE to revoke
LoginAnomaly (RTEM)Real-timeShield requiredML-scored suspicious login events

Event Monitoring Tiers

TierEventLogFile types availableRetention
Free (Enterprise / Unlimited / Performance)Exactly seven: Apex Unexpected Exception, CORS Violation Record, CSP Violation, Hostname Redirects, Login, Logout, API Total Usage1 day
Free (Developer Edition)All log types1 day
Event Monitoring add-on70+ types — adds ReportExport, DataExport, URI, LightningPageView, MetadataApiOperation and the rest30 days
ShieldAdd-on set plus Real-Time Event Monitoring (LoginAnomaly, PermissionSetAssignment, ApiAnomalyEventStore)30 days + RTEM real-time

Read the free-tier row for what it excludes, not just what it contains: URI, LightningPageView, Report, ReportExport and DataExport are all add-on-only. A responder on a free-tier org who plans the investigation around page-view or report-export evidence will burn the entire non-renewable 24-hour window querying event types the org does not have. Confirm the available set first — that is step 1 of the workflow, and it exists for this reason. Developer Edition's full log set is useful for rehearsing a runbook but is not a guide to what a production EE/UE org will actually have.

Transaction Security Policy Enforcement Actions

Policies can enforce one of four actions when a matching platform event fires:

ActionEffect
BlockPrevents the operation from completing
Two-Factor Authentication (MFA challenge)Requires step-up auth
NotificationEmails the org admin; no blocking
End SessionTerminates the user's current session

Policy configuration: Enhanced Condition Builder (no-code, available Spring '21+) or legacy Apex PolicyCondition class. Policies only apply to events fired after activation — they are not retroactive.

Session Revocation

Freezing a user in Setup does not revoke active sessions or OAuth tokens. Full containment requires:

  1. Freeze user (blocks new logins) — Setup > Users > Freeze
  2. Delete active AuthSession records via REST API or Setup > Session Management
  3. Revoke OAuth tokens — Setup > Connected Apps > OAuth Usage > Revoke All (per user), or DELETE AuthToken records via API

LoginAnomaly vs. LoginHistory

  1. Scope and license check — Identify the org's Event Monitoring tier (free / add-on / Shield). Query EventLogFile to determine which event types are available and how far back logs exist. If the org is free-tier and the incident window is >24 hours old, assess whether EventLogFile evidence has already expired.
  2. Preserve forensic evidence (before any containment) — Download all EventLogFile CSVs covering the attack window via REST API. Query and export LoginHistory, SetupAuditTrail, and AuthSession for the affected users. If Shield is active, query LoginAnomaly and ApiAnomalyEventStore. Save all exports externally before proceeding.
  3. Assess blast radius — Analyze EventLogFile (ReportExport, DataExport, ApiTotalUsage event types) to determine what records were accessed or exported. Check SetupAuditTrail for configuration changes (permission set assignments, connected app creation, profile edits). Cross-reference MetadataApiOperation events for API-based deploys.
  4. Contain the attacker — Execute in sequence: (a) freeze compromised user accounts; (b) delete active AuthSession records via REST API or Setup > Session Management; (c) revoke OAuth tokens for connected apps used by the attacker; (d) activate or tighten Transaction Security Policies to block ongoing attack vectors (e.g., Block on ReportExport or API usage above threshold).
  5. Eradicate persistence — Audit and remove: unauthorized connected apps, suspicious Apex classes/triggers installed during the window, anomalous named credentials, newly created admin/privileged users, and any permission set or profile changes that were not authorized. Restore modified Flow metadata to pre-incident versions.
  6. Recover and verify — Reset credentials for all affected accounts, rotate Named Credential secrets and OAuth client secrets for any compromised integrations, and verify data integrity for records that may have been modified. Confirm the attacker no longer has any access path by re-querying AuthSession and LoginHistory.
  7. Harden for the future — Configure a Transaction Security Policy for LoginAnomaly (if Shield is licensed) with a Notification action. Implement automated daily EventLogFile export to an external store for ongoing retention beyond the platform default. Document the incident timeline, blast radius, and remediation steps for post-incident review.

SOQL Reference Queries

LoginHistory — suspicious logins for a user in a time window

SELECT Id, UserId, LoginTime, SourceIp, LoginGeo.Country, LoginType,
       AuthenticationServiceId, Status, Browser, Platform, IsMFAEnabled
FROM LoginHistory
WHERE UserId = '005XXXXXXXXXXXXXXX'
  AND LoginTime >= 2026-01-01T00:00:00Z
  AND LoginTime <= 2026-01-10T23:59:59Z
ORDER BY LoginTime DESC

SetupAuditTrail — config changes in attack window

SELECT Id, Action, Section, Display, CreatedDate, CreatedBy.Username
FROM SetupAuditTrail
WHERE CreatedDate >= 2026-01-01T00:00:00Z
ORDER BY CreatedDate DESC
LIMIT 200

Active sessions for a user

SELECT Id, UsersId, LoginTime, LastActivityDate, SessionType, SourceIp
FROM AuthSession
WHERE UsersId = '005XXXXXXXXXXXXXXX'

EventLogFile — available event types and dates

SELECT Id, EventType, LogDate, LogFileLength, LogFileContentType
FROM EventLogFile
WHERE LogDate >= 2026-01-01T00:00:00Z
ORDER BY LogDate DESC

Recently modified Apex classes (detect metadata changes)

SELECT Id, Name, LastModifiedDate, LastModifiedBy.Username
FROM ApexClass
WHERE LastModifiedDate >= 2026-01-01T00:00:00Z
ORDER BY LastModifiedDate DESC

Official Sources Used

Dependencies

Package files