<-
Apache > HTTP Server > Documentation > Modules

Apache Module mod_auth_form 5o472x

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

Summary 6m2os

Warning 6h505h

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.

 Apache!

Topics 2c136y

Directives 1a4l6m

Bugfix checklist 4i2533

See also 27136x

top

Basic Configuration 5i1h4i

To protect a particular URL with mod_authn_file. If authentication is unsuccessful, the will be redirected to the form page.

Basic example y6t5y

<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.

top

Standalone 1p3w6w

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 .

Example form 6w3i3i

<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:

Form handler example 1j4z58

<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.

Example form with location 2d1y2p

<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>
top

Inline 275r5j

Warning 6h505h

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:

Basic inline example 6o16c

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.

Example inline form 3m2z5l

<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.

top

Inline with Body Preservation 214w1b

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.

Example with body preservation 4e51v

<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.

CGI example 5i396b

AuthFormProvider file
ErrorDocument 401 "/cgi-bin/.cgi"
...
top

Logging Out 2o5f31

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.

Basic example et51

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).

Basic session expiry example 627334

SetHandler form--handler
AuthFormLocation "http://example.com/loggedout.html"
Session On
SessionMaxAge 1
SessionCookieName session path=/
top

names and s w3f3y

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.

top

AuthFormAuthoritative Directive op4k

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.

top

AuthFormBody Directive c191y

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.

top

AuthFormDisableNoStore Directive 59c3w

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.

top

AuthFormFakeBasicAuth Directive 5g46o

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.

top

AuthFormLocation Directive 6a154r

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.

top

AuthFormRequiredLocation Directive 6253s

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.

top

AuthFormSuccessLocation Directive 2z6v3v

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.

top

AuthFormLocation Directive 6a154r

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:

Example 5z1g6h

<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.

top

AuthFormMethod Directive 374f2o

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.

top

AuthFormMimetype Directive 6ru3z

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.

top

AuthForm Directive 1c1o26

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 .

top

AuthFormProvider Directive 4d6y1f

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.

Example 5z1g6h

<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.

top

AuthFormSitephrase Directive 5y361h

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.

Warning 6h505h

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.

top

AuthFormSize Directive c3k64

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.

top

AuthFormname Directive 5c3s4g

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 

top

Comments 2p1l6j

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our s if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our mailing lists.