Summary
A DOM-based cross-site scripting vulnerability in Gogs allows attackers to inject HTML/JavaScript into a repository milestone name that is later rendered unsafely on the New Issue page.
When another user selects the crafted milestone while creating a new issue, the injected script executes in their browser, potentially enabling session theft, CSRF, or account takeover within the Gogs instance.
Affected context
The vulnerability occurs in Gogs' web UI when handling repository milestones on the New Issue creation page (/issues/new).
It manifests where milestone names, which can contain attacker-controlled content, are inserted into the DOM without proper sanitization or encoding.
The risk is present in deployments where users can create or modify milestones and other users routinely interact with those milestones when filing issues through a browser.
Exploit preconditions
- Attack surface: Web interface of a Gogs instance, specifically the New Issue page (
/issues/new) for repositories with milestones. - Required access: Ability to create or modify a repository milestone name (e.g., project member, collaborator, or any role permitted to manage milestones).
- Victim interaction: A separate user must visit the New Issue page and select or otherwise interact with the malicious milestone.
- Trigger point: Client-side JavaScript handlers or DOM updates that inject the milestone name into the page without proper encoding.
- Why exploitation is possible: The milestone name is treated as trusted data and is written directly into the DOM or interpreted as HTML/JavaScript, enabling code execution in the victim's browser context.
Why this happens
The root cause is improper neutralization of user-controlled data when rendering milestone names in the browser.
Instead of safely encoding the milestone name as text, the client-side logic (or templating layer that feeds it) allows raw HTML/JavaScript to be inserted into the DOM, leading to DOM-based XSS.
This maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), specifically a DOM-based variant where the unsafe behavior occurs in client-side code manipulating the document object model.
Potential impact
- Execution of arbitrary JavaScript in the victim's browser within the Gogs origin.
- Theft of session cookies or other sensitive web storage data, potentially enabling account hijacking.
- Unauthorized actions performed on behalf of the victim (e.g., creating/deleting repositories, changing settings) via CSRF-like behavior within the same origin.
- Injection of malicious content into issues, comments, or repository metadata to further spread the attack.
- Phishing overlays or UI redressing within the Gogs interface to trick users into revealing credentials or tokens.
General mitigation guidance
Effective mitigation centers on treating all milestone names and similar user-supplied fields as untrusted and ensuring they are safely handled in the browser:
- Apply strict output encoding/escaping for all user-controlled fields before inserting them into the DOM, using context-appropriate encoding (HTML, attribute, URL).
- Prefer DOM APIs that set text content (e.g.,
textContentor framework equivalents) instead of APIs that interpret HTML (e.g.,innerHTML). - Enforce a clear separation between data and code in client-side templates, ensuring that user data cannot be interpreted as script.
- Consider applying a restrictive Content Security Policy (CSP) to make XSS exploitation harder by disallowing inline scripts and only permitting trusted script sources.
- Minimize client-side string concatenation for building HTML; use templating or component frameworks that automatically escape variables by default.
How teams detect issues like this
Detection strategies can focus on both code-level and runtime signals:
- Static analysis: Configure security linters or SAST tools to flag uses of unsafe DOM APIs (e.g.,
innerHTML,outerHTML,document.write) where user-controlled data may flow into them. - Code review: During manual review, trace how milestone names and other user inputs are passed from server to client, verifying that output encoding is applied at every render point.
- Template inspection: Check client-side templates and server-rendered views for raw variable interpolation in HTML or script contexts without encoding helpers.
- Runtime monitoring: Use browser-based security testing tools or automated scanners targeting DOM-based XSS to identify dangerous sinks and confirm whether user input reaches them.
- Policy enforcement: Adopt coding guidelines that mandate context-aware encoding and restrict or ban direct use of APIs known to be XSS sinks unless explicitly justified and reviewed.

