Summary
Gogs, a self-hosted Git service, contains a stored cross-site scripting (XSS) vulnerability in issue descriptions and comments where HTML content is sanitized but still permits data: URI schemes.
Authenticated users can craft malicious links that trigger arbitrary JavaScript execution in the browser of any user viewing the affected issue or comment, potentially leading to account compromise and session hijacking.
Affected context
This vulnerability appears in Gogs instances that:
- Allow authenticated users to create or edit issue descriptions and comments containing rich text or HTML-like content
- Rely on an HTML sanitizer that intentionally permits
data:URI schemes - Render user-supplied issue and comment content directly in other users' browsers
The risk manifests in multi-user deployments where untrusted or semi-trusted users can interact via issues and comments, such as in shared repositories, internal developer platforms, or community instances.
Exploit preconditions
- Attack surface: Web UI for viewing issues and comments in Gogs.
- Required access: Authenticated account with permission to create or edit issues or comments in a repository.
- Trigger point: A victim user visits a page rendering the malicious issue description or comment in their browser.
- Why exploitation is possible: The HTML sanitization pipeline explicitly allows
data:URIs, which can be used to embed JavaScript-bearing payloads that are executed when rendered, resulting in stored XSS.
Why this happens
The root cause is an incomplete HTML sanitization strategy that treats data: URIs as safe when processing user-supplied content for issues and comments.
By allowing data: URI schemes in sanitized links or other HTML attributes, the application unintentionally preserves a scripting vector that modern browsers can interpret in a way that leads to JavaScript execution.
This maps to CWE-79: Improper Neutralization of Input During Web Page Generation, where user-controlled input is reflected into the DOM without sufficient encoding or scheme/attribute restrictions to prevent script execution.
Potential impact
- Theft or misuse of session cookies or authentication tokens via JavaScript in the victim's browser
- Impersonation of the victim within Gogs (e.g., creating or modifying repositories, issues, or comments)
- Unauthorized actions performed on behalf of privileged users (e.g., repository admins) viewing malicious content
- Exfiltration of sensitive data visible in the Gogs UI, such as repository names, private issue content, or internal metadata
- Delivery of further client-side attacks, such as redirecting users to phishing pages or loading additional malicious scripts
General mitigation guidance
Mitigation focuses on strict output encoding and conservative HTML sanitization for all user-supplied content that is rendered in browsers.
General defensive patterns include:
- Restricting or removing support for
data:URI schemes and other risky URL schemes (e.g.,javascript:) in all sanitized attributes - Applying a robust HTML sanitizer configuration that whitelists only necessary tags and attributes, and disallows inline event handlers (e.g.,
onclick,onload) - Ensuring all user-controlled text is HTML-encoded by default, and only minimal, reviewed formatting is allowed where strictly needed
- Using Content Security Policy (CSP) with scripts restricted to trusted origins and disallowing
unsafe-inlinewhere feasible, to limit the impact of any residual XSS vector - Separating display markup from data by rendering user-supplied content through safe templating engines that escape output by default
How teams detect issues like this
High-level detection and assurance approaches include:
- Static analysis and secure code review focused on:
- HTML sanitization utilities or middleware
- Custom whitelist-based sanitizers that permit URL schemes or inline event handlers
- Views or templates that interpolate raw user input or sanitized-but-still-HTML content
- Automated scanning using dynamic application security testing (DAST) tools configured with XSS payloads targeting:
- Issue creation and editing workflows
- Comment submission and rendering endpoints
- Unit and integration tests that:
- Assert that disallowed tags, attributes, and URL schemes are stripped or safely encoded
- Validate that rendered issue/comment content does not execute injected JavaScript
- Periodic policy enforcement that:
- Prohibits direct use of raw HTML from users unless passed through a vetted sanitization library
- Requires security review for any modifications to sanitization configuration or Markdown/HTML rendering logic

