Summary
Bugsink's web UI contains a stored cross-site scripting vulnerability in how it renders stacktraces that have been syntax-highlighted with Pygments.
An unauthenticated attacker who can send events to a Bugsink project can inject JavaScript into stored events, which will execute in an administrator's browser when they view the crafted stacktrace, allowing actions within Bugsink to be performed with that admin's privileges.
Affected context
This vulnerability affects Bugsink instances that:
- Accept events via public DSN-based ingest endpoints (per the Sentry protocol model)
- Use the stacktrace view in the web UI, particularly when syntax highlighting is applied via Pygments
- Allow administrators or privileged users to inspect detailed stacktraces for incoming events
The issue manifests when Pygments returns more lines than were originally provided for highlighting (a known quirk with Ruby heredoc-style input), causing raw, unsanitized lines from the event to be rendered directly in the browser.
Exploit preconditions
- Attack surface: Bugsink event ingestion (DSN) endpoint and the web-based stacktrace viewer.
- Required access: Ability to submit events to a specific Bugsink project (knowing the DSN or having access to a client using it); no Bugsink account is required to inject payloads.
- Trigger point: A privileged user, typically an administrator, must open the affected event's stacktrace in the Bugsink web UI, at which point the injected JavaScript runs in their browser.
- Why exploitation is possible: When Pygments returns more lines than expected,
_pygmentize_lines()intheme/templatetags/issues.py:75-77falls back to returning raw input lines. The template logic later callsmark_safe()(lines 111-113) unconditionally, marking unescaped attacker-controlled HTML/JavaScript as safe and causing it to be rendered as active content in the browser.
Why this happens
The underlying bug is a stored cross-site scripting (XSS) issue arising from improper trust in data passed through a syntax highlighter.
The _pygmentize_lines() helper assumes Pygments will return the same number of lines it was given and, on mismatch, simply falls back to the original raw input lines. These lines are then passed into the template where mark_safe() is applied without verifying whether the data is already escaped or whether it is safe to render as HTML. Because event payloads come from external clients over the DSN ingest endpoint, this violates the principle of treating all user-supplied input as untrusted. This pattern maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where attacker-controlled content is rendered directly in the browser without appropriate escaping or sanitization.
Potential impact
- Execution of arbitrary JavaScript in the browser of an authenticated Bugsink administrator or privileged user
- Impersonation of the affected administrator within the Bugsink UI (e.g., creating, modifying, or deleting projects or settings)
- Theft of session tokens, CSRF tokens, or other sensitive browser-stored data related to Bugsink
- Modification of error data, issue states, or configuration within the Bugsink instance
- Use of the Bugsink admin's access as a pivot point for broader compromise of associated services or integrations
General mitigation guidance
Effective mitigation focuses on enforcing robust output encoding and avoiding unsafe HTML-marking primitives in views that render untrusted data:
- Treat all event and stacktrace fields as untrusted input, regardless of upstream processing by helpers like Pygments or similar libraries.
- Apply context-appropriate escaping/encoding by default when rendering stacktrace lines, ensuring that any HTML or JavaScript-like content is displayed as text rather than executed.
- Avoid unconditional use of
mark_safe()or equivalent "trust this HTML" APIs, especially for values derived from user-controlled or external input; prefer safe template auto-escaping and narrowly scoped whitelists where HTML is truly required. - Handle library quirks defensively, such as Pygments returning more lines than supplied, by explicitly validating output shapes and rejecting or re-escaping unexpected or malformed data instead of falling back to raw input.
- Reduce privilege and exposure in the admin interface, for example by ensuring that critical actions are protected by additional confirmation steps and by separating high-risk diagnostics views from high-privilege configuration actions.
How teams detect issues like this
Detection can be approached through a combination of code analysis and runtime security practices:
- Static analysis and linters: Configure rules to flag use of
mark_safe()or similar functions in templates and views, particularly where the argument originates from request data, event payloads, logs, or other untrusted sources. - Code review patterns: During peer review, look for:
- Code paths where external event data flows into rendering logic without escaping
- Fallback logic (like
_pygmentize_lines()behavior) that returns raw user input to templates - Any template tag or helper that wraps content with "safe" markers or disables auto-escaping
- Security-focused tests: Add unit and integration tests that submit crafted stacktraces (including Ruby heredoc-style payloads) and verify that the resulting UI output is correctly escaped and does not execute scripts.
- Automated scanning: Use web security scanners or browser-based test harnesses to crawl the Bugsink UI for potential reflected and stored XSS by injecting benign payload markers into events and observing rendered output.

