Skip to content
Back

Hidden in Plain Sight: Account Takeovers and CSP Pitfalls

Eddie Zaltsman

December 23, 2024
Share

Content Security Policy (CSP) is a fundamental security measure designed to prevent Cross-Site Scripting (XSS) and data injection attacks. However, when not implemented correctly, attackers can exploit loopholes to bypass CSP, execute malicious payloads, and compromise entire systems. This article explores an interesting CSP bypass scenario where malicious code is disguised within an image file. We'll analyze a real-world case of a number of seemingly unrelated vulnerabilities are chained together in a cunning way in order to allow for mass account takeover.

While devising this attack, one significant challenge was the inability to host the payload externally. The platform's strict CSP configuration only allowed requests to *.redacted.com, preventing outbound XHR requests to other domains. To overcome this, the payload was embedded within an image hosted on the same platform, bypassing restrictions entirely.

Another key part of this exploit was transferring the extracted user data internally. The "Chat" feature, which serves as an internal chat-like mechanism, provided a covert channel to exfiltrate data. By embedding the stolen details as comments, the attack avoided external communication entirely while still automating the account takeover process.

Step 1: Bypassing Email Verification

Email verification is a common mechanism employed to validate user registrations. However, I noticed that after signing-up, we are immediately redirected to redacted.com/register/email/<<CODE>>, and that the same code was included in the verification link enclosed in the verification email message.

Armed with this valuable piece of information, an attacker can:

1. Register an account with any email (e.g., fakeemail@example.com).

2. Exploit the verification URL: By modifying the endpoint to /details/, the verification process is completed.

This procedure allows an attacker to register an account using any email address without requiring access to incoming emails.

Step 2: Crafting the Malicious Image for CSP Bypass

The strict CSP prevented external hosting of payloads, as outbound XHR requests were only allowed to *.redacted.com. This restriction forced attackers to get creative and find some other vulnerability within the site.

To bypass CSP, the attacker can upload a file with a .jpg extension containing malicious JavaScript code. The server fails to validate its content, treating the file as an image while allowing it to be stored on the same domain.

Step 3: Triggering Malicious Code Through Stored XSS

Every user has the option to create an event in the platform. Some fields inside the event like the event location were not properly sanitized, and users that access the event page can be poisoned using a specially crafted payload.

This payload fetches and executes the disguised image script using jQuery, triggering the payload for any user who views or interacts with the event. The impact of this vulnerability is significantly amplified by an additional feature within the platform that allows the attacker to highlight the event, ensuring its visibility to any user visiting the main page.

Step 4: Automated Account Deletion

A crucial aspect of this exploit involved identifying a request capable of triggering account deletion during the exploitation process. During the assessment, it was observed that some of the account data was kept even after it was deleted. By leveraging the existing authentication bypass, it became possible to chain this vulnerability to delete an account and subsequently re-register it with access to some of the original user's data.

Step 5: Exfiltrating Data Using Internal Features

A critical part of this exploit was transferring the victim's data. Since CSP restricted outbound communication, attackers used another feature within the platform — essentially an internal comment system — to embed exfiltrated data. This approach kept the data within the domain and thus avoided triggering CSP violations.

The script automates the following:

  1. Extract Victim Data: Retrieve user id, username, and email.

  2. Send Data Internally: Use the internal comment functionality to store base64-encoded user details as comments.

  3. Automate Account Takeover: Delete the victim's account and re-register using their details.

Overview of the Full Exploit Chain

An attacker can leverage Stored XSS combined with CSP bypass to perform the following actions:

  • Mass Account Takeover: Extract sensitive user data, delete victim accounts, and re-register under their details.

  • Content Security Policy Bypass: Embed malicious scripts inside image files (.jpg) to circumvent CSP restrictions.

  • Automated Stored XSS Injection: Inject payloads into event creation fields, triggering malicious code when victims interact with events.

  • Data Exfiltration: Use platform features like comments to exfiltrate stolen data covertly.

Key Takeaways

  • Validate File Uploads: Enforce strict server-side validation to ensure only valid image formats are accepted.

  • Sanitize User Inputs: Prevent stored XSS by encoding and validating all user-provided content.

  • Monitor Internal Features: Internal communication mechanisms like chat systems can be abused for data exfiltration.

  • Strengthen Email Verification: Avoid predictable or easily bypassed verification mechanisms.

  • Protect User Information: Comply with data protection regulations regarding user information.

Conclusion

This exploitation demonstrates how CSP restrictions can be cleverly bypassed by embedding code inside image files hosted on the same domain. The inability to use external payloads due to a strict connect-src policy forced attackers to think creatively, hiding the payload "in plain sight."

Additionally, leveraging internal platform functionalities like the chat system enabled covert data transfer within the CSP boundaries. This highlights the importance of securing internal features and validating inputs rigorously.

Stored XSS, when combined with CSP misconfigurations and poor validation, enables attackers to automate account takeovers, delete critical data, and manipulate platform functionalities. Organizations must adopt rigorous input validation, enforce robust CSP policies, and monitor endpoints for anomalous behavior.

Eddie Zaltsman