Course contentsShow
← Security
Lesson 644 of 3,05214. Web Security - XSS and Content InjectionFree lesson

Data Exfiltration Techniques

Methods for extracting sensitive data from the DOM, local storage, and user interactions via XSS.

Data Exfiltration Techniques

What you'll learn: How attackers use XSS to silently steal sensitive data from the DOM, browser storage, and user interactions.

Once an attacker successfully injects malicious JavaScript via XSS, their next goal is often data exfiltration—stealing valuable information and sending it to a server they control. Understanding these techniques helps you defend against them.

The Core Idea

Think of XSS as a burglar who's picked your lock. Data exfiltration is what they do once inside: photograph documents, copy keys, and pocket valuables. The JavaScript you injected can access everything the victim's browser can see.

Common Exfiltration Targets

DOM-Based Data Extraction: The attacker's script reads sensitive information directly from the page—usernames, email addresses, account numbers displayed in the HTML, or hidden form fields containing CSRF tokens.

Local Storage and Session Storage: Modern web apps store data locally using localStorage and sessionStorage. Injected JavaScript can read these key-value stores to extract API keys, user preferences, or cached sensitive data.

Cookie Theft: As covered in session hijacking, document.cookie provides access to non-HttpOnly cookies. This often includes session identifiers.

User Interaction Capture: Attackers can attach event listeners to forms or input fields to capture passwords, credit card numbers, and other sensitive data as users type—even before form submission.

Sending Data Out

Once collected, data must be exfiltrated. Common methods include making HTTP requests to attacker-controlled servers (using fetch() or image tags), encoding data in URLs, or using WebSockets for real-time streaming.

Key Takeaway: XSS enables attackers to silently extract sensitive data from the DOM, browser storage, cookies, and user inputs by executing JavaScript in the victim's browser context—making proper XSS prevention critical for protecting user data.