Skip to content
Path traversal Disclosed report Intermediate CVE-2023-27534

CVE-2023-27534: SFTP path ~ resolving discrepancy

The libcurl function that resolves the tilde character in SFTP paths does not behave as documented, converting a path component like '~a..' into a home directory reference followed by a parent directory traversal. An attacker with partial path access could bypass application path filtering and reach unintended remote system locations.

nyymi Follow

Originally disclosed on HackerOne

  • Triaged in 4 days
  • Fixed in 15 days
  • Disclosed after 18 days

Summary:

libcurl Curl_getworkingpath function resolves ~ as remote users' home directory. This routine behaves in an undocumented way for sftp protocol. In particular it is said that /~/ is converted to remote user's home directory (*1), while this isn't how the function actually behaves. This can lead to unexpected final path for the sftp access, and allow an attacker with partial path access to gain access to untended remote system path locations.

Steps To Reproduce:

  1. access sftp://host/~a../other/file
  2. remote path will result as: /home/user/../other/file

It's notable that when ~a.. path component is checked for path traversal via normal unix path resolving rules, the path component is not considered accessing a parent directory, and thus will bypass path sanitization operations attempting to disallow access to parent directory. As an additional remark, in regular UNIXy world ~user/ specifies another users' home directory, which clearly is not supported by sftp. This adds to potential confusion.

Remediation

  • In Curl_getworkingpath convert ~ in sftp paths only when either /~/ or /~ (if it is the full path) is used. Reject ~<something> paths (or don't convert them).

Supporting Material/References:

  1. https://everything.curl.dev/usingcurl/scpsftp

Impact

Bypassing application implemented path filtering.

The original report as published on HackerOne, by nyymi. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the tilde-expansion routine in libcurl's SFTP path handling converts any path component beginning with '~' rather than only the documented '/~/' or '/~' forms, producing a path that contains '..' after expansion and thus evades naive traversal filters.

Impact

An attacker with partial path access could bypass application-implemented path filtering and reach unintended remote system locations.

What the attacker needed

Attacker can influence an SFTP path; application relies on path filtering

The fix

The tilde should be converted only when the path is exactly '/~' or contains '/~/', and paths of the form '~<something>' should be rejected or left unconverted.

How it was found

  1. Access an SFTP URL whose path contains a tilde-prefixed component followed by '..' and further path segments.
  2. Observe that the remote path is resolved to the home directory followed by the parent-directory traversal and the remaining segments.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you use SFTP (a way to transfer files over SSH), a path starting with a tilde usually means 'home directory'. libcurl, a common programming library, tried to expand that tilde but did so incorrectly for certain inputs. This mistake let a crafted path slip past security checks that were meant to stop people from reaching files outside an allowed folder.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More by nyymi

View all

51 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.