Apache
DataDome Apache integration detects and protects against bot activity.
Supported versions
Apache version
DataDome supports the last two stable versions for Apache.
You can find the release strategy for Apache on this website.
The module is compatible with stable versions 2.2 and above.
Operating systems
The module is compatible with the following Operating Systems:
- Debian 9+
- Ubuntu 18+
- Centos 6+
Installation
Requirements
Server-Side Keyavailable in your DataDome dashboard
Protect your traffic
- Compile the module:
apt-get install make libssl-dev apache2-devyum install make openssl-devel httpd-devel which gcc mod_sslzypper install make openssl-devel apache2-develMake sure all packages are installed before proceding.
rm -f DataDome-Apache-latest.tgz
wget https://package.datadome.co/linux/DataDome-Apache-latest.tgz
tar -zxvf DataDome-Apache-latest.tgz
cd DataDome-ApacheDome-*
make prepare
make
make install # This might required sudo/root accessPlease refer to the FAQ in case of a custom path (Apache and/or Openssl) or if apache2-dev/httpd-dev is not available.
- Keep the output path of
mod_datadome_shield.so. - Copy
docs/mod_datadome.confto the Apache folder below:
cp docs/mod_datadome.conf /etc/apache2/mods-enabled/cp docs/mod_datadome.conf /etc/httpd/conf.modules.d/cp docs/mod_datadome.conf /etc/apache2/conf.d/- Open
mod_datadome.conf:
- Set the
DomeKeyusing theServer-Side Keyavailable in your DataDome dashboard. - Adjust the path (from step 2) of
LoadModuleformod_datadome_shield.so.
- Test the configuration:
apachectl -t
# Syntax OK- Restart Apache Server:
apachectl -k restartCongrats! You can now see your traffic in your DataDome dashboard.
Configuration
By default, the configuration is located in mod_datadome.conf.
Refer to the next Settings section for the full list of possible configuration settings.
Settings
| Setting | Description | Required | Default |
|---|---|---|---|
| DomeKey | DataDome Server-Side Key, found in your dashboard | Yes | |
| DomeApiHost | Host of the API Server: available endpoints | Optional | api.datadome.co Regional Endpoints |
| DomeApiPort | Port of the API server | Optional | 443 |
| DomeApiProtocol | Protocol for API Server connexion | Optional | HTTPS |
| DomeURIRegex | Regular expression to include URLs in the DataDome analyzed traffic | Optional | |
| DomeURIRegexExclusion | Regular expression to exclude URLs from being inspected by DataDome | Optional | |
| DomeStaticAssetExclusion | Regular expression with excluded static assets | Optional | list below |
| DomeEncodedCharInclusion | Regular expression to force the inspection of static-looking paths containing one of the listed encoded characters | Optional | "%23|%25|%2f|%3b|%3f" |
| DomeRemoveMatrixParams | Strip matrix parameters (;...) as documented by RFC 3986 per path segment before the exclusion regex | Optional | On |
| DomeTimeOut | The request timeout to DataDome API for new connections, in milliseconds Not supported since 2.46 | Optional | 100 |
| DomeRequestTimeOut | The request timeout to DataDome API for reused connections, in milliseconds Also used for new connections since 2.44 | Optional | 150 |
"\.(avi|avif|bmp|css|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|json|less|map|mka|mkv|mov|mp3|mp4|mpeg|mpg|ogg|ogm|opus|otf|png|svg|svgz|swf|ttf|wav|webm|webp|woff|woff2|xml|zip)$"
Starting with version 2.30, all settings were renamedThe "Dome" prefix was added to all settings to avoid conflict with others modules.
DebugMode deprecated and replaced with standard Apache logging method
Param DebugModeis deprecated (since version 2.26).
You can use standard Apache logging method.
Starting with version 2.46, DomeTimeOut is no more supportedIt is replaced by
DomeRequestTimeOutwhich is used as "API request timeout for both new and reused connections in ms".
Upgrade guide
To upgrade, recompile and reinstall the module from the latest package:
wget https://package.datadome.co/linux/DataDome-Apache-latest.tgz
tar -zxvf DataDome-Apache-latest.tgz
cd DataDome-ApacheDome-*
make prepare && make && sudo make installRefer to the Apache changelog for release notes.
Breaking changes: 3.0.0
Split exclusion settings
Move any static-asset extensions out of DomeURIRegexExclusion :
DomeURIRegexExclusionnow holds only your own URL exclusions.DomeStaticAssetExclusion(new) holds static-asset extensions: standard list, on by default.
- DomeURIRegexExclusion="/health|/heartbeat|\.(avi|avif|bmp|css|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|json|less|map|mka|mkv|mov|mp3|mp4|mpeg|mpg|ogg|ogm|opus|otf|png|svg|svgz|swf|ttf|wav|webm|webp|woff|woff2|xml|zip)$"
+ DomeURIRegexExclusion="/health|/heartbeat"New checks
Enabled by default. Review each and opt out where needed.
- Matrix params (
DomeRemoveMatrixParams): like query params (?), we ignore matrix params (;) before matching. - Encoding (
DomeEncodedCharInclusion): we inspect static-looking paths containing one of%23 %25 %2f %3b %3f.
For more information, see Split exclusion settings and default checks.
FAQ
Do you provide a demo?
We provide a Dockerfile with the setup and the configuration to help you to integrate DataDome.
How can I add debug logging?
- Update the
LogLeveloption in themod_datadome.conffile :
LogLevel error datadome_shield:debug
Configuration for Apache 2.2On Apache 2.2, LogLevel is not supported for module. You must set LogLevel globally.
Example: LogLevel debug
How can I access Log with DataDome information?
- DataDome sets two variables that can be added to
CustomLog:%{DATA_DOME_STATUS}: status code return from API Server or specific code- 200: API Server allow hit
- 403: API Server disallow hit
- 502: problem while connecting to API Server
- 504: timeout while connecting to API Server
- 700: url is not handle by the module because it doesn't match with regex
- 701: module was disabled
- 702: license key was not setup
- 703: wrong module configuration
- 704: API server response hasn't got expected X-DataDomeResponse header
%{DATA_DOME_SPENT_TIME}: time in ms spent by the module
Use the following LogFormat to add DataDome variable at the end:
LogFormat "%h %l %u %t \"%r\" %{DATA_DOME_STATUS}e %{DATA_DOME_SPENT_TIME}e" datadome
CustomLog logs/datadome_log datadomeThis configuration must be defined in your VirtualHost or Apache configuration file:
- Debian / Ubuntu:
/etc/apache2/apache2.conf - RHEL / Centos:
/etc/httpd/conf/httpd.conf - SUSE:
/etc/apache2/httpd.conf
To define it in the module configuration, use the GlobalLog directive. It defines a log shared by the main server configuration and all defined virtual hosts.
How can I add Bot information in logs?
- Enrichment headers can be injected in WebServer logs.
- Below an example of how to use it:
LogFormat "%h %l %u %t \"%r\" %{X-DataDome-isbot}i %{X-DataDome-botname}i %{X-DataDome-ruletype}i %{X-DataDome-captchapassed}i %{DATA_DOME_SPENT_TIME}e" datadome
CustomLog logs/datadome.log datadomeHow can I compile on a custom Apache installation?
- In case of
Neigher apxs or apxs2 found, please set configure path, set the path inAPACHE_BUILD_PATHparameters.
make prepare APACHE_BUILD_PATH=/home/apachebuildpath
make APACHE_BUILD_PATH=/home/apachebuildpath
make install APACHE_BUILD_PATH=/home/apachebuildpathHow can I compile on a custom OpenSSL installation?
- To compile with an OpenSSL installation that is not on a configured path:
- Use
OPENSSL_DIRas a parameter for the Makefile.
- Use
make prepare OPENSSL_DIR=/usr/local/openssl
make OPENSSL_DIR=/usr/local/openssl
make install OPENSSL_DIR=/usr/local/openssl
Avoid mixing OpenSSL versionsWe recommend that you use the same OpenSSL version for both Apache and the ApacheDome module.
How can I check if DataDome module is loaded?
- Check if the module is correctly loaded by running
apachectl -t -D DUMP_MODULES.
What about firewall?
- The DataDome module needs to communicate with the DataDome API servers.
- Please allow traffic from your servers to api.datadome.co ports 80 and 443.
- DataDome use a Load Balancer with dynamic IP: do not create rules based on a static IP.
How can I add a custom header?
- The module sets
DATA_DOME_IS_URI_REGEX_MATCHEDvariable to1if request has matched and0if it hasn't. To setup a header:
Header set X-DD-Regex-Matched "1" env=DATA_DOME_IS_URI_REGEX_MATCHEDHow can I enable or disable the module for specified location or vhost?
You can either enable or disable the module for specified locations and virtual hosts by changing the DomeStatus variable:
- To disable the module:
<Location "/private1">
DomeStatus off
</Location><VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
DomeStatus off
# Other directives here
</VirtualHost- To enable the module:
DomeStatus off # disabled globally
<Location "/private1">
DomeStatus on
</Location>DomeStatus off # disabled globally
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
DomeStatus on
# Other directives here
</VirtualHostHow can I disable the module for specified query params or IP?
Apache is able to conditionally disable the module based on incoming request characteristics such as query parameters, IP addresses, or hostnames with regular expressions:
- Disable it by setting the
DATA_DOME_DISABLEenvironment variable:
RewriteEngine On
RewriteCond %{QUERY_STRING} REGEX_TO_MATCH_URL [OR]
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.2$ [OR]
RewriteCond %{HTTP_HOST} ^www\.exemple\.com$
RewriteRule ^(.*)$ - [E=DATA_DOME_DISABLE]- For a specified condition, use the following logic:
RewriteEngine On
RewriteRule ^(.*)$ - [E=DATA_DOME_DISABLE]
RewriteCond %{QUERY_STRING} REGEX_TO_MATCH_URL [OR]
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$ [OR]
RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.2$ [OR]
RewriteCond %{REMOTE_ADDR} ^192\.168\.0\. [OR]
RewriteCond %{HTTP_HOST} ^www\.exemple\.com$
RewriteRule ^(.*)$ - [E=!DATA_DOME_DISABLE]- For Apache 2.4+, use
Ifdirective.
<If "%{QUERY_STRING} =~ /REGEX_TO_MATCH/">
DomeStatus off
</If><<If "%{REMOTE_ADDR} =~ /^127\.0\.0\.1/ || %{REMOTE_ADDR} =~ /^192\.168\.0\./">
DomeStatus off
</If>How can I use our corporate proxy?
- Use your corporate proxy with our module by changing your configuration in
mod_datadome.conf:
# Protocol to connect to the proxy
DomeApiProtocol HTTP
# Proxy hostname or IP
DomeApiHost proxy-server
# Proxy port
DomeApiPort 3128
# DataDome API to connect to DataDome, this will be used by the proxy
# DomeApiURI https://api.datadome.co/validate-request/
How can I use other headers as source for client IP
- If a proxy or a Load Balancer is used and adds
someHeadercontaining client IP, please insert this value intoTrue-Client-IPorX-Forwarded-For:
SetEnvIfNoCase ^someHeader$ ^(.*)$ someHeader=$1
RequestHeader set "True-Client-IP" "%{someHeader}e" env=someHeaderUpdated 3 days ago

