|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP COLDFUSION LINKS Security Implementing HTTP Basic Authentication
Route around many of the common limitations of traditional forms-based authentication
By: Patrick Correia
Jun. 5, 2006 04:00 PM
Most ColdFusion applications that require users to be authenticated follow the pattern laid out in the official ColdFusion documentation and in the ColdFusion MX Developer's Guide.
An Overview of Forms-Based Authentication
<cfif NOT IsDefined("SESSION.login")> Let's look at the series of requests and responses that occur between a Web browser (WB) and a server (S) when the user requests a page that's protected by this kind of authentication code:
WB: Please send me the page called /index.cfm. Notice how the server claimed the two pages it sent were both /index.cfm? That's an example of one problem with forms-based authentication: it misrepresents the resources identified by URLs. To illustrate another problem, take a look at what happens later, after the user takes a break from using the application and the session expires:
WB: Please send me the page called /administrator/addUser.cfm. Since the session expired, the server responded to the request by providing the login form again. Even if the form provides some information about why the user needs to log in again, the user may become confused, and at the very least is inconvenienced. There are other ways to implement forms-based authentication (such as using <cflocation> to redirect the browser to the login form instead of using <cfinclude> to send it in place of the requested page), but the basic issues are the same:
What's all this talk about "misrepresenting the resource," you say? It boils down to URLs and status codes. Each time the browser requests a page, it specifies the exact resource (page) it's requesting. This resource is identified by the URL and a basic tenet of HTTP is that two requests for the same resource (assuming there's no form submission happening) should return exactly the same result (this is closely related to the property of HTTP requests called "idempotency," the principle that GET requests shouldn't change the state of the resource being requested). When the server sometimes sends a login form and sometimes sends the actual page, it's breaking this one-to-one correspondence between the URL and the resource. Each time the server responds to a request, it sends a status code that very succinctly tells the Web browser the "gist" of its response. Most of the time (when it's serving ColdFusion pages at least), the server sends the status code 200 ("OK"), which means "this page I'm sending you is exactly what you asked for." If instead of executing the page the user requested, the server is sends a login form, it's lying to the browser when it says it found what the user asked for. When the ColdFusion server processes a <cflocation> tag, it sends the status code 302 ("Found"), which means "the page you're looking for is temporarily located somewhere else and I'm sending you its location." If the address the server sends isn't actually the page the user requested, but a login form, it's lying again. These distinctions may seem pedantic. But every Web browser since NCSA Mosaic has been raised speaking HTTP as its native language and there's a surprising amount of potential to be leveraged in modern browsers when you respect the true meaning of the terms in that language. And sometimes when you ignore the rules of HTTP you get burned - a notable example of this was when Google released a beta of its Web Accelerator and lots of developers who had ignored the principle of idempotency found that their Web sites were breaking.
Basic Authentication to the Rescue
WB: Please send me the page called /index.cfm. Doesn't that look like a much more productive exchange than when the server was telling all sorts of lies about the resources it was sending to the browser? In fact it is more productive and here are a few reasons why:
Basic authentication doesn't have to be implemented in application code. All the most common Web servers (including Apache and Microsoft's Internet Information Server) allow the administrator to protect resources with Basic authentication by setting some configuration parameters. In some cases, this may be sufficient, but if you want to validate the user login information against an existing user database (the one built into your application, for example), you'll almost certainly find it easier to keep the authentication code integrated with the rest of your application. YOUR FEEDBACK
CFDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||