Avoid TRACE requests (Cross-Site Tracing)
Marking cookies as Secure
and HttpOnly
isn't always enough. There's a technique called Cross-Site Tracing (XST) where a hacker uses the request methods TRACE
or TRACK
to bypass cookies marked as HttpOnly
. The TRACE
method is originally intended to help debugging, by letting the client know how a server sees a request. This debugging info is printed to the response, making it readable from the client.
If a hacker has successfully injected code onto your page, he/she could run the following script:
var xhr = new XMLHttpRequest();
xhr.open('TRACE', 'https://my.domain/', false);
xhr.send(null);
console.log(xhr.responseText);
If the receiving webserver supports TRACE
requests, the request including server variables, cookies, etc., is now written to the console. This would reveal the authentication cookie, even if it is marked as Secure
and HttpOnly
.
Luckily, modern browsers won't let anyone make TRACE
requests from JavaScript. You still want to eliminate the possibility, by updating your Web.config
accordingly:
<system.webServer>
<security>
<requestFiltering>
<verbs>
<add verb="TRACE" allowed="false" />
<add verb="TRACK" allowed="false" />
</verbs>
</requestFiltering>
</security>
</system.webServer>
The verbs
element includes a list of HTTP verbs not allowed.