Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

ModSecurity

> DevOps
Open source

ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx. It has a robust event-based programming language

9.7K stars0 likes1 views
WebsiteGitHub

About

ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx. It has a robust event-based programming language

Libmodsecurity is one component of the ModSecurity v3 project. The library codebase serves as an interface to ModSecurity Connectors taking in web traffic and applying traditional ModSecurity processing. In general, it provides the capability to load/interpret rules written in the ModSecurity SecRules format and apply them to HTTP content provided by your application via Connectors.

If you are looking for ModSecurity for Apache (aka ModSecurity v2.x), it is still under maintenance and available: here.

What is the difference between this project and the old ModSecurity (v2.x.x)?

  • All Apache dependencies have been removed
  • Higher performance
  • New features
  • New architecture

Libmodsecurity is a complete rewrite of the ModSecurity platform. When it was first devised the ModSecurity project started as just an Apache module. Over time the project has been extended, due to popular demand, to support other platforms including (but not limited to) Nginx and IIS. In order to provide for the growing demand for additional platform support, it has became necessary to remove the Apache dependencies underlying this project, making it more platform independent.

As a result of this goal we have rearchitected Libmodsecurity such that it is no longer dependent on the Apache web server (both at compilation and during runtime). One side effect of this is that across all platforms users can expect increased performance. Additionally, we have taken this opportunity to lay the groundwork for some new features that users have been long seeking. For example we are looking to natively support auditlogs in the JSON format, along with a host of other functionality in future versions.

It is no longer just a module.

The 'ModSecurity' branch no longer contains the traditional module logic (for Nginx, Apache, and IIS) that has traditionally been packaged all together. Instead, this branch only contains the library portion (libmodsecurity) for this project. This library is consumed by what we have termed 'Connectors' these connectors will interface with your webserver and provide the library with a common format that it understands. Each of these connectors is maintained as a separate GitHub project. For instance, the Nginx connector is supplied by the ModSecurity-nginx project (https://github.com/owasp-modsecurity/ModSecurity-nginx).

Keeping these connectors separated allows each project to have different release cycles, issues and development trees. Additionally, it means that when you install ModSecurity v3 you only get exactly what you need, no extras you won't be using.

Compilation

Before starting the compilation process, make sure that all required dependencies are installed.
See the Dependencies and Git submodules section for further information.

After compilation, make sure that there are no issues on your build/platform.
We strongly recommend running the unit tests and regression tests. These test utilities are located in the tests/ subfolder.

As a dynamic library, libmodsecurity must be installed in a location where your operating system can find dynamic libraries.

Unix (Linux, macOS, FreeBSD, …)

On Unix-like systems, the project uses autotools for the compilation process.

If you are working with a git checkout, make sure to clone the repository recursively or initialize all submodules before building.
See also the Git submodules section.

bash
git clone https://github.com/owasp-modsecurity/ModSecurity ModSecurity
cd ModSecurity

This repository uses git submodules. After cloning, make sure to initialize and fetch all submodules:

bash
git submodule update --init --recursive

You can verify that all submodules are properly initialized with:

bash
git submodule status

Submodules that are correctly initialized show a commit hash. A leading - indicates that the submodule has not been initialized.

You can then start the build process:

bash
./build.sh
./configure
make
sudo make install

Details on distribution-specific builds can be found in our Wiki: Compilation Recipes

Windows

Windows build information can be found here.

Dependencies

  • This library is written in C++ using the C++17 standard.
  • It uses Flex and Bison (Yacc) to produce the “Sec Rules Language” parser.
  • Mandatory dependencies include YAJL, as ModSecurity uses JSON for logging and its testing framework.
  • libXML2 (optional) is used for parsing XML requests.

Regular expression engine (PCRE2 / PCRE)

  • Regular expression processing in SecRules is implemented via the Regex utility (src/utils/regex.*).

  • By default, ModSecurity uses PCRE2 for regex handling.

  • This is used by operators such as @rx, @rxGlobal, and @verifyCC.

  • Build-time behavior:

    • Default: PCRE2 is detected and used.
    • Fallback: legacy PCRE can be used if --with-pcre is explicitly provided (WITH_PCRE).
  • In other words, current builds expect PCRE2 unless explicitly configured otherwise.

All other dependencies are related to operators specified within SecRules or configuration directives and may not be required for compilation.

Operator-related dependencies

  • libinjection is required for the operators @detectXSS and @detectSQL.
  • curl is required for the directive SecRemoteRules.

If those libraries are missing, ModSecurity will be compiled without support for the respective operators or directives.

Git-submodules

The repository includes the following submodules:

  • others/libinjection – used by @detectSQLi and @detectXSS operators.

  • others/mbedtls (TF-PSA-Crypto subset) – used for cryptographic functions and helpers (e.g. hashing, base64).

    Note: The newer mbedTLS v4 layout is not compatible with the older v3 structure. The internal structure has changed significantly, and many components have been moved into submodules (e.g. TF-PSA-Crypto).

    After merging PR #3532, it is required to run:

    bash
    git submodule update --init --recursive

    This ensures that all required submodules are fetched. Without this step, the project will not build successfully.

    You can verify that all submodules are properly initialized with:

    bash
    git submodule status

    Example output:

    bash
    bc625d5... bindings/python
    2117822... others/libinjection (v4.0.0)
    0fe989b... others/mbedtls (v4.1.0)
    a3d4405... test/test-cases/secrules-language-tests

    If a submodule is missing, it will be shown with a leading -, for example:

    bash
    -bc625d5... bindings/python

    A leading - indicates that the submodule has not been initialized or fetched.

  • test/test-cases/secrules-language-tests – shared SecRules conformance and regression test suite used by make check.

  • bindings/python – Python bindings for ModSecurity (not required for core library compilation).

others/libinjection and others/mbedtls are effectively required for source builds and must be initialized before building.

Optional external dependencies

Several external libraries are optional and enable additional features, including:

  • libcurl – required for SecRemoteRules

  • LMDB – persistent storage support

  • Lua – scripting support

  • XML libraries – extended XML processing

  • GeoIP (legacy) / MaxMind

    The legacy GeoIP C API (libGeoIP) is deprecated and no longer maintained by MaxMind. The upstream repository has been archived and should not be used for new deployments.

    Instead, ModSecurity supports the modern MaxMind DB API (libmaxminddb), which is actively maintained.

    During configuration you may see something like:

    bash
    + GeoIP/MaxMind                                 ....found
        * (MaxMind) v1.12.2
           -lmaxminddb , -I/usr/include/x86_64-linux-gnu

    This indicates that libmaxminddb is being used (recommended).

    It is strongly recommended to use MaxMind DB instead of the legacy GeoIP library.

Library documentation

The library documentation is written within the code in Doxygen format. To generate this documentation, please use the doxygen utility with the provided configuration file, “doxygen.cfg”, located with the "doc/" subfolder. This will generate HTML formatted documentation including usage examples.

Library utilization

The library provides a C++ and C interface. Some resources are currently only available via the C++ interface, for instance, the capability to create custom logging mechanism (see the regression test to check for how those logging mechanism works). The objective is to have both APIs (C, C++) providing the same functionality, if you find an aspect of the API that is missing via a particular interface, please open an issue.

Inside the subfolder examples, there are simple examples on how to use the API. Below some are illustrated:

Simple example using C++

cpp
using ModSecurity::ModSecurity;
using ModSecurity::Rules;
using ModSecurity::Transaction;

ModSecurity *modsec;
ModSecurity::Rules *rules;

modsec = new ModSecurity();

rules = new Rules();

rules->loadFromUri(rules_file);

Transaction *modsecTransaction = new Transaction(modsec, rules);

modsecTransaction->processConnection("127.0.0.1");
if (modsecTransaction->intervention()) {
   std::cout << "There is an intervention" << std::endl;
}

Simple example using C

…

Contributing

You are more than welcome to contribute to this project and look forward to growing the community around this new version of ModSecurity. Areas of interest include: New functionalities, fixes, bug report, support for beginning users, or anything that you are willing to help with.

Providing patches

We prefer to have your patch within the GitHub infrastructure to facilitate our review work, and our Q.A. integration. GitHub provides excellent documentation on how to perform “Pull Requests”, more information available here: https://help.github.com/articles/using-pull-requests/

Please respect the coding style. Pull requests can include various commits, so provide one fix or one piece of functionality per commit. Please do not change anything outside the scope of your target work (e.g. coding style in a function that you have passed by). For further information about the coding style used in this project, please check: https://www.chromium.org/blink/coding-style

Provides explanative commit messages. Your first line should give the highlights of your patch, 3rd and on give a more detailed explanation/technical details about your patch. Patch explanation is valuable during the review process.

Don’t know where to start?

Within our code there are various items marked as TODO or FIXME that may need your attention. Check the list of items by performing a grep:

$ cd /path/to/modsecurity-nginx
$ egrep -Rin "TODO|FIXME" -R *

A TODO list is also available as part of the Doxygen documentation.

Testing your patch

Along with the manual testing, we strongly recommend you to use the our regression tests and unit tests. If you have implemented an operator, don’t forget to create unit tests for it. If you implement anything else, it is encouraged that you develop complimentary regression tests for it.

The regression test and unit test utilities are native and do not demand any external tool or script, although you need to fetch the test cases from other repositories, as they are shared with other versions of ModSecurity, those others repositories git submodules. To fetch the submodules repository and run the utilities, follow the commands liste

Issues· 356 open

View all issuesOpen on GitHub
  • #3604

    Windows build fails: yajl's Conan recipe sets CMP0026 OLD, incompatible with newer CMake

    3.xwindowsUpdated Sep 17, 2026
  • #3630

    IIS: IPv6 link-local client addresses break IP matching ("IPmatch: bad IPv6 specification")

    Platform - IIS2.xUpdated Sep 17, 2026
  • #3619

    IIS: Content-Length header corrupted/truncated for large responses (wrong printf format + off-by-one buffer size)

    Platform - IIS2.xUpdated Sep 15, 2026
  • #3621

    IIS: Host header fallback is dead code (r->hostname == NULL can never be true)

    Platform - IIS2.xUpdated Sep 15, 2026
  • #3501

    Feature Request: Add `ARGS_RAW`, `ARGS_GET_RAW`, `ARGS_POST_RAW`, and `ARGS_NAMES_RAW` Variables

    new featureUpdated Sep 11, 2026
  • #3563

    REQBODY_ERROR "Extra content at the end of the document" after 3.0.15 update

    3.xUpdated Sep 11, 2026
  • #3131

    @rbl operator does not support IPv6

    bug2.x3.xduplicate:1st_place_medal: good first issueUpdated Aug 31, 2026
  • #3623

    IIS: ReadFileChunk allocates only 1 byte but reads m_dwPageSize (latent overflow)

    Platform - IIS2.xUpdated Aug 27, 2026
  • #3308

    Drop YAJL dependency

    2.x3.xUpdated Aug 24, 2026
  • #3609

    libModSecurity3: REQUEST_HEADERS names are treated as case sensitive with configure-time rule-exclusions

    3.x:1st_place_medal: good first issueUpdated Aug 23, 2026

> Tags

C++apacheapache2modsecuritynginx

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理