XSS Vulnerability Discovered in Sourcehut's Build Log Processing

A critical security flaw has been identified within Sourcehut, a popular platform for open-source project development. The vulnerability, discovered by security researcher `arusekk`, resides in the `ansi2html` component responsible for rendering build logs. This flaw could allow malicious actors to execute arbitrary JavaScript within a victim's browser, leading to sensitive information disclosure and potentially full account takeover.

Sourcehut, known for its minimalist and Unix-philosophy-driven approach, processes build logs generated by various CI/CD tools integrated with its platform. When a project's build process produces output containing ANSI escape codes, `ansi2html` is used to convert this raw text into HTML for display within the Sourcehut web interface. The vulnerability arises from improper sanitization of certain ANSI escape sequences, specifically those that can manipulate the terminal output or inject HTML-like tags.

The core of the exploit involves crafting a malicious build log that, when processed by `ansi2html`, injects harmful JavaScript code. This code can then be executed in the context of the user viewing the log. Imagine a build log not just showing compilation errors, but actively trying to steal your session cookies or redirect you to a phishing site. The attacker's goal would be to trick a user into viewing a specially crafted log file. If successful, the injected script could steal authentication tokens, modify project settings, or even post malicious commits on behalf of the compromised user.

Diagram illustrating the flow of a malicious build log through Sourcehut's ansi2html processing to exploit a user's browser.

Exploitation Vector: Malicious ANSI Escape Codes

The `ansi2html` tool is designed to interpret ANSI escape codes, which are special sequences of characters used to control text formatting, color, and cursor position in terminal emulators. These codes are standard in Unix-like systems and are widely used in build scripts, CI/CD output, and logging mechanisms. However, `ansi2html` failed to adequately escape or neutralize certain sequences that could be interpreted as HTML tags or JavaScript directives by the browser.

Specifically, the vulnerability lies in how `ansi2html` handles sequences that could lead to HTML injection. For instance, an attacker could embed a payload like <script>alert('XSS')</script> within a build log. If `ansi2html` does not properly escape this string before rendering it as HTML, the browser will interpret and execute the script. In a real-world attack, the script would be far more sophisticated, aiming to steal session cookies, CSRF tokens, or other sensitive data accessible within the user's Sourcehut session.

The attack requires an attacker to have the ability to influence the build logs of a project hosted on Sourcehut. This could be achieved by compromising a project's CI/CD pipeline, contributing a malicious patch that modifies build scripts, or if the attacker controls a project and intentionally inserts malicious code into its build process. Once a user navigates to view the compromised build log through the Sourcehut web interface, the injected JavaScript executes.

Impact: Account Takeover and Data Compromise

The potential impact of this cross-site scripting (XSS) vulnerability is severe. If an attacker can successfully execute JavaScript in a user's browser session on Sourcehut, they can effectively impersonate that user. This means they could:

  • Access and modify project code and settings.
  • View private repositories (if the user has access).
  • Perform actions on behalf of the user, such as pushing malicious commits or creating fraudulent issues.
  • Steal authentication tokens or cookies, granting persistent access to the user's account.
  • Use the compromised account to launch further attacks against other users or projects within the Sourcehut ecosystem.

The fact that this vulnerability allows for account takeover, rather than just defacement or minor data leakage, places it in the high-severity category. For developers and organizations relying on Sourcehut for their version control and CI/CD workflows, this presents a significant risk to their intellectual property and operational security.

Mitigation and Response

Sourcehut's development team, led by Drew DeVault, has been notified of the vulnerability. As is standard practice, they have likely been working on a patch to address the `ansi2html` sanitization issue. Users of Sourcehut are advised to remain vigilant and monitor official announcements for patch releases and security advisories.

Until a fix is deployed and applied, users can take several precautionary measures:

  • Limit exposure to untrusted logs: Be cautious when viewing build logs from projects you do not fully trust.
  • Review project CI/CD configurations: If you manage a Sourcehut project, ensure your build scripts and CI/CD pipelines are secure and do not introduce vulnerabilities.
  • Use security-hardened browsers: Employ browser extensions that enhance XSS protection.
  • Monitor account activity: Keep an eye on your Sourcehut account for any suspicious activity.

The `ansi2html` library is a common utility, and it is possible that other platforms or tools that use it for log rendering may be affected as well. Developers using `ansi2html` directly or indirectly should review its usage and ensure proper sanitization is in place for any user-controlled input that is rendered as HTML.

The Unanswered Question: Scope Beyond Sourcehut

While Sourcehut is the immediate focus, the underlying `ansi2html` library is used in numerous contexts. What remains unaddressed is the full scope of this vulnerability across the broader ecosystem. How many other platforms or tools rely on `ansi2html` without adequate input sanitization for their log rendering? Identifying and patching these instances will be crucial to preventing similar security incidents elsewhere.