When browsers like IE 11, Firefox 26, Chrome 32 etc. receive a Cookie over an insecure (HTTP) connection which has the "Secure" attribute specified, they store the cookie and send it back once they do a request to the same server over a secure (HTTPS) connection.
While this probably accords with some specification (I guess Netscape Cookies), I wonder if this opens an additional security hole (Session Fixation) to SSL-secured sites.
Consider the following scenario:
A user (having a clean/malware-free client device) wants to access a website which has a username+password login, over a non-secure network (e.g. unencrypted WiFi hotspot) where an attacker can read and modify all data sent over that network. Let the DNS name of the website be www.example.com
.
The user knows that when this website asks him to enter a password, to always look if the browser's address bar contains the SSL lock icon before entering the password.
The website:
Now, imagine that the attacker runs a programm that intercepts all data sent over non-secure HTTP requests, and if these are HTML pages, insert a snipped that makes the browser send a HTTP request to www.example.com, like an invisible img or iframe tag:
<img src="http://www.example.com/" style="display: none;" />
The attacker then visits https://www.example.com/
by himself to obtain a session cookie generated by the server, and keeps browsing the site to keep the session alive.
He then also modifies HTTP requests from the user to www.example.com
to include the same session cookie in the HTTP response that the attacker just got from the server. The cookie has the "Secure" flag set.
Now, imagine the user visiting some regular HTTP sites which don't transfer sensitive data and therefore do not have SSL. This means the user's browser will receive the session cookie sent by the attacker on these requests.
Later, the user wents to https://www.example.com/
and wants to log in. He looks at the address bar to ensure that the SSL icon is displayed, and because it is, logs in with his password. However, because the attacker fixated the user's session by sending a cookie with a "Secure" attribute over an insecure HTTP request earlier, the attacker now has access to the user's session state.
Note, that if the website was changing the session identifier when the users logs in, the attacker wouldn't have access to the user's session state, but it would still be possible for the attacker to login as himself and send his session cookie to the user, overwriting previous session/login cookies, so that the user does actions (e.g. write sensitive mails etc.) on behalf of the attacker.
My impression of this browser's behavior is that it introduces an additional Session Fixation scenario as described above. The only way that I can see to prevent this is to change the session identifier on each request (for a HTML page).
Am I missing something here?
My view would be that if a browser would reject cookies that have the "Secure" attribute set but were sent over an insecure HTTP connection, the attacker would not have been able to:
This would remove the need for the particular website from changing the session identifier with each request.
EDIT: Ok, one thing that I missed is that browsers do not seem to send the "Secure" attribute on the Cookie header back to the server, so the server has no way to determine if this cookie was set to the client's browser with the "Secure" attribute.
But this would mean, even if browsers would reject cookies with the "Secure" flag on non-SSL connections, it would be possible for the attacker to set a cookie without the "Secure" flag which then gets accepted by the website on HTTPS requests as it can't check the "Secure" flag of the cookie.
Any ideas?
Thanks!
A secure cookie is only sent to the server with an encrypted request over the HTTPS protocol. Even with Secure, sensitive information should never be stored in cookies, as they are inherently insecure and this flag can't offer real protection.
Strict secure cookies So http://example.com/ can't overwrite a secure cookie on https://example.com/, something which was possible before. After the specification was finalized, this new behavior was soon implemented in browsers, and in modern browsers secure cookies can no longer be overwritten.
Conclusion. Security of cookies is an important subject. HttpOnly and secure flags can be used to make the cookies more secure. When a secure flag is used, then the cookie will only be sent over HTTPS, which is HTTP over SSL/TLS.
It provides a gate that prevents the specialized cookie from being accessed by anything other than the server. Using the HttpOnly tag when generating a cookie helps mitigate the risk of client-side scripts accessing the protected cookie, thus making these cookies more secure.
You're correct, this is a known limitation of the secure flag. From https://www.rfc-editor.org/rfc/rfc6265#section-4.1.2.5
Although seemingly useful for protecting cookies from active network
attackers, the Secure attribute protects only the cookie's
confidentiality. An active network attacker can overwrite Secure
cookies from an insecure channel, disrupting their integrity (see
Section 8.6 for more details).
And then from https://www.rfc-editor.org/rfc/rfc6265#section-8.6
8.6. Weak Integrity
Cookies do not provide integrity guarantees for sibling domains (and
their subdomains). For example, consider foo.example.com and
bar.example.com. The foo.example.com server can set a cookie with a
Domain attribute of "example.com" (possibly overwriting an existing
"example.com" cookie set by bar.example.com), and the user agent will
include that cookie in HTTP requests to bar.example.com. In the
worst case, bar.example.com will be unable to distinguish this cookie
from a cookie it set itself. The foo.example.com server might be
able to leverage this ability to mount an attack against
bar.example.com.
I think your best option is not to rely too much on cookies for security-related requirements :b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With