22: FTP wildcard matching decodes server-provided filenames, enabling directory traversal
When wildcard matching is enabled, libcurl concatenated a server-provided FTP listing filename onto the wildcard path and then URL-decoded the whole string. A filename containing percent-encoded separators was decoded into a parent-directory reference, so curl silently fetched a file outside the intended directory while reporting success.
Originally disclosed on HackerOne
- Disclosed after 12 days
Summary
When CURLOPT_WILDCARDMATCH is enabled, libcurl concatenates the server-provided LIST filename directly onto the wildcard path and then URL-decodes the combined string. A filename containing percent-encoded path separators (e.g. %2e%2e%2fsecret.txt) is decoded into ../secret.txt, causing libcurl to traverse out of the intended directory and retrieve a different file. The transfer succeeds with CURLE_OK — the application has no indication it received the wrong file.
Affected versions
curl 7.21.0 through 8.21.0, plus tested 8.22.0 prerelease/development versions.
Root cause
In lib/ftp.c, wc_statemach() builds the download path by concatenating the untrusted LIST filename directly:
char *tmp_path = curl_maprintf("%s%s", wildcard->path, finfo->filename);
This combined string is then installed as ftp->path and passed to ftp_parse_url_path(), which URL-decodes the entire path via Curl_urldecode() before splitting it into directory components. A literal LIST filename %2e%2e%2fsecret.txt becomes ../secret.txt after decoding, introducing a CWD .. that escapes the wildcard directory.
Impact
On a shared FTP service, an unprivileged tenant who can create a filename in a wildcarded directory can cause a more-privileged client to silently retrieve a file outside that directory. The traversal does not bypass FTP server authentication — the victim's credentials must already authorize the read — but it breaks the application's scoping assumption about which files a wildcard transfer returns.
This is a Low severity issue: CURLOPT_WILDCARDMATCH is opt-in, and exploitation requires a shared FTP environment with specific access conditions. It is not API misuse — the URL ftp://host/shared/* is the documented usage pattern.
Reproduction
- Build an affected curl release, starting with 7.21.0, with FTP and wildcard-matching support enabled.
- Configure an FTP account that can list and retrieve files from a directory such as
/sharedand can also read a distinct target file outside it, such as/secret.txt. - Give an unprivileged test user or tenant the ability to create filenames inside
/sharedbut not to read/secret.txt. - In
/shared, create a file whose literal name contains percent-encoded traversal characters, such as%2e%2e%2fsecret.txt. - Give the literal file content that is clearly distinguishable from
/secret.txt. If the FTP listing reports file sizes and curl enforces them, make both files the same size so the result is not obscured by a partial-transfer error. - Ensure the FTP server's
LISTresponse returns the literal percent-bearing filename exactly as stored. - Create a libcurl transfer for a wildcard URL whose final component matches that filename, such as
ftp://host/shared/*. - Enable
CURLOPT_WILDCARDMATCHand authenticate using the broader-read FTP account. - Perform the transfer while recording the FTP control commands and downloaded bytes.
- Observe the vulnerable result: after listing
/shared, curl URL-decodes the matched filename into../secret.txt, issues a parent-directory change followed byRETR secret.txt, and returns the contents of/secret.txt. - Confirm that
curl_easy_perform()reports success, leaving the application unaware that the retrieved object was outside the wildcarded directory. - As a control, disable wildcard matching and directly request the literal percent-bearing filename by encoding each percent sign as
%25, for example/shared/%252e%252e%252fsecret.txt. - Confirm that the control remains in
/shared, retrieves the literal attacker-created file, and does not issue a parent-directory change. - Confirm a fix by encoding the server-provided listing filename as one opaque URL path segment before combining it with the wildcard path and reparsing it.
- Repeat the wildcard transfer and verify that curl retrieves the literal file in
/shared, never issuesCWD .., and never returns/secret.txt.
Expected result
A filename obtained from an FTP directory listing must remain one opaque filename. Percent sequences in that filename must not introduce directory components when curl retrieves the matched file.
Vulnerable result
Curl concatenates the untrusted listing filename with the wildcard path and URL-decodes the result. Encoded traversal characters become ../, causing retrieval outside the application-selected directory.
Suggested fix
Percent-encode the server-provided finfo->filename as a single opaque path segment before concatenating it with wildcard->path. At minimum, encode literal % as %25 and / as %2F so that ftp_parse_url_path() decodes it back to exactly the original filename without introducing new path components.
Impact
Summary:
On a shared FTP service, an attacker who can create filenames inside a wildcarded directory can cause a more-privileged curl client to retrieve a file outside that directory. If the application stores, processes, or exposes the returned bytes, this can disclose files accessible to the victim’s FTP account, although it does not bypass the server’s underlying permissions.
Context
curl is a command-line tool and libcurl is the library behind it. Among the many protocols libcurl speaks is FTP, and one of its optional features is wildcard matching: instead of fetching a single named file, the application can ask libcurl to list a directory and transfer every entry that matches a pattern. This is controlled by the CURLOPT_WILDCARDMATCH option, which is off by default and must be enabled explicitly by the application.
The documented usage pattern is a URL whose final component is a wildcard, for example ftp://host/shared/*. When the option is enabled, libcurl issues a directory listing, parses the returned filenames, and downloads the ones that match. The filenames in that listing come from the FTP server and are therefore untrusted input from the client's point of view.
This report describes what happens when such a server-provided filename contains percent-encoded path separators. The affected code is in lib/ftp.c, and the affected versions are curl 7.21.0 through 8.21.0; 8.22.0 prerelease and development versions were also tested.
Setup
Reproducing the issue needs a shared FTP environment with two levels of access:
- An FTP account that can list and retrieve files from a directory such as
/sharedand can also read a distinct target file outside it, such as/secret.txt. This is the more-privileged account whose credentials the victim client uses. - An unprivileged test user or tenant who can create filenames inside
/sharedbut cannot read/secret.txt. - An affected curl build, starting with 7.21.0, compiled with FTP and wildcard-matching support enabled.
- An FTP server whose
LISTresponse returns the literal percent-bearing filename exactly as stored.
The client side is a libcurl transfer with CURLOPT_WILDCARDMATCH enabled, authenticating with the broader-read account. The test records the FTP control commands and the downloaded bytes so the directory changes and the retrieved content can be inspected.
Finding it
The researcher looked at how wc_statemach() in lib/ftp.c builds the download path. The function concatenates the untrusted LIST filename directly onto the wildcard path:
char *tmp_path = curl_maprintf("%s%s", wildcard->path, finfo->filename);
The combined string is then installed as ftp->path and passed to ftp_parse_url_path(), which URL-decodes the entire path via Curl_urldecode() before splitting it into directory components. That ordering is the problem: a filename that is supposed to be one opaque name is decoded after it has been joined to the path, so percent sequences inside it can turn into path syntax. A literal LIST filename %2e%2e%2fsecret.txt becomes ../secret.txt after decoding, which introduces a CWD .. that escapes the wildcard directory.
What makes this worth reporting rather than dismissing as API misuse is that ftp://host/shared/* is the documented usage pattern. The application is using the feature as intended, and the traversal comes from data the server supplies.
Exploitation
Step 1: build an affected curl
Build an affected curl release, starting with 7.21.0, with FTP and wildcard-matching support enabled.
Step 2: configure the FTP account
Configure an FTP account that can list and retrieve files from a directory such as /shared and can also read a distinct target file outside it, such as /secret.txt.
Step 3: add the unprivileged tenant
Give an unprivileged test user or tenant the ability to create filenames inside /shared but not to read /secret.txt. This models the shared-hosting situation the issue is about: one tenant controls filenames in a directory that another, more-privileged client will later wildcard-match against.
Step 4: create the malicious filename
In /shared, create a file whose literal name contains percent-encoded traversal characters, such as %2e%2e%2fsecret.txt.
Step 5: make the content distinguishable
Give the literal file content that is clearly distinguishable from /secret.txt. If the FTP listing reports file sizes and curl enforces them, make both files the same size so the result is not obscured by a partial-transfer error.
Step 6: check the listing
Ensure the FTP server's LIST response returns the literal percent-bearing filename exactly as stored.
Step 7: build the wildcard transfer
Create a libcurl transfer for a wildcard URL whose final component matches that filename, such as ftp://host/shared/*.
Step 8: enable wildcard matching
Enable CURLOPT_WILDCARDMATCH and authenticate using the broader-read FTP account.
Step 9: record the transfer
Perform the transfer while recording the FTP control commands and downloaded bytes. The control channel is where the directory changes and the RETR command become visible.
Step 10: observe the vulnerable result
After listing /shared, curl URL-decodes the matched filename into ../secret.txt, issues a parent-directory change followed by RETR secret.txt, and returns the contents of /secret.txt. The client asked for files in /shared and received a file from outside it.
Step 11: confirm the silent success
Confirm that curl_easy_perform() reports success. The return code is CURLE_OK, so the application has no indication that it received the wrong file. Nothing in the result distinguishes the traversed transfer from a normal one.
Step 12: run the control
As a control, disable wildcard matching and directly request the literal percent-bearing filename by encoding each percent sign as %25, for example:
/shared/%252e%252e%252fsecret.txt
Step 13: check the control result
Confirm that the control remains in /shared, retrieves the literal attacker-created file, and does not issue a parent-directory change.
Step 14: apply the fix
Confirm a fix by encoding the server-provided listing filename as one opaque URL path segment before combining it with the wildcard path and reparsing it.
Step 15: verify the fix
Repeat the wildcard transfer and verify that curl retrieves the literal file in /shared, never issues CWD .., and never returns /secret.txt.
Expected versus vulnerable result
The expected behaviour is that a filename obtained from an FTP directory listing remains one opaque filename, and that percent sequences in that filename do not introduce directory components when curl retrieves the matched file.
The vulnerable behaviour is that curl concatenates the untrusted listing filename with the wildcard path and URL-decodes the result, so encoded traversal characters become ../ and cause retrieval outside the application-selected directory.
Root cause
The mistake is an ordering and trust-boundary error in wc_statemach(). The server-provided finfo->filename is treated as a path fragment rather than as a single opaque name. It is concatenated onto wildcard->path first, and only then is the whole string handed to ftp_parse_url_path(), which calls Curl_urldecode() on it and splits the decoded result into directory components. Because decoding happens after concatenation, percent sequences that arrived inside the filename are interpreted as path syntax, and %2e%2e%2f becomes a parent-directory component.
The FTP server's authentication and permissions still apply, so the traversal cannot reach anything the victim's credentials could not already read; what it breaks is the client-side assumption about which directory the transfer is scoped to. CURLOPT_WILDCARDMATCH is opt-in, and exploitation requires a shared FTP environment with specific access conditions.
Impact
On a shared FTP service, an unprivileged tenant who can create a filename in a wildcarded directory can cause a more-privileged client to silently retrieve a file outside that directory. If the application stores, processes, or exposes the returned bytes, this can disclose files accessible to the victim's FTP account.
The traversal does not bypass FTP server authentication: the victim's credentials must already authorise the read. What it breaks is the application's scoping assumption about which files a wildcard transfer returns, and the transfer succeeds with CURLE_OK, so the application has no indication it received the wrong file.
The report rates this as Low severity. It is not API misuse, since ftp://host/shared/* is the documented usage pattern.
Fix
The suggested fix is to percent-encode the server-provided finfo->filename as a single opaque path segment before concatenating it with wildcard->path. At minimum, encode literal % as %25 and / as %2F, so that ftp_parse_url_path() decodes it back to exactly the original filename without introducing new path components.
Variants to test
A positive result is a CWD .. (or equivalent parent change) on the control channel and content from outside the wildcarded directory, with curl_easy_perform() still returning CURLE_OK.
A positive result is the client receiving the literal percent-bearing name and decoding it into path components.
A positive result is a clean transfer of the out-of-scope file rather than a partial-transfer error that masks the traversal.
A positive result for the control is that it stays in /shared and returns the literal file, confirming the difference is in the wildcard path assembly.
A positive result is that curl retrieves the literal file in /shared, never issues CWD .., and never returns the out-of-scope file.
What happened, in plain words
Imagine a shared filing cabinet in an office building. Several people rent space in it, and each person can put files into their own folder. One day, someone puts a file into a shared folder whose name is deliberately confusing: it looks like a note saying "go up one floor and open the secret drawer". A more senior employee, who is allowed to look in the shared folder and also happens to have keys to the secret drawer, uses a tool that reads every file in the shared folder. The tool reads the confusing name, follows the instruction hidden in it, walks up a floor, and quietly hands back the contents of the secret drawer. The senior employee thinks they got a file from the shared folder. Nothing warns them otherwise.
That is the shape of this bug. curl is a widely used program for moving files over the internet, and libcurl is the library that other programs use to do the same thing. One of libcurl's optional features is called wildcard matching: instead of asking for one specific file, a program can ask libcurl to list a folder on a server and download everything whose name matches a pattern, such as "everything in this folder". The names in that list come from the server, and the client has to treat them with suspicion, because the server (or another user on the server) controls them.
The bug is that libcurl took a name from the server, glued it onto the folder path, and then decoded it. Decoding is the process of turning special written-out codes such as %2e back into the characters they stand for. Because the decoding happened after the gluing, a name that was supposed to be one harmless filename could turn into instructions to move to a different folder. The download still reported success, so the program using libcurl had no idea it had received the wrong file.
This is a path traversal: a class of bug where input that is supposed to name something inside a permitted area is crafted so that it points outside that area. The classic example is a web address containing ../, which in file paths means "go up one folder".
The pieces involved
Before the details, here are the main parts, explained from scratch.
- curl is a command-line program: you type a command in a terminal and it fetches or sends data over a network. libcurl is the library version of the same engine, which programmers embed inside their own applications. When an application "uses curl", it is usually using libcurl.
- FTP (File Transfer Protocol) is an older way of moving files between computers. A client connects to an FTP server, logs in with a username and password, and can then list folders and download or upload files. FTP uses two connections: a control channel, where the client sends short commands such as "change directory" and the server replies, and a data channel, where the actual file bytes travel.
- Wildcard matching is a feature where you give a pattern instead of an exact name. In a file manager,
*.txtmeans "every file ending in .txt". In libcurl, wildcard matching means: list the folder, look at each name, and download the ones that match the pattern. CURLOPT_WILDCARDMATCHis the setting (an "option") that switches wildcard matching on. It is off by default. A program has to deliberately turn it on.- Percent-encoding (also called URL encoding) is a way of writing characters that would otherwise be awkward or ambiguous in a web address. A percent sign followed by two hexadecimal digits stands for one byte. For example,
%2emeans a dot (.),%2fmeans a slash (/), and%25means a literal percent sign (%). This exists so that a filename containing a slash can be written in a URL without the slash being mistaken for a folder separator. - URL decoding is the reverse: turning
%2e%2e%2fback into../. CWDis the FTP command for "change working directory", i.e. move to another folder.CWD ..means "move up one folder".RETRis the FTP command for "retrieve", i.e. download a file.LISTis the FTP command that asks the server to send back the contents of a folder, including the filenames.CURLE_OKis the success code that libcurl returns when a transfer completes without error.curl_easy_perform()is the libcurl function that actually performs a transfer; its return value tells the program whether it worked.
Context
curl is a command-line tool and libcurl is the library behind it. Among the many protocols libcurl speaks is FTP, and one of its optional features is wildcard matching: instead of fetching a single named file, the application can ask libcurl to list a directory and transfer every entry that matches a pattern. This is controlled by the CURLOPT_WILDCARDMATCH option, which is off by default and must be enabled explicitly by the application.
The documented usage pattern is a URL whose final component is a wildcard, for example ftp://host/shared/*. When the option is enabled, libcurl issues a directory listing, parses the returned filenames, and downloads the ones that match. The filenames in that listing come from the FTP server and are therefore untrusted input from the client's point of view.
This report describes what happens when such a server-provided filename contains percent-encoded path separators. The affected code is in lib/ftp.c, and the affected versions are curl 7.21.0 through 8.21.0; 8.22.0 prerelease and development versions were also tested.
In plain terms: a program tells libcurl "download everything in /shared". libcurl asks the FTP server for the list of names in /shared. Those names are written by whoever controls the server or that folder, so they cannot be trusted. The bug appears when one of those names contains encoded slashes and dots.
Setup
Reproducing the issue needs a shared FTP environment with two levels of access:
- An FTP account that can list and retrieve files from a directory such as
/sharedand can also read a distinct target file outside it, such as/secret.txt. This is the more-privileged account whose credentials the victim client uses. - An unprivileged test user or tenant who can create filenames inside
/sharedbut cannot read/secret.txt. - An affected curl build, starting with 7.21.0, compiled with FTP and wildcard-matching support enabled.
- An FTP server whose
LISTresponse returns the literal percent-bearing filename exactly as stored.
The client side is a libcurl transfer with CURLOPT_WILDCARDMATCH enabled, authenticating with the broader-read account. The test records the FTP control commands and the downloaded bytes so the directory changes and the retrieved content can be inspected.
Why each piece is needed:
- The privileged account plays the victim. It is allowed to read both
/sharedand/secret.txt, so the server will not stop the read. The bug is not about breaking the server's login; it is about the client being tricked into asking for the wrong file. - The unprivileged tenant plays the attacker. They can only create names in
/shared. They cannot read/secret.txtthemselves. Their only power is choosing what a filename looks like. - The affected curl build is needed because the bug is present in those versions. The build must include FTP and wildcard support, otherwise the feature does not exist to be abused.
- The server that returns names verbatim matters because the client only sees the name the server sends in its listing. If the server changes the name, the client never sees the encoded slashes, and the trick does not work.
Finding it
The researcher looked at how wc_statemach() in lib/ftp.c builds the download path. The function concatenates the untrusted LIST filename directly onto the wildcard path:
char *tmp_path = curl_maprintf("%s%s", wildcard->path, finfo->filename);
Line by line:
char *tmp_pathdeclares a variable that will hold the new path string. The*means it points at text in memory.curl_maprintfis curl's own version of the classicprintfformatting function: it builds a new string from a template and some values, and allocates memory for it."%s%s"is the template. Each%sis a placeholder for a piece of text.wildcard->pathis the folder part the application asked for, for example/shared/.finfo->filenameis the name that came back from the server's listing, for example%2e%2e%2fsecret.txt.- The result is the two pieces glued together with no separator and no escaping:
/shared/%2e%2e%2fsecret.txt.
The combined string is then installed as ftp->path and passed to ftp_parse_url_path(), which URL-decodes the entire path via Curl_urldecode() before splitting it into directory components. That ordering is the problem: a filename that is supposed to be one opaque name is decoded after it has been joined to the path, so percent sequences inside it can turn into path syntax. A literal LIST filename %2e%2e%2fsecret.txt becomes ../secret.txt after decoding, which introduces a CWD .. that escapes the wildcard directory.
Think of it like writing an address on an envelope. If you write the street and the house number separately and then decode a secret code in the house number afterwards, the decoded text can change the street too.
What makes this worth reporting rather than dismissing as API misuse is that ftp://host/shared/* is the documented usage pattern. The application is using the feature as intended, and the traversal comes from data the server supplies. "API misuse" would mean the programmer did something the documentation warns against. Here the programmer followed the documentation.
Exploitation
Step 1: build an affected curl
Build an affected curl release, starting with 7.21.0, with FTP and wildcard-matching support enabled.
Why: you need a version that still contains the bug, and you need the FTP and wildcard features compiled in, otherwise there is nothing to test.
Step 2: configure the FTP account
Configure an FTP account that can list and retrieve files from a directory such as /shared and can also read a distinct target file outside it, such as /secret.txt.
Why: this account is the victim. It must be allowed to read the secret file, because the bug does not grant new permissions; it only makes the client ask for the wrong file with permissions it already has.
Step 3: add the unprivileged tenant
Give an unprivileged test user or tenant the ability to create filenames inside /shared but not to read /secret.txt. This models the shared-hosting situation the issue is about: one tenant controls filenames in a directory that another, more-privileged client will later wildcard-match against.
Why: the attacker's only lever is the filename. If they could already read the secret file, there would be nothing to demonstrate.
Step 4: create the malicious filename
In /shared, create a file whose literal name contains percent-encoded traversal characters, such as %2e%2e%2fsecret.txt.
Why: the whole trick depends on the client decoding the name later. %2e%2e%2f is the encoded form of ../, which means "up one folder".
Step 5: make the content distinguishable
Give the literal file content that is clearly distinguishable from /secret.txt. If the FTP listing reports file sizes and curl enforces them, make both files the same size so the result is not obscured by a partial-transfer error.
Why: you need to prove which file actually arrived. If both files contained the same text, you could not tell. If the sizes differ and curl checks sizes, the transfer might fail partway and hide the traversal behind an unrelated error.
Step 6: check the listing
Ensure the FTP server's LIST response returns the literal percent-bearing filename exactly as stored.
Step 7: build the wildcard transfer
Create a libcurl transfer for a wildcard URL whose final component matches that filename, such as ftp://host/shared/*.
Why: the * is the wildcard. It tells libcurl to list /shared and download everything that matches, which includes the attacker's file.
Step 8: enable wildcard matching
Enable CURLOPT_WILDCARDMATCH and authenticate using the broader-read FTP account.
Why: the feature is off by default, so it must be switched on. The login uses the victim account, because that is the account whose permissions the trick abuses.
Step 9: record the transfer
Perform the transfer while recording the FTP control commands and downloaded bytes. The control channel is where the directory changes and the RETR command become visible.
Why: the downloaded bytes show what arrived, and the control channel shows how the client got there. Seeing CWD .. followed by RETR secret.txt is direct evidence that the client walked out of /shared.
Step 10: observe the vulnerable result
After listing /shared, curl URL-decodes the matched filename into ../secret.txt, issues a parent-directory change followed by RETR secret.txt, and returns the contents of /secret.txt. The client asked for files in /shared and received a file from outside it.
Why this matters: the application's intent was "files in /shared". The result was a file from outside. The boundary the application relied on was crossed.
Step 11: confirm the silent success
Confirm that curl_easy_perform() reports success. The return code is CURLE_OK, so the application has no indication that it received the wrong file. Nothing in the result distinguishes the traversed transfer from a normal one.
Why this matters: if the transfer had failed, the application would notice. Because it succeeds, the wrong file can be stored, processed, or shown to a user as if it were a legitimate match.
Step 12: run the control
As a control, disable wildcard matching and directly request the literal percent-bearing filename by encoding each percent sign as %25, for example:
/shared/%252e%252e%252fsecret.txt
Line by line:
/shared/is the folder the file really lives in.%25decodes to a literal%.- So
%252edecodes to%2e,%252eagain to%2e, and%252fto%2f. - The whole path therefore names the file whose actual name is
%2e%2e%2fsecret.txt, inside/shared.
Why: a control is a comparison. It shows what happens when you ask for the same file directly, without wildcard matching. If that stays in /shared, then the traversal must come from the wildcard code, not from percent signs in URLs in general.
Step 13: check the control result
Confirm that the control remains in /shared, retrieves the literal attacker-created file, and does not issue a parent-directory change.
Why: this isolates the cause. The same characters, handled the normal way, are harmless. The bug is in the wildcard path assembly.
Step 14: apply the fix
Confirm a fix by encoding the server-provided listing filename as one opaque URL path segment before combining it with the wildcard path and reparsing it.
Why: "opaque" means the name is treated as a single blob of text with no special meaning. If you encode it first, then joining and decoding later gives back exactly the original name, with no new folder separators appearing.
Step 15: verify the fix
Repeat the wildcard transfer and verify that curl retrieves the literal file in /shared, never issues CWD .., and never returns /secret.txt.
Why: a fix is only proven by repeating the attack and seeing it fail in the right way. The client should still download the attacker's file, because it does match the wildcard, but it should download it from /shared and not from anywhere else.
Expected versus vulnerable result
The expected behaviour is that a filename obtained from an FTP directory listing remains one opaque filename, and that percent sequences in that filename do not introduce directory components when curl retrieves the matched file.
The vulnerable behaviour is that curl concatenates the untrusted listing filename with the wildcard path and URL-decodes the result, so encoded traversal characters become ../ and cause retrieval outside the application-selected directory.
In everyday terms: a name on a list should stay a name. It should never turn into an instruction to walk to another folder.
Root cause
The mistake is an ordering and trust-boundary error in wc_statemach(). The server-provided finfo->filename is treated as a path fragment rather than as a single opaque name. It is concatenated onto wildcard->path first, and only then is the whole string handed to ftp_parse_url_path(), which calls Curl_urldecode() on it and splits the decoded result into directory components. Because decoding happens after concatenation, percent sequences that arrived inside the filename are interpreted as path syntax, and %2e%2e%2f becomes a parent-directory component.
A trust boundary is the line between data you control and data you do not. Here the boundary is between the application (which chose /shared) and the server (which supplies filenames). Data crossing that line must be treated as untrusted. The code crossed the line in the wrong order: it mixed trusted and untrusted text, then applied a transformation that gives the untrusted part new meaning.
The FTP server's authentication and permissions still apply, so the traversal cannot reach anything the victim's credentials could not already read; what it breaks is the client-side assumption about which directory the transfer is scoped to. CURLOPT_WILDCARDMATCH is opt-in, and exploitation requires a shared FTP environment with specific access conditions.
Impact
On a shared FTP service, an unprivileged tenant who can create a filename in a wildcarded directory can cause a more-privileged client to silently retrieve a file outside that directory. If the application stores, processes, or exposes the returned bytes, this can disclose files accessible to the victim's FTP account.
Disclosure here means the wrong file's contents end up somewhere they should not: saved to disk, shown to a user, forwarded to another service, or logged.
The traversal does not bypass FTP server authentication: the victim's credentials must already authorise the read. What it breaks is the application's scoping assumption about which files a wildcard transfer returns, and the transfer succeeds with CURLE_OK, so the application has no indication it received the wrong file.
The report rates this as Low severity. It is not API misuse, since ftp://host/shared/* is the documented usage pattern.
Severity is a rough measure of how bad a bug is in practice. Low here means: the feature is off by default, and the attacker needs a shared server where they can create files and where a privileged client uses wildcard matching. That is a real but narrow situation.
Fix
The suggested fix is to percent-encode the server-provided finfo->filename as a single opaque path segment before concatenating it with wildcard->path. At minimum, encode literal % as %25 and / as %2F, so that ftp_parse_url_path() decodes it back to exactly the original filename without introducing new path components.
In plain words: before gluing the server's name onto the folder path, replace any % with %25 and any / with %2F. Then when the combined path is decoded later, those sequences turn back into the original % and / characters, and no new folder separators appear. The name stays a name.
Variants to test
A positive result is a CWD .. (or equivalent parent change) on the control channel and content from outside the wildcarded directory, with curl_easy_perform() still returning CURLE_OK.
%5c is the encoded form of a backslash (\), which is a folder separator on Windows. Testing it checks whether the same trick works with a different separator character.
A positive result is the client receiving the literal percent-bearing name and decoding it into path components.
This checks how much the bug depends on the server's behaviour. A server that sanitises names may block the attack; one that passes them through does not.
A positive result is a clean transfer of the out-of-scope file rather than a partial-transfer error that masks the traversal.
This removes a source of noise. If the sizes differ and curl checks them, the transfer might fail for an unrelated reason and hide whether the traversal happened.
A positive result for the control is that it stays in /shared and returns the literal file, confirming the difference is in the wildcard path assembly.
This is the same comparison as Step 12 and Step 13: the same characters, handled normally, do not traverse.
A positive result is that curl retrieves the literal file in /shared, never issues CWD .., and never returns the out-of-scope file.
A regression test checks that a fix works and that the old behaviour does not come back. Here it proves the encoded name is treated as one opaque segment.
Glossary
- API: a defined way for one piece of software to ask another piece of software to do something. libcurl's options and functions are its API.
- Control channel: the FTP connection that carries short commands such as
CWDandRETRand the server's replies, separate from the connection that carries file bytes. - curl: a command-line program for transferring data over networks.
- libcurl: the library version of curl, embedded inside other applications.
CURLOPT_WILDCARDMATCH: the libcurl option that turns wildcard matching on. Off by default.CURLE_OK: libcurl's success return code, meaning the transfer completed without error.curl_easy_perform(): the libcurl function that performs a transfer and returns a status code.CWD: the FTP command to change the working directory, i.e. move to another folder.RETR: the FTP command to retrieve (download) a file.LIST: the FTP command that asks the server for the contents of a folder, including filenames.- FTP: File Transfer Protocol, an older protocol for listing, downloading and uploading files on a server.
- Path traversal: a bug where crafted input makes a program access a file outside the folder it was supposed to stay in, typically using
../to go up a level. - Percent-encoding / URL encoding: writing characters as a percent sign plus two hexadecimal digits, e.g.
%2efor.,%2ffor/,%25for%. - URL decoding: turning percent-encoded sequences back into the characters they represent.
- Opaque: treated as a single blob of text with no special meaning inside it, so no part of it is interpreted as syntax.
- Trust boundary: the line between data you control and data you do not. Data from the far side must be treated as untrusted.
- Wildcard matching: downloading every file whose name matches a pattern such as
*, instead of one named file. - Severity: a rough rating of how serious a bug is in practice, often Low, Medium, High or Critical.
- Disclosure: the wrong data ending up somewhere it should not, such as being stored, shown or forwarded.
- Regression test: a test that confirms a fix works and that the old faulty behaviour does not return.
- Credentials: the username and password (or similar) used to log in to a server.
- Tenant: one customer or user sharing a server with others, each with their own limited access.