# Download of file with arbitrary extension via injection into attachment header

Nextcloud Mail failed to escape quotes in the Content-Disposition filename, so an attachment named test.bat".png downloads as test.bat, enabling malware delivery.

- Payout: $125
- Severity: medium
- Program: Nextcloud
- Found by: foobar7
- Disclosed: 2021-08-11
- CVE: CVE-2021-32679
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1215263
- Library page: https://bugbountylibrary.com/r/h1%3A1215263
- Tags: area:web domain:web impact:integrity kind:bounty platform:hackerone sev:medium tech:email technique:recon vuln:file-upload

**Target:** Nextcloud Mail attachment download endpoint (/apps/mail/api/messages/{id}/attachment/{id})
**Root cause:** The attachment filename is inserted into the Content-Disposition header without escaping embedded double quotes, so a crafted filename breaks out of the quoted-string and the browser parses the trailing extension as the real filename.
**Steps:**
1. Send an email to a Nextcloud Mail-connected address with an attachment named `test.bat".png`.
2. Open the mail in Nextcloud Mail; UI shows the attachment as a benign `.png`.
3. Click the attachment download icon.
4. Observe response header `Content-Disposition: attachment; filename="test.bat".png"` and the saved file is `test.bat`.
**How found:** Researcher noticed the app displays the attachment as `.png` but the download filename differs, hypothesizing the Content-Disposition header was built by naive string concatenation without escaping quotes; confirmed by naming a file `test.bat".png` and inspecting the response header.
**Exploitation:** Attacker emails a file named `test.bat".png` (or `.vbs`/`.docm` with macros) to a victim whose mailbox is connected to Nextcloud Mail. The UI displays a benign `.png`, but on download the unescaped quote in the header causes the browser to save it as `test.bat`, which the victim may open, executing code. Also bypasses extension-based filtering by intermediate mail providers.
**Insight:** When a UI shows one filename but the download saves another, inspect the raw Content-Disposition header: embedded quotes in filenames break quoted-string parsing and let you smuggle a dangerous extension past both the app's display and upstream mail filters.

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

**Request/response showing unescaped filename in Content-Disposition**

```
GET /nextcloud/index.php/apps/mail/api/messages/26/attachment/2 HTTP/1.1
    Host: 192.168.0.101

    HTTP/1.1 200 OK
    [...]
    Content-Disposition: attachment; filename="test.bat".png"
    [...]
    Content-Type: application/octet-stream

    C:\Windows\system32\calc.exe
```

