# CVE-2023-27534: SFTP path ~ resolving discrepancy

curl's SFTP tilde expansion treated `~2` as a home-dir prefix, so `/~2/foo` resolved to `/home/dan2/foo`, letting attackers bypass path filters.

- Payout: $480
- Severity: low
- Program: Internet Bug Bounty
- Found by: nyymi
- Disclosed: 2023-03-20
- CVE: CVE-2023-27534
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1912777
- Library page: https://bugbountylibrary.com/r/h1%3A1912777
- Tags: area:oss domain:oss impact:integrity kind:bounty platform:hackerone sev:low tech:curl technique:source-review vuln:path-traversal

**Target:** curl SFTP URL path parser (tilde expansion)
**Root cause:** Tilde handling replaced `~` whenever it was a prefix of the first path element, not only when it was the standalone first element, so `~2` expanded to `<home>2`.
**Steps:**
1. Connect to an SFTP server as user `dan` with home `/home/dan`.
2. Request URL path `/~2/foo`.
3. curl expands `~2` to `/home/dan2` and fetches `/home/dan2/foo` instead of treating `~2` literally.
**How found:** Reading the SFTP URL tilde-expansion code against the RFC draft wording; noticed the replacement applied to any first-element prefix rather than only a standalone `~`.
**Exploitation:** Attacker supplies an SFTP URL with a `~<suffix>` first path element to escape the intended home-relative path and reach sibling directories, circumventing path filtering.
**Insight:** When a spec says a token denotes home only as a standalone path element, test prefix variants like `~2`, `~user2` to catch over-broad string-prefix matching in path normalization.

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

**SFTP URL path with tilde prefix**

```
Using a path like /~2/foo when accessing a server using the user dan (with home directory /home/dan) would then quite surprisingly access the file /home/dan2/foo.
```

