Summary
A stored cross-site scripting (XSS) vulnerability in JupyterLab Git allows malicious JavaScript to execute when viewing commit history for renamed files.
By crafting a specially formatted filename in a Git repository, an attacker can run code in the victim's browser when they open the Git History tab and view the rename diff.
Affected context
This vulnerability appears in JupyterLab environments that use the JupyterLab Git extension between versions 0.30.0b3 and 0.53.x.
It specifically occurs when the Git History tab renders rename diffs and the PlainTextDiff.ts createHeader() method injects Git filenames directly into innerHTML without sanitization.
Any workflow where users browse commit history for renamed files in projects that may contain untrusted filenames is potentially exposed.
Exploit preconditions
- Attack surface: JupyterLab Git UI, specifically the Git History tab showing renamed files.
- Required access: Ability to create or push commits with filenames controlled by the attacker into a repository that a victim later opens in JupyterLab.
- Trigger point: Victim user opens the JupyterLab Git History tab and selects a commit containing a rename with a crafted filename so that
createHeader()renders it. - Why exploitation is possible: The component uses
innerHTMLwith unsanitized filename data, allowing attacker-controlled HTML/JavaScript to be interpreted by the browser instead of treated as plain text.
Why this happens
The underlying issue is improper neutralization of user-controlled data before inserting it into the DOM, aligning with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting).
The PlainTextDiff.ts createHeader() function uses innerHTML to render Git filenames in the rename header, assuming filenames are trustworthy.
Because Git metadata can be influenced by attackers (for example, via cloned or shared repositories), treating filenames as HTML creates an injection point where script code is executed in the context of the JupyterLab origin.
Potential impact
- Execution of arbitrary JavaScript in the victim's browser while using JupyterLab Git.
- Theft or misuse of session information and authentication tokens accessible to the page.
- Unauthorized actions in JupyterLab on behalf of the victim (e.g., manipulating files, triggering notebook executions via UI interactions).
- Exposure of sensitive project data visible in the Jupyter environment, including code, outputs, and configuration details.
- Lateral movement within the browser context, such as pivoting to other tabs or services that trust the same authentication state, where applicable.
General mitigation guidance
Effective mitigation focuses on treating all Git-derived metadata, including filenames, as untrusted and rendering it safely in the UI.
Common defensive patterns include:
- Avoiding direct use of
innerHTMLfor dynamic content; instead, use text-only DOM APIs (e.g.,textContent, text nodes, or template bindings that escape by default). - Applying robust output encoding for any content inserted into the DOM when HTML rendering is truly required, tailored to the specific context (HTML, attribute, URL, etc.).
- Centralizing HTML-escaping utilities and enforcing their usage for all user-controlled or external data paths in UI components.
- Adopting secure-by-default component patterns where templating engines or frameworks escape data automatically unless explicitly overridden.
- Minimizing the privilege of web components by limiting access to sensitive APIs and strongly separating display logic from security-relevant operations.
How teams detect issues like this
Detection can focus on both code-level patterns and runtime behavior:
- Static analysis rules that flag uses of
innerHTML,outerHTML,insertAdjacentHTML, or similar DOM sinks when fed with variables derived from external sources (e.g., Git metadata, network responses). - Code review checklists that explicitly require developers to justify any non-escaped HTML insertion and confirm proper encoding or sanitization.
- Linting and type-checking rules within the front-end codebase that discourage or forbid direct HTML injection without going through approved, safe wrappers.
- Browser-focused security testing that attempts to inject XSS payloads into fields like filenames, commit messages, and branches, verifying that rendered UI treats them as plain text.
- Integration of automated SAST/DAST tools into CI pipelines to scan for known XSS patterns and regressions in UI components.

