This lab examines how Salesforce Session IDs can leak through outbound messages, logs, callback payloads, or integration headers, enabling replay attacks and unauthorized API access if token hygiene controls are weak.
Executive Summary
Session IDs are bearer credentials. If they appear in outbound integration flows, browser-visible responses, debug logs, or third-party callbacks, attackers can replay them to impersonate privileged sessions.
Managed package integrations are especially sensitive because token leakage can propagate outside Salesforce trust boundaries into partner systems and observability pipelines.
Salesforce Attack Surface
Visualforce exposure: direct rendering of $Api.Session_ID in pages or scripts
Apex leakage:UserInfo.getSessionId() included in debug logs or outbound payloads
Integration headers: SessionID sent to external endpoints where storage is uncontrolled
Client-side bridging: session-bearing data passed via JavaScript, postMessage, or URL parameters
Monitoring pipelines: leaked tokens in log aggregators, error trackers, or proxy traces
Business Impact
Account impersonation: attacker reuses leaked SessionID to call Salesforce APIs
Unauthorized data access: API queries run under victim session context
Privilege abuse: admin sessions leaked through troubleshooting logic become high-value compromise paths
Compliance impact: token leakage can violate customer security and audit controls
// Vulnerable outbound pattern
HttpRequest req = new HttpRequest();
req.setEndpoint(externalEndpoint);
req.setMethod('POST');
req.setHeader('X-Session-Id', UserInfo.getSessionId()); // Token leakage to third party
Attacker retrieves leaked SessionID from UI/log/third-party trace.
Attacker replays token against Salesforce REST or Tooling APIs.
Unauthorized API activity succeeds within leaked session scope.
Testing Methodology
Source discovery: identify all uses of $Api.Session_ID and UserInfo.getSessionId()
Sink mapping: trace where token values are returned, logged, or transmitted externally
Replay validation: verify whether leaked tokens are usable in realistic API calls
Context analysis: test leakage under low-privilege and high-privilege users
Control verification: confirm masking/redaction/omission in logs and outbound telemetry
Secure Engineering Patterns
Never expose SessionID: do not return, render, or transmit raw session tokens
Tokenless integration design: use Named Credentials and OAuth scopes instead of session passthrough
Logging hygiene: redact bearer tokens and security-sensitive headers at source