Online Book Reader

Home Category

Apache Security - Ivan Ristic [90]

By Root 1930 0
to the application.

Other authentication methods exist (Windows NT challenge/response authentication and the Kerberos-based Negotiate protocol), but they are proprietary to Microsoft and of limited interest to Apache administrators.

Basic Authentication

Authentication methods built into HTTP use headers to send and receive authentication-related information. When a client attempts to access a protected resource the server responds with a challenge. The response is assigned a 401 HTTP status code, which means that authentication is required. (HTTP uses the word "authorization" in this context but ignore that for a moment.) In addition to the response code, the server sends a response header WWW-Authenticate, which includes information about the required authentication scheme and the authentication realm. The realm is a case-insensitive string that uniquely identifies (within the web site) the protected area. Here is an example of an attempt to access a protected resource and the response returned from the server:

$ telnet www.apachesecurity.net 80

Trying 217.160.182.153...

Connected to www.apachesecurity.net.

Escape character is '^]'.

GET /review/ HTTP/1.0

Host: www.apachesecurity.net

HTTP/1.1 401 Authorization Required

Date: Thu, 09 Sep 2004 09:55:07 GMT

WWW-Authenticate: Basic realm="Book Review"

Connection: close

Content-Type: text/html

The first HTTP 401 response returned when a client attempts to access a protected resource is normally not displayed to the user. The browser reacts to such a response by displaying a pop-up window, asking the user to type in the login credentials. After the user enters her username and password, the original request is attempted again, this time with more information.

$ telnet www.apachesecurity.net 80

Trying 217.160.182.153...

Connected to www.apachesecurity.net.

Escape character is '^]'.

GET /review/ HTTP/1.0

Host: www.apachesecurity.net

Authorization: Basic aXZhbnI6c2VjcmV0

HTTP/1.1 200 OK

Date: Thu, 09 Sep 2004 10:07:05 GMT

Connection: close

Content-Type: text/html

The browser has added an Authorization request header, which contains the credentials collected from the user. The first part of the header value contains the authentication scheme (Basic in this case), and the second part contains a base-64 encoded combination of the username and the password. The aXZhbnI6c2VjcmV0 string from the header decodes to ivanr:secret. (To experiment with base-64 encoding, use the online encoder/decoder at http://makcoder.sourceforge.net/demo/base64.php.) Provided valid credentials were supplied, the web server proceeds with the request normally, as if authentication was not necessary.

Nothing in the HTTP protocol suggests a web server should remember past authentication requests, regardless of if they were successful. As long as the credentials are missing or incorrect, the web server will keep responding with status 401. This is where some browsers behave differently than others. Mozilla will keep prompting for credentials indefinitely. Internet Explorer, on the other hand, gives up after three times and displays the 401 page it got from the server. Being "logged in" is only an illusion provided by browsers. After one request is successfully authenticated, browsers continue to send the login credentials until the session is over (i.e., the user closes the browser).

Basic authentication is not an ideal authentication protocol. It has a number of disadvantages:

Credentials are transmitted over the wire in plaintext.

There are no provisions for user logout (on user request, or after a timeout).

The login page cannot be customized.

HTTP proxies can extract credentials from the traffic. This may not be a problem in controlled environments when proxies are trusted, but it is a potential problem in general when proxies cannot be trusted.

An attempt to solve some of these problems was made with the addition of Digest authentication to the HTTP protocol.

Digest Authentication

The major purpose of Digest authentication is to allow authentication

Return Main Page Previous Page Next Page

®Online Book Reader