Double linking cause XSS (but blokeced by CSP in gitlab.com)
A double-linking bug in GitLab's URL rendering allowed HTML injection, and potentially XSS, when a crafted Gemfile was previewed. On gitlab.com the XSS was blocked by CSP, but HTML and CSS injection remained possible.
- Disclosed after 3 months
Summary
URL display on Gitlab.com is currently broken.
There is a risk of XSS due to double conversion of URLs into links. However, 12.5 incorporating the fix has not yet been released and is blocked by CSP at gitlab.com.
Steps to reproduce
- Login to gitlab.com
- Create new project
- Create a file with the following contents as
Gemfile - Previe the
Gemfile - You can see in the developer tool that javascript execution has been blocked by CSP.
gem '<img/src/onerror=alert(location)>', '2'
Examples
The above code is converted to HTML as shown below and connected to XSS via the img tag.
<span class="s1">'<a href="<a href=" https:="" rubygems.org="" gems="" "="">https://rubygems.org/gems/</a><img src="" onerror="alert(location)">" rel="nofollow noreferrer noopener" target="_blank"><img/src/onerror=alert(location)>'</span>
What is the current bug behavior?
There is a problem with this MR (https://gitlab.com/gitlab-org/gitlab/merge_requests/18305/diffs) that was captured by Milestone 12.5.
The issue is here. https://gitlab.com/gitlab-org/gitlab/issues/35120
What is the expected correct behavior?
It is expected that there will be no processing that links the URL in the screen twice. Probably this MR. https://gitlab.com/gitlab-org/gitlab/merge_requests/19464
Relevant logs and/or screenshots

screenshots https://gitlab.com/gitlab-org/gitlab/blob/master/Gemfile
Output of checks
This bug only occurs on GitLab.com .
Results of GitLab environment info
The 12.5 version has not yet been released and will not occur in other environments.
Impact
Since gitlab.com is blocked by CSP, there is almost no risk as XSS. There are dangers of HTML injection and CSS injection.
If this issue is not fixed and a 12.5 release is made, XSS can occur in Gitlab CE / EE.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the URL auto-linking logic ran twice on the same text, so the HTML it inserted the first time was treated as input the second time and its escaped characters were turned back into live markup.
Impact
On gitlab.com the XSS was blocked by CSP, leaving only HTML and CSS injection; if the fix were not released, a 12.5 release could allow XSS in GitLab CE and EE.
What the attacker needed
A gitlab.com account; ability to create a project and file
The fix
The text references a merge request intended to stop the double linking, but does not state that it was deployed.
How it was found
- Log in to gitlab.com.
- Create a new project.
- Create a file named Gemfile with crafted content.
- Preview the Gemfile.
- Observe in the developer tools that JavaScript execution was blocked by CSP.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When GitLab shows a file, it turns web addresses into clickable links. A bug made it do this twice, so a specially crafted line in a file could sneak in extra HTML, including a script-like image tag. On the main GitLab site a security feature called CSP stopped the script from running, but the page could still be altered.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.