Skip to content
File upload Disclosed report Intermediate CVE-2022-24888

Control character filtering misses leading and trailing whitespace in file and folder names

The server trims filenames before checking for control characters, so files and folders with leading or trailing newline, carriage return, tab, or vertical tab characters can be created. An attacker could potentially use these names for injection if they are later inserted unfiltered into HTTP responses.

david_h1 Follow

Originally disclosed on HackerOne

Medium 4.3 View original
  • Triaged in 29 hours
  • Fixed in 4 months
  • Paid in 5 months
  • Disclosed after 6 months

Summary by the program

https://github.com/nextcloud/security-advisories/security/advisories/GHSA-w3h6-p64h-q9jp

The report

Summary:

It is possible to create files and folders that have leading and trailing \n, \r, \t, and \v characters. The server rejects files and folders that have these characters in the middle of their names, so this might be an opportunity for injection.

In lib/private/Files/Storage/Common.php, the filename is trimmed before being checked for control characters:

        556         protected function verifyPosixPath($fileName) {
        557                 $fileName = trim($fileName);
        558                 $this->scanForInvalidCharacters($fileName, "\\/");
        ...
        570         private function scanForInvalidCharacters($fileName, $invalidChars) {
        571                 foreach (str_split($invalidChars) as $char) {
        572                         if (strpos($fileName, $char) !== false) {
        573                                 throw new InvalidCharacterInPathException();
        574                         }
        575                 }
        576
        577                 $sanitizedFileName = filter_var($fileName, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
        578                 if ($sanitizedFileName !== $fileName) {
        579                         throw new InvalidCharacterInPathException();
        580                 }
        581         }

Steps To Reproduce:

  1. Create a file with an HTTP request of PUT /remote.php/webdav/%09%0a%0b%0dfile%09%0a%0b%0d...
  2. Browse to http://NEXTCLOUD_HOST/index.php/apps/files/ and notice that the file has been created.
  3. Run ls in the data directory to see that the filename contains control characters.

or,

  1. Create a folder with an HTTP request of MKCOL /remote.php/dav/files/user/%09%0a%0b%0ddir%09%0a%0b%0d...
  2. Browse to http://NEXTCLOUD_HOST/index.php/apps/files/ and notice that the folder has been created.
  3. Run ls in the data directory to see that the folder's name contains control characters.

Supporting Material/References:

  • The result of ls in the data directory: F1516406.

Impact

This may just be a hardening issue, but if the file or directory names are inserted into an HTTP response unfiltered, CRLF injection may occur.

Attachments

nextcloud-control-character-paths.png
nextcloud-control-character-paths.png From the original on HackerOne

The original report as published on HackerOne, by david_h1. 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

The filename is trimmed before the control character check, so leading and trailing control characters are removed and not detected.

Impact

This may just be a hardening issue, but if the file or directory names are inserted into an HTTP response unfiltered, CRLF injection may occur.

What the attacker needed

Access to send HTTP requests to the WebDAV endpoint

How it was found

  1. Send an HTTP PUT request to the WebDAV endpoint with a filename containing leading and trailing control characters.
  2. Browse to the files app and observe that the file was created.
  3. Run ls in the data directory to see the control characters in the filename.

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 upload a file, the server checks its name for dangerous characters. It trims the start and end before checking, so it misses control characters like newlines at the edges. This means a file with such a name can be stored, which might cause problems if the name is later shown in a web page without cleaning.

What is File upload?

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.

More from Nextcloud

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Unrestricted file upload

The lesson behind this report.

An upload feature accepts a file that the server or other users' browsers then treat as code or as something trusted.