Stored-XSS on wiki pages
A stored cross-site scripting vulnerability existed on GitLab wiki pages because the author URL was inserted into an anchor tag without sanitisation. An attacker could inject attributes into the link, leading to script execution when a victim viewed the wiki page.
- Triaged in 19 hours
- Fixed in 57 days
- Paid in 19 hours
- Disclosed after 6 months
Hello,
A Stored-XSS is existing on Wiki pages. It is caused by recent change in show.html.haml#L10
... "<a href='#{@page.last_version.author_url}'>".html_safe ...
author_url is defined by committed email in wiki_page_version.rb:
delegate :message, :sha, :id, :author_name, :author_email, :authored_date, to: :commit
def author_url
user = ::User.find_by_any_email(author_email)
user.nil? ? "mailto:#{author_email}" : Gitlab::UrlBuilder.build(user)
end
Since the author_urlis considered as safe, attackers may inject any DOM attributes of <a> tag.
Steps to reproduce
- Clone wiki repository of an existing project or a new one, for example:
git clone [email protected]:root/test.wiki.git - Go to inside
test.wikidirectory, then add the 3 following lines at then end of.git/configfile (if there exists[user]section in.git/config, then replace its section by the following lines):
[user]
name = anyname
email = "#' style=animation-name:blinking-dot onanimationstart=alert(document.domain) other"
- Modify/create any wiki page, for example:
echo "Hi" >> home.md - Commit the modification and push it into gitlab server
- Open the wiki page in Web browser, http://gl.local/hi/test/-/wikis/home, you should see the alert
Impact
XSS may allows attackers to perform any actions on behalf of victims at client side.
What is the current bug behavior?
author_url is not sanitized
What is the expected correct behavior?
author_url should be sanitized
Output of checks
Results of GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:env:info)
System: Ubuntu 18.04
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.7.2p137
Gem Version: 3.1.4
Bundler Version:2.1.4
Rake Version: 13.0.3
Redis Version: 5.0.9
Git Version: 2.29.0
Sidekiq Version:5.2.9
Go Version: unknown
GitLab information
Version: 13.8.0-ee
Revision: 1ae10d09692
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 12.4
URL: http://gl.local
HTTP Clone URL: http://gl.local/some-group/some-project.git
SSH Clone URL: [email protected]:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 13.15.0
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
XSS may allows attackers to perform any actions on behalf of victims at client side.
Context
GitLab wikis are backed by a separate Git repository per project (the .wiki.git repository). Users with access to a project can clone that repository, edit Markdown pages, commit and push, and the changes appear on the wiki pages served by the GitLab web application. Each wiki page has a version history, and the page view renders information about the last commit, including the author.
The report concerns a stored cross-site scripting (XSS) issue on wiki pages, rated medium with a CVSS score of 5.4, in the "Your Own GitLab Instance" asset. The researcher is yvvdwf and the report was disclosed on 13 July 2021.
Setup
The researcher worked against a self-hosted GitLab instance reachable at http://[redacted], with a project owned by root and a wiki repository at [redacted]:root/test.wiki.git. The environment information reported was:
System: Ubuntu 18.04
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.7.2p137
Gem Version: 3.1.4
Bundler Version:2.1.4
Rake Version: 13.0.3
Redis Version: 5.0.9
Git Version: 2.29.0
Sidekiq Version:5.2.9
Go Version: unknown
GitLab information
Version: 13.8.0-ee
Revision: 1ae10d09692
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 12.4
URL: http://[redacted]
HTTP Clone URL: http://[redacted]/some-group/some-project.git
SSH Clone URL: [redacted]:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 13.15.0
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
The precondition is simply the ability to push to a project's wiki repository, which is the normal way to edit wiki pages. No special role beyond that is described.
Finding it
The researcher traced the behaviour to a recent change in the wiki page view template, app/views/shared/wikis/show.html.haml, at line 10:
... "<a href='#{@page.last_version.author_url}'>".html_safe ...
The value interpolated into the href attribute is marked html_safe, so it is emitted into the page without escaping. That value, author_url, is defined in lib/gitlab/git/wiki_page_version.rb:
delegate :message, :sha, :id, :author_name, :author_email, :authored_date, to: :commit
def author_url
user = ::User.find_by_any_email(author_email)
user.nil? ? "mailto:#{author_email}" : Gitlab::UrlBuilder.build(user)
end
When no GitLab user matches the commit's author email, author_url becomes mailto: followed by the raw author email taken from the commit. Because the template treats author_url as safe, an attacker who controls the author email in a commit can inject arbitrary DOM attributes into the <a> tag, not just a URL. The researcher's summary of the bug is that author_url is not sanitised.
Exploitation
Step 1: Clone the wiki repository
git clone [redacted]:root/test.wiki.git
This gives a local working copy of the project's wiki Git repository, the same repository the web application reads page versions from.
Step 2: Set a crafted author identity in the repository config
Inside the test.wiki directory, add the following three lines at the end of .git/config (or replace the existing [user] section with them):
[user]
name = anyname
email = "#' style=animation-name:blinking-dot onanimationstart=alert(document.domain) other"
The email value is the payload. The email value is the payload. Because the email does not belong to any GitLab user, author_url falls back to mailto: plus this string, and the whole thing is rendered as html_safe. then adds a style attribute and an onanimationstart handler that runs alert(document.domain). The trailing other is filler. Because the email does not belong to any GitLab user, author_url falls back to mailto: plus this string, and the whole thing is rendered as html_safe.
Step 3: Modify or create a wiki page
echo "Hi" >> home.md
This appends a line to home.md, producing a change to commit.
Step 4: Commit and push
Commit the modification and push it to the GitLab server. The commit is authored with the identity configured in step 2, so the stored author_email carries the payload.
Step 5: Open the wiki page
http://[redacted]/hi/test/-/wikis/home
Loading the page in a browser renders the last version's author link with the injected attributes, and the onanimationstart handler fires, showing the alert. The researcher notes that the alert should appear on opening the wiki page.
Root cause
The template builds an anchor tag by string interpolation and marks the result html_safe, so the author_url value is not HTML-escaped. author_url itself is derived from commit metadata: when the commit author email does not match a GitLab user, it is embedded verbatim into a mailto: URL. Commit author identity is attacker-controlled for anyone who can push to the wiki repository, so the fallback path carries arbitrary text into an attribute context that the template has declared trusted. The report's stated bug behaviour is that author_url is not sanitised, and the expected behaviour is that it should be.
Impact
As stated in the report, XSS may allow attackers to perform any actions on behalf of victims at the client side.
Fix
The report does not describe the fix that was applied. The expected behaviour it states is that author_url should be sanitised, which would prevent commit-controlled values from being emitted as trusted markup.
Variants to test
- Try other attribute-injection contexts in the same template, for example values placed inside double-quoted attributes, where a payload would need to break out with
"rather than'. - Test whether a commit author email that does match a GitLab user still influences the rendered link, since in that branch
author_urlcomes fromGitlab::UrlBuilder.build(user)rather than the raw email. - Check other places where commit metadata (author name, email, message) is rendered with
html_safeor equivalent raw output, such as commit lists and activity views. A positive result is script execution or attribute injection from a value you control in a commit. - Try the same technique on other Git-backed features that display commit authorship, such as snippets or repository file history, looking for the same
mailto:fallback pattern.
Hunting notes
This bug hides at the boundary between Git metadata and server-rendered HTML: any field a user can set in a commit (author name, author email, committer fields, message) that later appears in a page is a candidate. During recon, look for features backed by user-pushable Git repositories, such as wikis and snippets, and for templates that mark interpolated values html_safe or otherwise bypass escaping. The signal is a code path that falls back to raw user data, here mailto:#{author_email}, combined with a template that trusts the result. The researcher demonstrated impact with a minimal, reproducible sequence: clone, set the author email, commit, push, open the page, and observe the alert, which is enough to show stored script execution against any viewer of the page.
What happened, in plain words
GitLab is a website where teams keep their code and documentation. One of its features is the wiki: a set of pages, like a small website, attached to each project. Behind the scenes, every wiki is stored in a Git repository. Git is the tool programmers use to track changes to files: you copy the repository to your computer, edit files, save a snapshot (a commit) and send it back to the server (push). GitLab then shows the latest version of each page on the web.
Every commit records who made it: a name and an email address. GitLab uses that email address to build a small link on the wiki page, the one that shows who last edited the page. The researcher found that this link was built by gluing text together and telling the page "this is safe, do not check it". Because the email address comes from the commit, and anyone who can push to the wiki can choose their own email address, a person could put special characters in the email that turn the harmless link into a small piece of code. When another user opens the wiki page, that code runs in their browser. This kind of attack is called stored cross-site scripting (XSS): the malicious content is saved on the server (stored) and later runs in the browser of whoever views the page.
The report was rated medium severity with a CVSS score of 5.4. CVSS is a standard scoring system for the seriousness of a security flaw, from 0 to 10. The researcher is yvvdwf, and the report was disclosed on 13 July 2021. It concerns the "Your Own GitLab Instance" asset, meaning a GitLab server that an organisation runs itself rather than the public gitlab.com service.
Setup
The researcher tested against a GitLab server they ran themselves, reachable at http://[redacted]. The project belonged to the user root, and its wiki repository was at [redacted]:root/test.wiki.git. The environment information reported was:
System: Ubuntu 18.04
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.7.2p137
Gem Version: 3.1.4
Bundler Version:2.1.4
Rake Version: 13.0.3
Redis Version: 5.0.9
Git Version: 2.29.0
Sidekiq Version:5.2.9
Go Version: unknown
GitLab information
Version: 13.8.0-ee
Revision: 1ae10d09692
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 12.4
URL: http://[redacted]
HTTP Clone URL: http://[redacted]/some-group/some-project.git
SSH Clone URL: [redacted]:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 13.15.0
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
This block is the output of a GitLab command that lists how the server is built. It tells us the operating system (Ubuntu 18.04), the versions of the various programs GitLab depends on (Ruby 2.7.2, Git 2.29.0, PostgreSQL 12.4 and so on), the GitLab version itself (13.8.0-ee, the enterprise edition) and the addresses used to reach it. It matters because a bug can depend on a specific version: this tells other people exactly what was tested.
The only precondition is the ability to push to a project's wiki repository, which is the normal way to edit wiki pages. No special role beyond that is described.
Finding it
The researcher traced the behaviour to a recent change in the template that draws the wiki page, a file called app/views/shared/wikis/show.html.haml, at line 10:
... "<a href='#{@page.last_version.author_url}'>".html_safe ...
A template is a file that describes what a web page should look like, with blanks filled in by the server. Here the server builds an HTML link, written <a href='...'>, and drops a value called author_url into the address part. The important part is .html_safe. .html_safe switches that protection off and says "trust this, output it exactly as it is".
The value author_url is defined in lib/gitlab/git/wiki_page_version.rb:
delegate :message, :sha, :id, :author_name, :author_email, :authored_date, to: :commit
def author_url
user = ::User.find_by_any_email(author_email)
user.nil? ? "mailto:#{author_email}" : Gitlab::UrlBuilder.build(user)
end
Line by line: the first line says that details such as the commit message, its identifier, the author's name and the author's email are read from the commit object. The author_url method then looks up a GitLab user account with that email address. If no account is found (user.nil?), it returns mailto: followed by the raw email address from the commit. If an account is found, it builds a link to that user's profile instead.
So when the commit's email does not belong to any GitLab user, the raw email text ends up in the link. Because the template treats author_url as safe, an attacker who controls the author email in a commit can inject arbitrary attributes into the <a> tag, not just a URL. Attributes are the extra settings inside an HTML tag, such as style or event handlers. The researcher's summary of the bug is that author_url is not sanitised: it is not cleaned of dangerous characters before being placed on the page.
Exploitation
Step 1: Clone the wiki repository
git clone [redacted]:root/test.wiki.git
This copies the project's wiki repository from the server to the researcher's computer. It is the same repository the web application reads page versions from, so anything pushed here becomes content on the wiki. Cloning is the first step because the attack needs to create a commit with a chosen author email, and commits are made locally before being sent to the server.
Step 2: Set a crafted author identity in the repository config
Inside the test.wiki directory, add the following three lines at the end of .git/config (or replace the existing [user] section with them):
[user]
name = anyname
email = "#' style=animation-name:blinking-dot onanimationstart=alert(document.domain) other"
The .git/config file holds settings for this local copy of the repository. The [user] section tells Git which name and email to record in new commits. The email value is the payload, the malicious text. Because the email does not belong to any GitLab user, author_url falls back to mailto: plus this string, and the whole thing is rendered as html_safe. Then it adds a style attribute and an onanimationstart handler. An event handler is a piece of JavaScript attached to an element that runs when something happens to it; here the trigger is the start of a CSS animation, which the style attribute sets up. The handler runs alert(document.domain), a pop-up showing the address of the page, which proves code is running. The trailing other is filler.
Step 3: Modify or create a wiki page
echo "Hi" >> home.md
This appends the line Hi to the file home.md, which is the wiki page called home. The point is simply to have a change to commit: a commit is needed to carry the crafted author email.
Step 4: Commit and push
Commit the modification and push it to the GitLab server. A commit is a saved snapshot of the files plus information about who made it and when. Because the identity from step 2 is configured, the commit records the payload as its author email. Pushing sends the commit to the server, where GitLab stores it and later reads it to draw the wiki page.
Step 5: Open the wiki page
http://[redacted]/hi/test/-/wikis/home
Loading this address in a browser makes GitLab render the page. The page shows the last version's author link, built with the injected attributes, and the onanimationstart handler fires, showing the alert. The researcher notes that the alert should appear on opening the wiki page.
Root cause
The template builds a link by gluing text together and marks the result html_safe, so the author_url value is not HTML-escaped. author_url itself comes from commit metadata: when the commit author email does not match a GitLab user, it is embedded verbatim into a mailto: URL. The commit author identity is controlled by anyone who can push to the wiki repository, so the fallback path carries arbitrary text into an attribute, a place the template has declared trusted. The report's stated bug behaviour is that author_url is not sanitised, and the expected behaviour is that it should be.
Impact
As stated in the report, XSS may allow attackers to perform any actions on behalf of victims at the client side. In plain terms, the code runs inside the victim's browser, so it could act on the victim's behalf on the site.
Fix
The report does not describe the fix that was applied. The expected behaviour it states is that author_url should be sanitised, which would prevent commit-controlled values from being emitted as trusted markup.
Variants to test
- Try other attribute-injection contexts in the same template, for example values placed inside double-quoted attributes, where a payload would need to break out with
"rather than'. - Test whether a commit author email that does match a GitLab user still influences the rendered link, since in that branch
author_urlcomes fromGitlab::UrlBuilder.build(user)rather than the raw email. - Check other places where commit metadata (author name, email, message) is rendered with
html_safeor equivalent raw output, such as commit lists and activity views. A positive result is script execution or attribute injection from a value you control in a commit. - Try the same technique on other Git-backed features that display commit authorship, such as snippets or repository file history, looking for the same
mailto:fallback pattern.
Hunting notes
This bug hides at the boundary between Git metadata and server-rendered HTML: any field a user can set in a commit (author name, author email, committer fields, message) that later appears in a page is a candidate. During recon, look for features backed by user-pushable Git repositories, such as wikis and snippets, and for templates that mark interpolated values html_safe or otherwise bypass escaping. The signal is a code path that falls back to raw user data, here mailto:#{author_email}, combined with a template that trusts the result. The researcher demonstrated impact with a minimal, reproducible sequence: clone, set the author email, commit, push, open the page, and observe the alert, which is enough to show stored script execution against any viewer of the page.
Glossary
- XSS (cross-site scripting): a flaw where an attacker gets their own code to run inside another user's browser on a trusted website.
- Stored XSS: XSS where the malicious content is saved on the server and runs for every user who later views the affected page.
- CVSS: a standard scoring system for the severity of a security flaw, from 0 to 10.
- Git: a tool for tracking changes to files, used to store code and wiki pages as a history of commits.
- Repository: a folder of files plus its full change history, managed by Git.
- Clone: to copy a repository from a server to your own computer.
- Commit: a saved snapshot of files together with information about who made it and when.
- Push: to send your local commits to a server.
- Commit author email: the email address recorded in a commit as belonging to the person who made it.
- Template: a file describing what a web page should look like, with blanks filled in by the server.
- HTML attribute: an extra setting inside an HTML tag, such as
styleor an event handler. - HTML escaping: turning characters such as
<and'into harmless codes so user text cannot become code. html_safe: a Ruby on Rails marker that switches off HTML escaping and outputs a value exactly as it is.- Sanitise: to clean a value of dangerous characters before using it in a page.
mailto:: a link prefix that opens an email program instead of a web page.- Event handler: a piece of JavaScript attached to an element that runs when something happens to it, such as an animation starting.
alert(): a browser function that shows a pop-up; used here to prove code is running.document.domain: the address of the current page, shown in the pop-up to prove which site the code runs on.- Payload: the malicious text an attacker inserts to trigger the flaw.
- Recon: the early phase of a security test where you look around a target for interesting features and code paths.
- Snippet: a small piece of code or text stored on GitLab, also backed by Git.