Should web developers say no to cookie-based authentication?
Timothy D. Morgan of Virtual Security Research (VSR) has written a paper proposing a system for web applications to authenticate users that offers significantly better security than the common practice of storing session IDs in cookies. Morgan's proposal is based on the existing (but seldom-used) HTTP Digest Access Authentication method, so it could be implemented with very little effort in existing web browsers and web servers. He argues that digest authentication's lack of popularity is primarily due to inflexible implementations that web developers find inconvenient compared to the simplicity of using cookies, and suggests some changes that could make it more appealing.
The paper, "Weaning the Web off of Session Cookies: Making Digest Authentication Viable," is available as a PDF from the VSR web site. Morgan begins by outlining the established security problems with using cookies to store session IDs on the user's web browser. In a typical scheme, a user authenticates to a web application via a username/password combination entered through an HTML form, after which a session key is sent back to the user's browser and stored in a cookie, the value of which is either generated pseudorandomly or is some value that is encrypted server-side.
Even if the communication channel uses SSL/TLS, however, there are security problems with this approach. The pseudorandom number generator may be predictable or the encryption algorithm insecure, allowing an attacker to spoof the session. Worse, such session IDs can be exposed in URLs, and captured in referrer logs, proxy logs, and browser histories. In addition, many popular web application frameworks set a session cookie before requiring login, then subsequently "upgrade" the session to an authenticated state after redirecting the user to a login page — but using the same cookie. An attacker can hijack such a session simply by visiting the HTTP site before the login takes place and recording the session ID.
Morgan also points out several flaws with cookie-based session IDs at the protocol level. First, a cookie originally sent on HTTPS will also be sent over HTTP on subsequent requests, unless the web developer takes the proactive step of setting the "secure" flag on the cookie, which few application frameworks do. Second, by default stored cookies are available to client-side JavaScript, making them vulnerable to theft via cross-site-scripting attacks. Internet Explorer and Firefox both feature an "HttpOnly" cookie flag to block this behavior, but other browsers do not, and few session-management frameworks have adopted it. Failure to automatically time-out sessions and poorly-implemented single sign-on (SSO) methods also make many cookie-based session management schemes vulnerable.
Digest
Morgan then explains the basics of HTTP Digest Authentication, which was introduced with HTTP 1.1 in RFC 2069, and updated in RFC 2617. Digest authentication is an improvement over HTTP Basic Access Authentication, which simply encodes the username/password combination in base64 and transmits it to the server in plaintext.
Digest authentication is significantly more secure, because it computes a cryptographic hash based on the username, password, HTTP authentication realm, a server-provided nonce, the URI requested, the request method and (optionally) the request body. The RFC 2617 revision also includes a nonce count and a client nonce to further protect the integrity of the request.
The primary reason that digest authentication is not popular with web developers, Morgan says, is that it does not integrate into application and site design. All major web browsers implement HTTP basic and digest authentication in the same way, by launching a generic, modal pop-up window prompting the user for his or her username and password. The pop-up cannot be integrated into page design, nor customized, which makes it unappealing to developers. In addition to that, when using digest authentication there is no established method for the application to log the user out (which is a security risk of its own).
Finally, the current version of HTTP digest authentication specifies the MD5 hash algorithm, which is known to be vulnerable to preimage computation — although using the RFC 2617 mode makes such an attack impractical by incorporating the client-side nonce in its response.
The proposed improvements
Morgan suggests three methods to make digest authentication more accessible — and thus, useful — to web application developers.
The first is to use AJAX to take a username/password combination from an HTML form and generate the HTTP digest authentication request, which preserves the developer's ability to customize and control the login page. Making this method work seamlessly, however, would require a change to the way application respond if the username/password fails. Most web servers send a 401 error code, which causes today's browsers to automatically open a pop-up window; thus negating the work to integrate the authentication into the page. If the server returned a different error code, however, that problem could be avoided.
More difficult is how to provide a system with which the application can trigger a logout. Morgan observes that when most popular browsers receive the 401 Unauthorized error code, they immediately launch the authentication pop-up window, regardless of whether the user was already logged into the site. But this behavior is not specified in the HTTP standard; if browsers simply checked for existing credentials in the cache, a 401 could be used to trigger a logout in the event that the user is logged in, and prompt for credentials if the user is not logged in.
He also suggests another solution, a new HTTP header called "Authentication-Control" that could be used to terminate a session from the web server.
Practical problems
The paper outlines several practical problems that would come with attempting to migrate to digest authentication for session management. To begin with, digest authentication is so rarely used that its implementation in popular web servers and web browsers is immature. Just as bad, today's browsers have weak, bare-bones user interfaces for HTTP authentication. Password managers do not differentiate between credentials stored for HTTP sites and those stored for HTTPS, making man-in-the-middle attacks possible.
The authentication pop-up windows are also sparse in their presentation, offering confusing messages that make phishing attacks possible. Morgan shows example windows from Internet Explorer, Firefox, Safari and Opera, in which the "realm" value sent in the authentication request is used to display an intentionally-misleading message to the user.
Finally, Morgan notes, because application developers have relied on cookie-based session management for several years, they have become accustomed to the application framework handling session management. Switching to digest authentication would mean relying on the web server to manage the session authentication, and that change could meet with resistance.
Reaction
Morgan posted news of the paper to Bugtraq, Full Disclosure, and several other security mailing lists in January. Reaction was mixed; while most agreed with the technical arguments, some thought that the paper did not explain how important web application functionality — namely SSO — could be made to work with digest authentication. The strongest disagreements, however, came from those who argued that the amount of coding and refactoring required to change web application frameworks' authentication systems make the entire argument moot.
The proposal did receive a friendlier reception in mozilla.dev.security, however, where Mozilla's Dan Veditz pointed out similar work on improving web authentication going on at Mozilla Labs.
Will web developers be weaned off of their cookie addiction? Presumably that hinges on whether the popular application frameworks undertake the task of replacing cookies as a session-tracking tool. Morgan argues in the paper that because cookies are widely used for many general-purpose tasks, asking them to correctly implement secure authentication is a losing battle: other concerns, from marketing to SSO, will always be more popular, and get the lion's share of developer attention. But it is interesting to note that an almost-complete, more secure solution already exists in the standards. Perhaps decoupling authentication and cookies would be a quicker process than the naysayers believe.
Index entries for this article | |
---|---|
Security | Browser cookies |
Security | Web sessions |
GuestArticles | Willis, Nathan |
Frameworks a drawback, huh?
Posted Mar 25, 2010 1:05 UTC (Thu)
by martinfick (subscriber, #4455)
[Link] (2 responses)
Posted Mar 25, 2010 1:05 UTC (Thu) by martinfick (subscriber, #4455) [Link] (2 responses)
Frameworks a drawback, huh?
Posted Mar 25, 2010 2:20 UTC (Thu)
by draco (subscriber, #1792)
[Link] (1 responses)
Posted Mar 25, 2010 2:20 UTC (Thu) by draco (subscriber, #1792) [Link] (1 responses)
http://www.cs.ucl.ac.uk/staff/m.handley/papers/only-just-...
Frameworks a drawback, huh?
Posted Mar 28, 2010 10:15 UTC (Sun)
by erwbgy (subscriber, #4104)
[Link]
Posted Mar 28, 2010 10:15 UTC (Sun) by erwbgy (subscriber, #4104) [Link]
Thanks for the link. This is an excellent paper about the Internet, the stack of protocols proposed and active and potential future problems. I would recommend others read it.
Should web developers say no to cookie-based authentication?
Posted Mar 25, 2010 2:22 UTC (Thu)
by dps (guest, #5725)
[Link]
Posted Mar 25, 2010 2:22 UTC (Thu) by dps (guest, #5725) [Link]
Cookies, and usually java, can be used to implement security which is *much more secure* than digest authentication. Session hijacking, cookies as sent over the wire and any previous values can all be easily rendered useless.
Taking a leaf out of secure RPC's book and using storing a public key and encrypted private key on the server requires the use of cookies. If you want to use SRP the deal is the same: you must use cookies. Either way implementing the flaws described is less probable than SQL injection attacks via evil cookie values.
If the application is LWN then security it is not critical: the marginal cost of shipping a few unfunded bits is presumably minimal. It is enough for a reasonable majority of people to pay.
Duncan
P.S. You can implement digest logout now by always returning 401 if a cookie is not present, even if the credentials are valid. The logout button just deletes the cookie. You can include the cookie in the 401 response. I know this works in IE, firefox, opera and chrome.
A real browser "forget my credentials for this website" button would be much batter and more secure but I am fairly sure it will not be implemented within the next 3 years.
Should web developers say no to cookie-based authentication?
Posted Mar 25, 2010 2:27 UTC (Thu)
by ras (subscriber, #33059)
[Link] (1 responses)
Posted Mar 25, 2010 2:27 UTC (Thu) by ras (subscriber, #33059) [Link] (1 responses)
1. RFC 2617 auth can be immune to replay attacks, because they include a nonce count. This difficult to do with cookies.
2. By making it possible for app coders to use a standard auth library, we reduce the number of bugs.
Is that it?
Should web developers say no to cookie-based authentication?
Posted Mar 25, 2010 16:58 UTC (Thu)
by epa (subscriber, #39769)
[Link]
Posted Mar 25, 2010 16:58 UTC (Thu) by epa (subscriber, #39769) [Link]
3. In practice, a lot of cookie-based auth systems are badly done, whereas the digest authentication in popular browsers and popular web servers follows a sensible design (the two RFCs mentioned) and is well implemented. However, it doesn't have a shiny user interface that site designers want.
Eh?
Posted Mar 25, 2010 18:43 UTC (Thu)
by jmorris42 (guest, #2203)
[Link]
Posted Mar 25, 2010 18:43 UTC (Thu) by jmorris42 (guest, #2203) [Link]
And the proposed solution would require getting 100% of clients upgraded to a browser version that doesn't currently exist. How many hits does the average site still get from IE6? Typical security researcher living in an academic nonreality proposing improbably solutions to things that aren't even serious problems in the real world.
Should web developers say no to cookie-based authentication?
Posted Mar 25, 2010 20:31 UTC (Thu)
by Cyberax (✭ supporter ✭, #52523)
[Link] (2 responses)
Posted Mar 25, 2010 20:31 UTC (Thu) by Cyberax (✭ supporter ✭, #52523) [Link] (2 responses)
Cookies are just a way to store session-id. I'd understand if the author wanted to define a special session-tracking API (in essence, adding state to HTTP) with protection against cross-site scripting, etc.
But this crap? No way.
How can I use OpenID with digest authentication? How do I use GSSAPI (Kerberos or SMKP)?
Use single responsibility principle and split the spec into session-tracking stuff and use digest authentication as one way to provide session identifiers.
Should web developers say no to cookie-based authentication?
Posted Mar 26, 2010 21:19 UTC (Fri)
by jo42 (subscriber, #59640)
[Link] (1 responses)
Posted Mar 26, 2010 21:19 UTC (Fri) by jo42 (subscriber, #59640) [Link] (1 responses)
Should web developers say no to cookie-based authentication?
Posted Mar 26, 2010 21:20 UTC (Fri)
by Cyberax (✭ supporter ✭, #52523)
[Link]
Posted Mar 26, 2010 21:20 UTC (Fri) by Cyberax (✭ supporter ✭, #52523) [Link]
Should web developers say no to cookie-based authentication?
Posted Mar 25, 2010 22:51 UTC (Thu)
by jonabbey (guest, #2736)
[Link]
Posted Mar 25, 2010 22:51 UTC (Thu) by jonabbey (guest, #2736) [Link]
Should web developers say no to cookie-based authentication?
Posted Apr 1, 2010 6:42 UTC (Thu)
by eduperez (guest, #11232)
[Link] (1 responses)
Posted Apr 1, 2010 6:42 UTC (Thu) by eduperez (guest, #11232) [Link] (1 responses)
Should web developers say no to cookie-based authentication?
Posted Apr 2, 2010 16:09 UTC (Fri)
by ghamlin (guest, #57789)
[Link]
Posted Apr 2, 2010 16:09 UTC (Fri) by ghamlin (guest, #57789) [Link]
That is the mistake. Form-based login screens should never have become acceptable. There can be never be a trusted UI, if the password UI is a webpage (even with flash disabled, even with content restriction ).
It is just broken. It is a good paper and a very pragamtic one,too. He outline many half-way approaches one could take.
In a related vein. I think the ECP profile for SAML would be interesting in the browser. I'd like to see that happen. When it does I hope they build in a trusted visual path element.
Security needs to be outside of javascript and html, otherwise we can't fix it. Cookies are not sane for login credentials.