Summary
Gogs prior to 0.14.3 contains a stored cross-site scripting flaw in the Jupyter Notebook (.ipynb) preview feature, where client-side re-rendering bypasses server-side sanitization.
An attacker can embed malicious links that regenerate unsafe schemes, and when a user clicks such a link, arbitrary JavaScript executes in the Gogs origin under typical browsing conditions.
Affected context
The vulnerability occurs in Gogs instances that support previewing Jupyter Notebook (.ipynb) files via the web interface.
It manifests when server-sanitized notebook content is subsequently re-rendered in the browser using client-side Markdown processing on elements with the .nb-markdown-cell class, without equivalent sanitization.
This is most relevant in deployments where users can upload or push notebook files to repositories and other users routinely view those files within the Gogs web UI.
Exploit preconditions
- Attack surface: Web-based notebook preview pages served by Gogs.
- Required access: Ability to create or modify a repository containing a crafted
.ipynbfile (e.g., via push, upload, or commit). - Trigger point: A victim user visits the notebook preview in the Gogs UI and clicks an attacker-controlled link inside a rendered notebook cell.
- Why exploitation is possible: Client-side Markdown rendering via
marked()on.nb-markdown-cellelements reconstructs link content without enforcing a safe URL scheme or HTML sanitization, allowing reintroduction ofjavascript:or similar payloads despite prior server-side sanitization.
Why this happens
The underlying issue is a mismatch between server-side sanitization and client-side rendering logic.
Although the .ipynb content is sanitized on the server, the frontend code uses marked() to re-render Markdown in .nb-markdown-cell elements without applying equivalent sanitization or scheme filtering.
This pattern maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where untrusted content from repository files persists and is later interpreted as active script in a user's browser.
Potential impact
- Arbitrary JavaScript execution in the context of the Gogs origin.
- Theft of session cookies or other authentication tokens associated with Gogs.
- Unauthorized actions performed on behalf of the victim (e.g., repository operations, account changes).
- Manipulation of repository content or settings visible to the victim.
- Potential lateral movement through social engineering using trusted Gogs UI.
General mitigation guidance
Mitigation typically focuses on aligning client-side rendering behavior with secure server-side sanitization and constraining what notebook content can do in the browser.
Common defensive patterns include:
- Ensuring all client-side Markdown rendering paths apply robust HTML sanitization, including filtering dangerous URL schemes such as
javascript:. - Centralizing content sanitization logic so that both server and client use the same, security-aware transformation pipeline.
- Treating repository file content as untrusted input and rendering it in a strictly inert form (e.g., using safe HTML whitelists and disabling inline event handlers).
- Limiting the privileges associated with user sessions so that compromise of one account yields minimal damage.
- Applying content security policies to reduce the impact of any script execution that might occur.
How teams detect issues like this
Effective detection combines code-level analysis with behavioral monitoring:
- Use static analysis or manual code review to flag any client-side rendering of untrusted repository content that bypasses sanitization routines, especially uses of Markdown libraries such as
marked()without safe configuration. - Define review checklists that require verification of URL scheme filtering and HTML escaping wherever links or rich text from user-controlled files are processed.
- Employ automated security testing (e.g., dynamic application security tests) to scan notebook and Markdown preview features for persistent XSS behaviors.
- Maintain policies in CI that block changes introducing new unsanitized rendering paths or relaxing existing sanitization filters.

