The analysis of the provided security advisory and the associated commit 17b168b11ca759a7550e1f4bbd68bbde14db7785 clearly indicates a stored XSS vulnerability in the client-side rendering of .ipynb files. The vulnerability is not in a Go function but in the inline JavaScript within the templates/repo/view_file.tmpl Go template.
The root cause is the re-rendering of server-sanitized content on the client side using the marked() JavaScript library without proper configuration for URL sanitization. The patch confirms this by:
- Upgrading the
marked.js library from version 0.8.1 to 4.3.0.
- Introducing a custom
renderer.link function that explicitly checks for and neutralizes malicious URL schemes (e.g., javascript:).
The vulnerable code is located within the success callback of a jQuery $.getJSON call, which is triggered when a user views a .ipynb file. This callback processes the notebook's markdown cells, and the line $(markdown).html(marked($(markdown).html(), {renderer: renderer})); is where the unsanitized rendering occurs. An attacker could craft a malicious .ipynb file with a javascript: link, and any user viewing this file and clicking the link would execute the script in their browser, in the context of the Gogs domain.