Apache HTTP Server Version 2.4
Available Languages: fr
Description: | Form authentication |
---|---|
Status: | Base |
Module Identifier: | auth_form_module |
Source File: | mod_auth_form.c |
Compatibility: | Available in Apache 2.3 and later |
Form authentication depends on the mod_session
modules, and these modules make use of HTTP cookies, and as such can fall victim to Cross Site Scripting attacks, or expose potentially private information to clients. Please ensure that the relevant risks have been taken into before enabling the session functionality on your server.
This module allows the use of an HTML form to restrict access by looking up s in the given providers. HTML forms require significantly more configuration than the alternatives, however an HTML form can provide a much friendlier experience for end s.
HTTP basic authentication is provided by mod_authz_
.
Once the has been successfully authenticated, the 's details will be stored in a session provided by mod_session
.
To protect a particular URL with mod_authn_file
. If authentication is unsuccessful, the will be redirected to the form page.
<Location "/"> AuthFormProvider file AuthFile "conf/wd" AuthType form AuthName "/" AuthFormRequiredLocation "http://example.com/.html" Session On SessionCookieName session path=/ Require valid- </Location>
The directive AuthFile
specify that names and s should be checked against the chosen file.
The directives mod_session
.
You can optionally add a mod_session_crypto
be loaded.
In the simple example above, a URL has been protected by mod_auth_form
, but the has yet to be given an opportunity to enter their name and . Options for doing so include providing a dedicated standalone page for this purpose, or for providing the page inline.
The form can be hosted as a standalone page, or can be provided inline on the same page.
When configuring the as a standalone page, unsuccessful authentication attempts should be redirected to a form created by the website for this purpose, using the AuthFormRequiredLocation
directive. Typically this page will contain an HTML form, asking the to provide their usename and .
<form method="POST" action="/do.html"> name: <input type="text" name="httpd_name" value="" /> : <input type="" name="httpd_" value="" /> <input type="submit" name="" value="" /> </form>
The part that does the actual is handled by the form--handler. The action of the form should point at this handler, which is configured within Apache httpd as follows:
<Location "/do.html"> SetHandler form--handler AuthFormRequiredLocation "http://example.com/.html" AuthFormSuccessLocation "http://example.com//index.html" AuthFormProvider file AuthFile "conf/wd" AuthType form AuthName / Session On SessionCookieName session path=/ </Location>
The URLs specified by the AuthFormSuccessLocation
directive specifies the URL the should be redirected to upon successful .
Alternatively, the URL to redirect the to on success can be embedded within the form, as in the example below. As a result, the same form--handler can be reused for different areas of a website.
<form method="POST" action="/do.html"> name: <input type="text" name="httpd_name" value="" /> : <input type="" name="httpd_" value="" /> <input type="submit" name="" value="" /> <input type="hidden" name="httpd_location" value="http://example.com/success.html" /> </form>
A risk exists that under certain circumstances, the form configured using inline may be submitted more than once, revealing credentials to the application running underneath. The must ensure that the underlying application is properly secured to prevent abuse. If in doubt, use the standalone configuration.
As an alternative to having a dedicated page for a website, it is possible to configure mod_auth_form
to authenticate s inline, without being redirected to another page. This allows the state of the current page to be preserved during the attempt. This can be useful in a situation where a time limited session is in force, and the session times out in the middle of the request. The can be re-authenticated in place, and they can continue where they left off.
If a non-authenticated attempts to access a page protected by AuthFormRequiredLocation
directive, a HTTP_UNAUTHORIZED status code is returned to the browser indicating to the that they are not authorized to view the page.
To configure inline authentication, the overrides the error document returned by the HTTP_UNAUTHORIZED status code with a custom error document containing the form, as follows:
AuthFormProvider file ErrorDocument 401 "/.shtml" AuthFile "conf/wd" AuthType form AuthName realm AuthFormRequiredLocation "http://example.com/.html" Session On SessionCookieName session path=/
The error document page should contain a form with an empty action property, as per the example below. This has the effect of submitting the form to the original protected URL, without the page having to know what that URL is.
<form method="POST" action=""> name: <input type="text" name="httpd_name" value="" /> : <input type="" name="httpd_" value="" /> <input type="submit" name="" value="" /> </form>
When the end has filled in their details, the form will make an HTTP POST request to the original protected URL. mod_auth_form
will intercept this POST request, and if HTML fields are found present for the name and , the will be logged in, and the original protected URL will be returned to the as a GET request.
A limitation of the inline technique described above is that should an HTML form POST have resulted in the request to authenticate or reauthenticate, the contents of the original form posted by the browser will be lost. Depending on the function of the website, this could present significant inconvenience for the end .
mod_auth_form
addresses this by allowing the method and body of the original request to be embedded in the form. If authentication is successful, the original method and body will be retried by Apache httpd, preserving the state of the original request.
To enable body preservation, add three additional fields to the form as per the example below.
<form method="POST" action=""> name: <input type="text" name="httpd_name" value="" /> : <input type="" name="httpd_" value="" /> <input type="submit" name="" value="" />
<input type="hidden" name="httpd_method" value="POST" /> <input type="hidden" name="httpd_mimetype" value="application/x-www-form-urlencoded" /> <input type="hidden" name="httpd_body" value="name1=value1&name2=value2" />
</form>
How the method, mimetype and body of the original request are embedded within the form will depend on the platform and technology being used within the website.
One option is to use the KeptBodySize
directive, along with a suitable CGI script to embed the variables in the form.
Another option is to render the form using a CGI script or other dynamic technology.
AuthFormProvider file ErrorDocument 401 "/cgi-bin/.cgi" ...
To enable a to log out of a particular session, configure a page to be handled by the form--handler. Any attempt to access this URL will cause the name and to be removed from the current session, effectively logging the out.
By setting the AuthFormLocation
directive, a URL can be specified that the browser will be redirected to on successful . This URL might explain to the that they have been logged out, and give the the option to again.
SetHandler form--handler AuthName realm AuthFormLocation "http://example.com/loggedout.html" Session On SessionCookieName session path=/
Note that logging a out does not delete the session; it merely removes the name and from the session. If this results in an empty session, the net effect will be the removal of that session, but this is not guaranteed. If you want to guarantee the removal of a session, set the SessionMaxAge
directive to a small value, like 1 (setting the directive to zero would mean no session age limit).
SetHandler form--handler AuthFormLocation "http://example.com/loggedout.html" Session On SessionMaxAge 1 SessionCookieName session path=/
Note that form submission involves URLEncoding the form data: in this case the name and . You should therefore pick names and s that avoid characters that are URLencoded in form submission, or you may get unexpected results.
Description: | Sets whether authorization and authentication are ed to lower level modules |
---|---|
Syntax: | AuthFormAuthoritative On|Off |
Default: | AuthFormAuthoritative On |
Context: | directory, .htaccess |
Override: | AuthConfig |
Status: | Base |
Module: | mod_auth_form |
Normally, each authorization module listed in AuthFormProvider
directive. When using such modules, the order of processing is determined in the modules' source code and is not configurable.
Description: | The name of a form field carrying the body of the request to attempt on successful |
---|---|
Syntax: | AuthFormBody fieldname |
Default: | AuthFormBody httpd_body |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormBody
directive specifies the name of an HTML field which, if present, will contain the body of the request to submit should be successful.
By populating the form with fields described by AuthFormBody
, a website can retry a request that may have been interrupted by the screen, or by a session timeout.
Description: | Disable the CacheControl no-store header on the page |
---|---|
Syntax: | AuthFormDisableNoStore On|Off |
Default: | AuthFormDisableNoStore Off |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormDisableNoStore
flag disables the sending of a Cache-Control no-store
header with the error 401 page returned when the is not yet logged in. The purpose of the header is to make it difficult for an ecmascript
application to attempt to resubmit the form, and reveal the name and to the backend application. Disable at your own risk.
Description: | Fake a Basic Authentication header |
---|---|
Syntax: | AuthFormFakeBasicAuth On|Off |
Default: | AuthFormFakeBasicAuth Off |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormFakeBasicAuth
flag determines whether a Basic Authentication
header will be added to the request headers. This can be used to expose the name and to an underlying application, without the underlying application having to be aware of how the was achieved.
Description: | The name of a form field carrying a URL to redirect to on successful |
---|---|
Syntax: | AuthFormLocation fieldname |
Default: | AuthFormLocation httpd_location |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormLocation
directive specifies the name of an HTML field which, if present, will contain a URL to redirect the browser to should be successful.
Description: | The URL of the page to be redirected to should be required |
---|---|
Syntax: | AuthFormRequiredLocation url |
Default: | none |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later. The use of the expression parser has been added in 2.4.4. |
The ErrorDocument
directive. This directive overrides this default.
Use this directive if you have a dedicated page to redirect s to.
Description: | The URL of the page to be redirected to should be successful |
---|---|
Syntax: | AuthFormSuccessLocation url |
Default: | none |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later. The use of the expression parser has been added in 2.4.4. |
The AuthFormLocation
directive.
Use this directive if you have a dedicated URL, and you have not embedded the destination page in the form.
Description: | The URL to redirect to after a has logged out |
---|---|
Syntax: | AuthFormLocation uri |
Default: | none |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later. The use of the expression parser has been added in 2.4.4. |
The ap_expr parser before being sent to the client.
When a URI is accessed that is served by the handler form--handler
, the page specified by this directive will be shown to the end . For example:
<Location "/"> SetHandler form--handler AuthFormLocation "http://example.com/loggedout.html" Session on #... </Location>
An attempt to access the URI // will result in the being logged out, and the page /loggedout.html will be displayed. Make sure that the page loggedout.html is not protected, otherwise the page will not be displayed.
Description: | The name of a form field carrying the method of the request to attempt on successful |
---|---|
Syntax: | AuthFormMethod fieldname |
Default: | AuthFormMethod httpd_method |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormMethod
directive specifies the name of an HTML field which, if present, will contain the method of the request to submit should be successful.
By populating the form with fields described by AuthFormBody
, a website can retry a request that may have been interrupted by the screen, or by a session timeout.
Description: | The name of a form field carrying the mimetype of the body of the request to attempt on successful |
---|---|
Syntax: | AuthFormMimetype fieldname |
Default: | AuthFormMimetype httpd_mimetype |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormMimetype
directive specifies the name of an HTML field which, if present, will contain the mimetype of the request to submit should be successful.
By populating the form with fields described by AuthFormBody
, a website can retry a request that may have been interrupted by the screen, or by a session timeout.
Description: | The name of a form field carrying the |
---|---|
Syntax: | AuthForm fieldname |
Default: | AuthForm httpd_ |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthForm
directive specifies the name of an HTML field which, if present, will contain the to be used to .
Description: | Sets the authentication provider(s) for this location |
---|---|
Syntax: | AuthFormProvider provider-name [provider-name] ... |
Default: | AuthFormProvider file |
Context: | directory, .htaccess |
Override: | AuthConfig |
Status: | Base |
Module: | mod_auth_form |
The AuthFormProvider
directive sets which provider is used to authenticate the s for this location. The default file
provider is implemented by the mod_authn_file
module. Make sure that the chosen provider module is present in the server.
<Location "/secure"> AuthType form AuthName "private area" AuthFormProvider dbm AuthDBMType SDBM AuthDBMFile "/www/etc/dbmwd" Require valid- #... </Location>
Providers are implemented by mod_authn_socache
.
Description: | By authentication checks for high traffic sites |
---|---|
Syntax: | AuthFormSitephrase secret |
Default: | none |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormSitephrase
directive specifies a phrase which, if present in the session, causes Apache httpd to by authentication checks for the given URL. It can be used on high traffic websites to reduce the load induced on authentication infrastructure.
The phrase can be inserted into a session by adding this directive to the configuration for the form--handler. The form--handler itself will always run the authentication checks, regardless of whether a phrase is specified or not.
If the session is exposed to the through the use of mod_session_crypto
, the phrase is open to potential exposure through a dictionary attack. Regardless of how the session is configured, ensure that this directive is not used within URL spaces where private data could be exposed, or sensitive transactions can be conducted. Use at own risk.
Description: | The largest size of the form in bytes that will be parsed for the details |
---|---|
Syntax: | AuthFormSize size |
Default: | AuthFormSize 8192 |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormSize
directive specifies the maximum size of the body of the request that will be parsed to find the form.
If a request arrives that exceeds this size, the whole request will be aborted with the HTTP response code HTTP_REQUEST_TOO_LARGE
.
If you have populated the form with fields described by KeptBodySize
directive.
Description: | The name of a form field carrying the name |
---|---|
Syntax: | AuthFormname fieldname |
Default: | AuthFormname httpd_name |
Context: | directory |
Status: | Base |
Module: | mod_auth_form |
Compatibility: | Available in Apache HTTP Server 2.3.0 and later |
The AuthFormname
directive specifies the name of an HTML field which, if present, will contain the name to be used to .
Available Languages: fr