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

GitHub Security Lab (GHSL) Vulnerability Report: Insufficient path validation in ReceiveExternalFilesActivity.java (GHSL-2022-060)

The Owncloud Android app's ReceiveExternalFilesActivity did not properly sanitise file paths, allowing attackers to read internal storage files and write arbitrary .txt files. An attacker could exploit this to disclose sensitive app data or write files to restricted directories.

atorralba Follow

Originally disclosed on HackerOne

Bounty$50 Low 3.5 View original
  • Triaged in 6 days
  • Fixed in 5 months
  • Paid in 5 months
  • Disclosed after 6 months

The GitHub Security Lab team has identified potential security vulnerabilities in Owncloud Android app.

We are committed to working with you to help resolve these issues. In this report you will find everything you need to effectively coordinate a resolution of these issues with the GHSL team.

If at any point you have concerns or questions about this process, please do not hesitate to reach out to us at [email protected] (please include GHSL-2022-059 or GHSL-2022-060 as a reference).

If you are NOT the correct point of contact for this report, please let us know!

Summary

The Owncloud Android app handles externally-provided files in the activity ReceiveExternalFilesActivity, where potentially malicious file paths are not properly sanitized, allowing attackers to read from and write to the application's internal storage.

## Details

Access to arbitrary files in the app's internal storage fix bypass

ReceiveExternalFilesActivity handles the upload of files provided by third party components in the device. The received data can be set arbitrarily by attackers, causing some functions that handle file paths to have unexpected behavior. https://hackerone.com/reports/377107 shows how that could be exploited in the past, using the android.intent.extra.STREAM extra to force the application to upload its internal files, like com.owncloud.android_preferences.xml. To fix it, the following code was added:

ReceiveExternalFilesActivity.java:521

Java
private void prepareStreamsToUpload() {
    // --snip--

    for (Uri stream : mStreamsToUpload) {
        String streamToUpload = stream.toString();
        if (streamToUpload.contains("/data") &&
                streamToUpload.contains(getPackageName()) &&
                !streamToUpload.contains(getCacheDir().getPath())
        ) {
            finish();
        }
    }
}

This protection can be bypassed in two ways:

  • Using the path returned by getCacheDir() in the payload, e.g. "file:///data/user/0/com.owncloud.android/cache/../shared_prefs/com.owncloud.android_preferences.xml".
  • Using a content provider URI that uses the org.owncloud.files provider to access the app's internal file folder, e.g. "content://org.owncloud.files/files/owncloud/logs/owncloud.2022-07-25.log".

With those payloads, the original issue can be still exploited with the same impact.

Write of arbitrary .txt files in the app's internal storage

Additionally, there's another insufficient path validation when uploading a plain text file that allows to write arbitrary files in the app's internal storage.

When uploading a plain text file, the following code is executed, using the user-provided text at input to save the file:

ReceiveExternalFilesActivity:920

Java
private void showUploadTextDialog() {
        // --snip--
        final TextInputEditText input = dialogView.findViewById(R.id.inputFileName);
        // --snip--
        setFileNameFromIntent(alertDialog, input);
        alertDialog.setOnShowListener(dialog -> {
            Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(view -> {
                // --snip--
                } else {
                    fileName += ".txt";
                    Uri fileUri = savePlainTextToFile(fileName);
                    mStreamsToUpload.clear();
                    mStreamsToUpload.add(fileUri);
                    uploadFiles();
                }
                inputLayout.setErrorEnabled(error != null);
                inputLayout.setError(error);
            });
        });
        alertDialog.show();
    }

By reviewing savePlainTextToFile, it can be seen that the plain text file is momentarily saved in the app's cache, but the destination path is built using the user-provided fileName:

ReceiveExternalFilesActivity:983

Java
private Uri savePlainTextToFile(String fileName) {
    Uri uri = null;
    String content = getIntent().getStringExtra(Intent.EXTRA_TEXT);
    try {
        File tmpFile = new File(getCacheDir(), fileName); // here
        FileOutputStream outputStream = new FileOutputStream(tmpFile);
        outputStream.write(content.getBytes());
        outputStream.close();
        uri = Uri.fromFile(tmpFile);

    } catch (IOException e) {
        Timber.w(e, "Failed to create temp file for uploading plain text: %s", e.getMessage());
    }
    return uri;
}

An attacker can exploit this using a path traversal attack to write arbitrary text files into the app's internal storage or other restricted directories accessible by it. The only restriction is that the file will always have the .txt extension, limiting the impact.

Remediation

Validate user input before using it to construct a file path. Ideally, follow these rules:

  • Do not allow more than a single . character.
  • Do not allow directory separators such as / or \ (depending on the file system).
  • Do not rely on simply replacing problematic sequences such as ../. For example, after applying this filter to

.../...// the resulting string would still be ../.

  • Ideally use an allowlist of known good patterns.

Resources

The following PoC demonstrates how to upload arbitrary files from the app's internal storage:

adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --eu "android.intent.extra.STREAM" "file:///data/user/0/com.owncloud.android.debug/cache/../shared_prefs/com.owncloud.android.debug_preferences.xml"

The following PoC demonstrates how to upload arbitrary files from the app's internal files directory:

adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --eu "android.intent.extra.STREAM" "content://org.owncloud.files/files/owncloud/logs/owncloud.2022-07-25.log"

The following PoC demonstrates how to write an arbitrary test.txt text file to the app's internal storage:

adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --es "android.intent.extra.TEXT" "Arbitrary contents here" --es "android.intent.extra.TITLE" "../shared_prefs/test"

GitHub Security Advisories

We recommend you create a private GitHub Security Advisory for these findings. This also allows you to invite the GHSL team to collaborate and further discuss these findings in private before they are published.

Credit

These issues were discovered and reported by the CodeQL team member @atorralba (Tony Torralba).

Contact

You can contact the GHSL team at [email protected], please include a reference to GHSL-2022-059 or GHSL-2022-060 in any communication regarding these issues.

Disclosure Policy

This report is subject to our coordinated disclosure policy.

Impact

These issues may lead to information disclosure when uploading the app's internal files, and to arbitrary file write when uploading plain text files (although limited by the .txt extension).

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

The target is the ownCloud Android app, package com.owncloud.android. The feature in scope is the activity ReceiveExternalFilesActivity, which handles files that other components on the device send to the app for upload. When a third-party app or the user shares a file with ownCloud, this activity receives the intent, collects the file URIs, and uploads them to the account.

Because the received data can be set arbitrarily by whoever sends the intent, any file path that the activity later uses is attacker-controlled. The GitHub Security Lab team identified two problems in how those paths are validated: a bypass of an earlier fix for reading internal files, and a separate path traversal when saving a plain text upload. The report is GHSL-2022-060, filed against ownCloud on HackerOne, rated low severity with a CVSS score of 3.5 and a 50 USD bounty, and disclosed on 16 January 2023.

Setup

The report does not describe any account, role or tooling setup. The only precondition that matters is the ability to send an intent to ReceiveExternalFilesActivity, which the proof-of-concept commands do through adb shell am start against the debug build of the app. The PoCs target com.owncloud.android.debug, so the package name in the payloads differs from the production package.

Finding it

The starting point is a previously reported issue, hackerone.com/reports/377107, which showed that the android.intent.extra.STREAM extra could be used to force the app to upload its own internal files, such as com.owncloud.android_preferences.xml. To close that, the following check was added to prepareStreamsToUpload in ReceiveExternalFilesActivity.java:

Java
private void prepareStreamsToUpload() {
    // --snip--

    for (Uri stream : mStreamsToUpload) {
        String streamToUpload = stream.toString();
        if (streamToUpload.contains("/data") &&
                streamToUpload.contains(getPackageName()) &&
                !streamToUpload.contains(getCacheDir().getPath())
        ) {
            finish();
        }
    }
}

The check rejects a stream URI only when it contains /data, contains the package name, and does not contain the cache directory path. That is a string-matching filter rather than a path resolution, and the researcher found two ways around it. Separately, while reviewing the plain text upload flow, the researcher noticed that the destination file name is taken from user input and joined to the cache directory without validation.

Exploitation

Step 1: read internal files through the cache directory

The first bypass puts the cache directory path into the payload so the third condition of the check fails, while the .. segment walks back out of the cache into shared_prefs:

Text
file:///data/user/0/com.owncloud.android/cache/../shared_prefs/com.owncloud.android_preferences.xml

The URI contains /data and the package name, but it also contains the cache directory path, so the guard does not call finish() and the file is uploaded. The .. component resolves the path to the preferences file in the app's private storage.

Step 2: read internal files through the app's content provider

The second bypass avoids the /data string entirely by using the app's own org.owncloud.files provider, which exposes the internal files folder:

Text
content://org.owncloud.files/files/owncloud/logs/owncloud.2022-07-25.log

Because the URI does not contain /data, the guard never triggers, and the provider resolves the path into the app's internal files directory. With either payload, the original issue can still be exploited with the same impact.

Step 3: upload an internal file with adb

The report provides a PoC that drives the first bypass end to end against the debug build:

Text
adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --eu "android.intent.extra.STREAM" "file:///data/user/0/com.owncloud.android.debug/cache/../shared_prefs/com.owncloud.android.debug_preferences.xml"

This starts ReceiveExternalFilesActivity with a SEND action and a text/plain type, and passes the traversing file:// URI as the android.intent.extra.STREAM extra. The activity treats it as a file to upload, and the guard is satisfied because the cache path is present in the string.

Step 4: upload from the internal files directory with adb

The second PoC uses the content provider URI instead:

Text
adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --eu "android.intent.extra.STREAM" "content://org.owncloud.files/files/owncloud/logs/owncloud.2022-07-25.log"

Here the stream extra is a content:// URI served by the app's own provider, pointing at a log file under the internal files directory. The /data check does not match, so the upload proceeds.

Step 5: write an arbitrary .txt file

The plain text upload path has a second, independent flaw. When the user uploads a plain text file, showUploadTextDialog takes the text from the intent and appends .txt to the user-provided file name before calling savePlainTextToFile:

Java
private void showUploadTextDialog() {
        // --snip--
        final TextInputEditText input = dialogView.findViewById(R.id.inputFileName);
        // --snip--
        setFileNameFromIntent(alertDialog, input);
        alertDialog.setOnShowListener(dialog -> {
            Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(view -> {
                // --snip--
                } else {
                    fileName += ".txt";
                    Uri fileUri = savePlainTextToFile(fileName);
                    mStreamsToUpload.clear();
                    mStreamsToUpload.add(fileUri);
                    uploadFiles();
                }
                inputLayout.setErrorEnabled(error != null);
                inputLayout.setError(error);
            });
        });
        alertDialog.show();
    }

savePlainTextToFile then builds the destination with new File(getCacheDir(), fileName), where fileName is still the attacker-controlled string:

Java
private Uri savePlainTextToFile(String fileName) {
    Uri uri = null;
    String content = getIntent().getStringExtra(Intent.EXTRA_TEXT);
    try {
        File tmpFile = new File(getCacheDir(), fileName); // here
        FileOutputStream outputStream = new FileOutputStream(tmpFile);
        outputStream.write(content.getBytes());
        outputStream.close();
        uri = Uri.fromFile(tmpFile);

    } catch (IOException e) {
        Timber.w(e, "Failed to create temp file for uploading plain text: %s", e.getMessage());
    }
    return uri;
}

A .. sequence in the file name escapes the cache directory. The following PoC writes test.txt into shared_prefs with the contents supplied in android.intent.extra.TEXT:

Text
adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --es "android.intent.extra.TEXT" "Arbitrary contents here" --es "android.intent.extra.TITLE" "../shared_prefs/test"

The PoC supplies the contents in android.intent.extra.TEXT and the traversing name in android.intent.extra.TITLE, and the .txt suffix is appended by the activity. The result is a file at ../shared_prefs/test.txt relative to the cache directory, inside the app's private storage. The only restriction is that the written file always carries the .txt extension, which limits the impact.

Root cause

The stream guard is a substring check on the URI string rather than a canonical path check. It can be satisfied by including the cache directory path anywhere in the URI, and it can be avoided entirely by using a URI scheme that does not contain /data, such as the app's own content provider. Neither case resolves the path before deciding whether it is inside the app's private storage.

The plain text flow trusts the file name from the intent and concatenates it to the cache directory without rejecting directory separators or .. sequences. The report's remediation notes that simply replacing ../ is not enough, because filtering .../...// still leaves ../ behind after the replacement.

Impact

The read side leads to information disclosure: an attacker who can send an intent to the activity can cause the app to upload its internal files, including preferences and logs. The write side allows arbitrary file write inside the app's internal storage or other restricted directories the app can reach, limited to files with a .txt extension. The report rates the overall severity as low.

Fix

The report recommends validating user input before using it to construct a file path, with these rules:

  1. Do not allow more than a single . character.
  2. Do not allow directory separators such as / or \, depending on the file system.
  3. Do not rely on simply replacing problematic sequences such as ../, since filtering .../...// still yields ../.
  4. Ideally, use an allowlist of known good patterns.

The report does not state which changes ownCloud ultimately made.

Variants to test

  1. Cache-path bypass on other apps. Send a stream URI that contains the app's cache directory followed by ../ and a path into shared_prefs or databases. A positive result is the app uploading a file from its private storage.
  2. Own content provider URIs. Look for exported providers in the app's manifest and pass a content:// URI pointing into the app's internal files directory. A positive result is the file being read and uploaded without the /data guard firing.
  3. File name traversal in save flows. Wherever an app writes a user-supplied name under a fixed directory, try ../ sequences in the name. A positive result is a file appearing outside the intended directory.
  4. Filter evasion. If a filter strips ../, try nested sequences such as .../...// and check whether the result still resolves to a parent directory.

Hunting notes

This class of bug tends to hide in activities that accept intents from other apps, especially share and send handlers that take file URIs or file names from extras. During recon, look for exported activities with SEND or VIEW intent filters, and for content providers declared in the manifest. String-based path checks such as contains("/data") are a strong signal that canonicalisation is missing. The report provides concrete adb commands that target an internal file for upload and a traversing name for the plain text write, covering both the read and the write paths.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

The ownCloud Android app is a mobile app that lets you store and sync your files on your own server. One of its features is that other apps on your phone can share a file with ownCloud, and ownCloud will upload it to your account. The part of the app that receives those shared files is called ReceiveExternalFilesActivity.

When another app shares a file, it sends a small message to ownCloud. On Android, that message is called an intent. An intent is like a sealed envelope handed from one app to another: it says what the sender wants to do (for example "send this file") and carries some extra pieces of data, called extras. The problem is that whoever sends the intent decides what goes inside it. The sender can put any text they like into those extras, including file paths that point at places they should not be able to reach.

A file path is the address of a file on the device, like a street address for data. On Android, each app has its own private storage area that other apps are not supposed to read or write. If an app takes a path from an outside sender and uses it without checking it carefully, the sender can point that path at the app's private files.

The GitHub Security Lab team found two problems in how the app checked those paths:

  1. An earlier fix that was supposed to stop the app from uploading its own private files could be bypassed in two different ways.
  2. A separate flaw in the plain text upload feature let an attacker write files into the app's private storage.

The report is GHSL-2022-060, filed against ownCloud on HackerOne. It was rated low severity with a CVSS score of 3.5, carried a 50 USD bounty, and was disclosed on 16 January 2023.

Setup

The report does not describe any account, role or tooling setup. The only thing that matters is being able to send an intent to ReceiveExternalFilesActivity. The proof-of-concept commands do this with adb shell am start, which is a command-line tool used to talk to an Android device from a computer. The commands target the debug build of the app, whose package name is com.owncloud.android.debug, so the package name in the payloads differs from the production package.

Finding it

The story starts with an older report, hackerone.com/reports/377107. That report showed that the android.intent.extra.STREAM extra could be used to force the app to upload its own internal files, such as com.owncloud.android_preferences.xml. The STREAM extra is simply a slot in the intent where the sender puts the location of the file they want to share.

To close that hole, the developers added a check to prepareStreamsToUpload in ReceiveExternalFilesActivity.java:

Java
private void prepareStreamsToUpload() {
    // --snip--

    for (Uri stream : mStreamsToUpload) {
        String streamToUpload = stream.toString();
        if (streamToUpload.contains("/data") &&
                streamToUpload.contains(getPackageName()) &&
                !streamToUpload.contains(getCacheDir().getPath())
        ) {
            finish();
        }
    }
}

Line by line:

  • private void prepareStreamsToUpload() { starts a method, a named block of code that does one job. This one prepares the list of files to upload.
  • for (Uri stream : mStreamsToUpload) { loops over every file location (each one a Uri, which is a way of writing a file address) that the app has collected.
  • String streamToUpload = stream.toString(); turns that address into plain text so it can be inspected as a string.
  • if (streamToUpload.contains("/data") && checks whether the text contains the characters /data. The && means "and", so all the conditions must be true together.
  • streamToUpload.contains(getPackageName()) && checks whether the text contains the app's package name, which is its unique identifier on the device.
  • !streamToUpload.contains(getCacheDir().getPath()) checks that the text does not contain the path of the app's cache directory. The ! means "not". The cache directory is a scratch area where apps keep temporary files.
  • ) { closes the condition.
  • finish(); closes the activity, refusing the upload.
  • The closing braces end the loop and the method.

The check rejects a stream only when the text contains /data, contains the package name, and does not contain the cache directory path. That is a text-matching filter, not a real check of where the file actually lives. The researcher found two ways around it. Separately, while reviewing the plain text upload flow, the researcher noticed that the destination file name is taken from user input and joined to the cache directory without any validation.

Exploitation

Step 1: read internal files through the cache directory

The first bypass puts the cache directory path into the payload so the third condition of the check fails, while the .. segment walks back out of the cache into shared_prefs:

Text
file:///data/user/0/com.owncloud.android/cache/../shared_prefs/com.owncloud.android_preferences.xml

This is a URI, a standard way of writing the address of a file or resource. The file:// part says it is a file on the device. The rest is the path. The .. segment is the key: in file paths, .. means "go up one folder", just like clicking the parent folder in a file browser. So the path starts in the cache folder, goes up one level, and then down into shared_prefs, where the app keeps its preferences.

The URI contains /data and the package name, but it also contains the cache directory path, so the guard does not call finish() and the file is uploaded. The .. component resolves the path to the preferences file in the app's private storage.

Step 2: read internal files through the app's content provider

The second bypass avoids the /data string entirely by using the app's own org.owncloud.files provider, which exposes the internal files folder:

Text
content://org.owncloud.files/files/owncloud/logs/owncloud.2022-07-25.log

A content provider is an Android component that lets one app offer data to other apps through a standard address, written with the content:// prefix. Here the provider belongs to ownCloud itself and serves files from its internal files folder. Because the URI does not contain /data, the guard never triggers, and the provider resolves the path into the app's internal files directory. With either payload, the original issue can still be exploited with the same impact.

Step 3: upload an internal file with adb

The report provides a PoC that drives the first bypass end to end against the debug build:

Text
adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --eu "android.intent.extra.STREAM" "file:///data/user/0/com.owncloud.android.debug/cache/../shared_prefs/com.owncloud.android.debug_preferences.xml"

Line by line:

  • adb shell opens a command shell on the connected Android device from your computer.
  • am start is the Android activity manager command that starts an activity.
  • -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity names the exact activity to start: the debug build of ownCloud and its file-receiving screen.
  • -t "text/plain" sets the type of the data to plain text.
  • -a "android.intent.action.SEND" sets the action, which tells the app "someone wants to send you something".
  • --eu "android.intent.extra.STREAM" "file:///..." adds an extra of type URI (eu means extra URI) named android.intent.extra.STREAM, holding the traversing file address.

This starts ReceiveExternalFilesActivity with a SEND action and a text/plain type, and passes the traversing file:// URI as the android.intent.extra.STREAM extra. The activity treats it as a file to upload, and the guard is satisfied because the cache path is present in the string.

Step 4: upload from the internal files directory with adb

The second PoC uses the content provider URI instead:

Text
adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --eu "android.intent.extra.STREAM" "content://org.owncloud.files/files/owncloud/logs/owncloud.2022-07-25.log"

The command has the same shape as the previous one. The difference is the value of the STREAM extra: here it is a content:// URI served by the app's own provider, pointing at a log file under the internal files directory. The /data check does not match, so the upload proceeds.

Step 5: write an arbitrary .txt file

The plain text upload path has a second, independent flaw. When the user uploads a plain text file, showUploadTextDialog takes the text from the intent and appends .txt to the user-provided file name before calling savePlainTextToFile:

Java
private void showUploadTextDialog() {
        // --snip--
        final TextInputEditText input = dialogView.findViewById(R.id.inputFileName);
        // --snip--
        setFileNameFromIntent(alertDialog, input);
        alertDialog.setOnShowListener(dialog -> {
            Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(view -> {
                // --snip--
                } else {
                    fileName += ".txt";
                    Uri fileUri = savePlainTextToFile(fileName);
                    mStreamsToUpload.clear();
                    mStreamsToUpload.add(fileUri);
                    uploadFiles();
                }
                inputLayout.setErrorEnabled(error != null);
                inputLayout.setError(error);
            });
        });
        alertDialog.show();
    }

Line by line:

  • private void showUploadTextDialog() { starts the method that shows the dialog for uploading text.
  • final TextInputEditText input = dialogView.findViewById(R.id.inputFileName); finds the text box in the dialog where the file name is shown.
  • setFileNameFromIntent(alertDialog, input); fills that box with a file name taken from the incoming intent.
  • alertDialog.setOnShowListener(dialog -> { sets up code that runs when the dialog appears.
  • Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE); grabs the dialog's confirm button.
  • button.setOnClickListener(view -> { sets up code that runs when the button is clicked.
  • fileName += ".txt"; appends the .txt extension to the file name.
  • Uri fileUri = savePlainTextToFile(fileName); saves the text to a file using that name and returns its address.
  • mStreamsToUpload.clear(); empties the list of files to upload.
  • mStreamsToUpload.add(fileUri); adds the newly saved file to that list.
  • uploadFiles(); starts the upload.
  • inputLayout.setErrorEnabled(error != null); and inputLayout.setError(error); show or hide an error message on the text box.
  • alertDialog.show(); displays the dialog.

savePlainTextToFile then builds the destination with new File(getCacheDir(), fileName), where fileName is still the attacker-controlled string:

Java
private Uri savePlainTextToFile(String fileName) {
    Uri uri = null;
    String content = getIntent().getStringExtra(Intent.EXTRA_TEXT);
    try {
        File tmpFile = new File(getCacheDir(), fileName); // here
        FileOutputStream outputStream = new FileOutputStream(tmpFile);
        outputStream.write(content.getBytes());
        outputStream.close();
        uri = Uri.fromFile(tmpFile);

    } catch (IOException e) {
        Timber.w(e, "Failed to create temp file for uploading plain text: %s", e.getMessage());
    }
    return uri;
}

Line by line:

  • private Uri savePlainTextToFile(String fileName) { starts the method that saves the text, taking the file name as input.
  • Uri uri = null; prepares a variable to hold the file address, initially empty.
  • String content = getIntent().getStringExtra(Intent.EXTRA_TEXT); reads the text to save from the intent's EXTRA_TEXT slot.
  • try { begins a block where errors are caught rather than crashing the app.
  • File tmpFile = new File(getCacheDir(), fileName); // here builds the destination: the cache directory plus the supplied file name. The comment marks the vulnerable line.
  • FileOutputStream outputStream = new FileOutputStream(tmpFile); opens that file for writing.
  • outputStream.write(content.getBytes()); writes the text into it.
  • outputStream.close(); closes the file.
  • uri = Uri.fromFile(tmpFile); turns the file into a URI.
  • } catch (IOException e) { catches any input/output error.
  • Timber.w(e, "Failed to create temp file for uploading plain text: %s", e.getMessage()); logs a warning.
  • return uri; returns the address, or null if something failed.

A .. sequence in the file name escapes the cache directory. The following PoC writes test.txt into shared_prefs with the contents supplied in android.intent.extra.TEXT:

Text
adb shell am start -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity -t "text/plain" -a "android.intent.action.SEND" --es "android.intent.extra.TEXT" "Arbitrary contents here" --es "android.intent.extra.TITLE" "../shared_prefs/test"

Line by line:

  • adb shell am start starts an activity on the device, as before.
  • -n com.owncloud.android.debug/com.owncloud.android.ui.activity.ReceiveExternalFilesActivity names the target activity.
  • -t "text/plain" sets the data type to plain text.
  • -a "android.intent.action.SEND" sets the send action.
  • --es "android.intent.extra.TEXT" "Arbitrary contents here" adds an extra of type string (es means extra string) holding the text to write.
  • --es "android.intent.extra.TITLE" "../shared_prefs/test" adds another string extra holding the file name, which contains the .. traversal.

The PoC supplies the contents in android.intent.extra.TEXT and the traversing name in android.intent.extra.TITLE, and the .txt suffix is appended by the activity. The result is a file at ../shared_prefs/test.txt relative to the cache directory, inside the app's private storage. The only restriction is that the written file always carries the .txt extension, which limits the impact.

Root cause

The stream guard is a substring check on the URI text rather than a check of the real, resolved path. It can be satisfied by including the cache directory path anywhere in the URI, and it can be avoided entirely by using a URI scheme that does not contain /data, such as the app's own content provider. Neither case resolves the path before deciding whether it is inside the app's private storage.

The plain text flow trusts the file name from the intent and joins it to the cache directory without rejecting directory separators or .. sequences. The report's remediation notes that simply replacing ../ is not enough, because filtering .../...// still leaves ../ behind after the replacement.

Impact

The read side leads to information disclosure: an attacker who can send an intent to the activity can cause the app to upload its internal files, including preferences and logs. The write side allows arbitrary file write inside the app's internal storage or other restricted directories the app can reach, limited to files with a .txt extension. The report rates the overall severity as low.

Fix

The report recommends validating user input before using it to construct a file path, with these rules:

  1. Do not allow more than a single . character.
  2. Do not allow directory separators such as / or \, depending on the file system.
  3. Do not rely on simply replacing problematic sequences such as ../, since filtering .../...// still yields ../.
  4. Ideally, use an allowlist of known good patterns.

An allowlist is a list of things that are explicitly allowed, with everything else rejected. The report does not state which changes ownCloud ultimately made.

Variants to test

  1. Cache-path bypass on other apps. Send a stream URI that contains the app's cache directory followed by ../ and a path into shared_prefs or databases. A positive result is the app uploading a file from its private storage.
  2. Own content provider URIs. Look for exported providers in the app's manifest and pass a content:// URI pointing into the app's internal files directory. A positive result is the file being read and uploaded without the /data guard firing.
  3. File name traversal in save flows. Wherever an app writes a user-supplied name under a fixed directory, try ../ sequences in the name. A positive result is a file appearing outside the intended directory.
  4. Filter evasion. If a filter strips ../, try nested sequences such as .../...// and check whether the result still resolves to a parent directory.

Hunting notes

This class of bug tends to hide in activities that accept intents from other apps, especially share and send handlers that take file URIs or file names from extras. During recon, look for exported activities with SEND or VIEW intent filters, and for content providers declared in the manifest. String-based path checks such as contains("/data") are a strong signal that canonicalisation is missing. Canonicalisation means turning a path into its one true, resolved form, so that cache/../shared_prefs becomes shared_prefs before any decision is made. The report provides concrete adb commands that target an internal file for upload and a traversing name for the plain text write, covering both the read and the write paths.

Glossary

  • Activity: a single screen or task in an Android app, such as the screen that receives shared files.
  • adb: Android Debug Bridge, a command-line tool for talking to an Android device from a computer.
  • Allowlist: a list of things that are explicitly permitted, with everything else rejected.
  • Cache directory: a scratch folder where an app keeps temporary files.
  • Canonicalisation: converting a path into its single resolved form, removing .. and . segments, before making decisions about it.
  • Content provider: an Android component that shares data with other apps through content:// addresses.
  • CVSS: a standard scoring system for rating the severity of a security flaw.
  • Extra: a named piece of data carried inside an Android intent.
  • File path: the address of a file on a device.
  • Intent: a message one Android app sends to another to request an action, carrying data and extras.
  • Package name: the unique identifier of an app on an Android device, such as com.owncloud.android.
  • Path traversal: a flaw where .. sequences in a supplied path let someone reach files outside the intended folder.
  • PoC: proof of concept, a concrete demonstration that a flaw can be exploited.
  • Provider: short for content provider.
  • Shared preferences: a private storage area where an Android app keeps its settings.
  • String: a piece of text in programming.
  • Substring check: testing whether one piece of text appears anywhere inside another, rather than checking the whole value.
  • URI: a standard way of writing the address of a file or resource, such as file:///... or content://....
  • Vulnerability: a weakness in software that someone can abuse to do something harmful.

More by atorralba

View all

1 more disclosed report, best first.

More from ownCloud

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.