[APACHE DOCUMENTATION]

mod_eaccess: Extended Access control

This module enables Regular Expression filtering on URL, including HTTP method, URI, QUERY_STRING and body content (DATA).

Table of Contents

Download

Summary

This module is specially designed for Apache server to act as a secure reverse proxy server, filtering access to CGI and their parameters.
Here is an example:

Installation

Extract apache:

Extract mod_eaccess:

Configure apache with mod_eaccess:

Compile:

See Limitation if you want special installation (specialy for complete body checks).

Directives


EAccessEnable

Syntax: EAccessEnable on | off
Default: EAccessEnable on
Context: server config, virtual host

The EAccessEnable directive enables or disables the runtime extended access control engine.

If it is set to off this module does no runtime processing at all.
If it is set to on this module does runtime processing and then first sets default policy to deny all.


EAccessRule

Syntax: EAccessRule action "pattern" [option]
Default: none
Context: server config, virtual host

The EAccessRule directive is the real extended access control workhorse. The directive can occur more than once. Each directive then defines one single access control rule. The definition order of these rules is important, because this order is used when applying the rules at run-time.

pattern can be extended regular expression which gets applied to the current URL. The following "options" can be used for pattern:

action can be one of permit, deny, warning, auth/basic, auth/securid or exec:

For each requested URL, the module constructs the following string for controls:

Note that both QUERY_STRING and body may be present, so the string is:

Then this string is unescaped: `%encoded' characters are translated into their corresponding values, except for:
  %00 ('\0') => "\0",
  %07 ('\a') => "\a",
  %08 ('\b') => "\b",
  %0A ('\n') => "\n",
  %0B ('\v') => "\v",
  %0C ('\f') => "\f",
  %0D ('\r') => "\r",
  %26 ('&') => ".",
  %7C ('|') => ".".

CR-LF (character \r followed by character \r) are also translated into string \n.

This makes URL arguments and body easier to match.

Then the unescaped string is used by the module to try to match a pattern defined in EAccessRule.

As default policy is set to deny all when extended access control is set to on, the algorithm used for each URL by the module is:

In fact, for auth/* action, if option is set in the rule, we do not trust the web server because authentication is first checked by mod_eaccess.
If option is not set, we do trust the web server and then do not check if an authentication is set in the HTTP header.


EAccessLog

Syntax: EAccessLog file-pipe
Default: EAccessLog logs/eaccess_log
Context: server config, virtual host

The EAccessLog directive sets the name of the file to which the server logs any extended access controls it performs. If the name begins with a pipe ('|'), followed by a command, then it is assumed to be a program that receives the agent log information on its standard input. Else, it must be a filename. If the filename does not begin with a slash ('/') then it is assumed to be relative to the Server Root.

When EAccessLogLevel is set, each action logs a line in the common log format (host, ident, authuser, date), followed by a text, depending upon the action:

Notice: To disable the logging, it is not recommended to set filename to /dev/null, because although the module does not create output to a logfile it still creates the logfile output internally. This will slow down the server! To disable logging use EAccessLogLevel 0.


EAccessLogLevel

Syntax: EAccessLogLevel level
Default: EAccessLogLevel 1
Context: server config, virtual host

The EAccessLogLevel directive set the verbosity level of the extended access control logfile.

Level 0 means no logging.
Level 1 logs which EAccessRule grants or denies access to URL.
Level > 1 is for debugging.


EAccessCache

Syntax: EAccessCache filename
Default: EAccessCache logs/eaccess_auth
Context: server config, virtual host

The EAccessCache directive sets the name of the file to which the server caches user authentication when auth/* is used in EAccessRule. If the name does not begin with a slash ('/') then it is assumed to be relative to the Server Root.

Notice: To avoid dump of the cache, MD5 digest of the authentications is stored...


EAccessOptim

Syntax: EAccessOptim level
Default: EAccessOptim 1
Context: server config, virtual host

The EAccessOptim directive sets the optimization level.

Level 0 (default value) means no optimization: only regular expressions strings are stored in memory.
Level 1 means more optimization: compiled regular expressions are also stored in memory. With a bad regex lib, this may cost a lot... Use GNU regex.


EAccessTmpDir

Syntax: EAccessTmpDir directory
Default: EAccessTmpDir /tmp
Context: server config, virtual host

The EAccessTmpDir directive sets the temporary directory used to store body files.

This directive is only available if you compile mod_eaccess with -DEACCESS_BODY_HACK (See Limitation).


Limitation

Only the beginning of the body can be checked; limit is near DEFAULT_BUFSIZE (defined in buff.c), but also depends on system settings:

When Apache receives a connection, it is read from a socket and put into a buffer. Default socket buffer size is controlled with:

So the first socket read of an incomming connection (limit: default socket buffer size, as Apache does not set it) is put into buffer (limit: DEFAULT_BUFSIZE, set to 4096 in buff.c). It is then a good idea to have default socket buffer size greater than DEFAULT_BUFSIZE: we recommend to use at least 8192.

Finally, as the beginning of the HTTP connection includes headers and body, EAccess will use at most for body: DEFAULT_BUFSIZE - sizeof (HTTP headers).

To bypass this limit, we must patch Apache code. The raison is simple: when Apache has read once the body, it cannot read it again (because of socket...). The little patch mod_eaccess.patch is supplied to enable complete body checks. Do the following:

Patch apache:

Compile apache with complete body future:

Security tips

As we said, the string used to match a RE is:

In fact, URI is set by Apache as the path portion of the %unescaped unparsed uri, with some path optimisations. For example:

And the string used to match a RE is exactly:

When EAccess is used with Apache running as a web-server, this is fine because this string is really the URI Apache is looking for.

But when EAccess is used with Apache running as a reverse-proxy, this may be dangerous; suppose for example the URL the reverse-proxy receives is:

The URI in the reverse-proxy running with EAccess will be:

and will be proxy as: Then the next server (suppose Apache), will compute his URI as:

This may be very dangerous if EAccess rules are:

This allows good.cgi to be used with a argument param which contains up to 64 characters. For example: But this also allows the following URL: which is scanned by EAccess filter as "/good.cgi?param=/../bad.cgi?badargs", resend by reverse-proxy as "/good.cgi%3Fparam=/../bad.cgi?badargs" and parsed by next server as "/bad.cgi?badargs".

Conclusion: when using EAccess on Apache running as a reverse-proxy, it is a good idea to use the first rule:


Apache HTTP Server Version 1.3

Index