• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H05-Jul-2021-173131

bindings/python/H05-Jul-2021-260168

build/H07-Jul-2021-11,53310,404

doc/H03-May-2022-3,0032,382

examples/H07-Jul-2021-6,0614,960

headers/modsecurity/H05-Jul-2021-4,0242,375

others/H03-May-2022-36,62529,989

src/H07-Jul-2021-74,61754,409

test/H03-May-2022-65,45963,632

tools/H07-Jul-2021-1,7521,518

.gitignoreH A D05-Jul-2021874 5150

.gitmodulesH A D05-Jul-2021404 109

AUTHORSH A D05-Jul-2021202 54

CHANGESH A D07-Jul-202118.7 KiB459441

LICENSEH A D05-Jul-202111.1 KiB202169

Makefile.amH A D05-Jul-202117.8 KiB351323

Makefile.inH A D07-Jul-2021173.5 KiB3,4123,262

README.mdH A D05-Jul-202112.3 KiB277186

aclocal.m4H A D07-Jul-202156.8 KiB1,5901,435

ar-libH A D07-Jul-20215.7 KiB272211

build.shH A D05-Jul-2021273 149

compileH A D07-Jul-20217.2 KiB349259

config.guessH A D07-Jul-202147.9 KiB1,6871,476

config.subH A D07-Jul-202133.4 KiB1,8541,677

configureH A D07-Jul-2021744.1 KiB25,18121,057

configure.acH A D05-Jul-202116.5 KiB616489

depcompH A D07-Jul-202123 KiB792502

install-shH A D07-Jul-202115 KiB542352

ltmain.shH A D07-Jul-2021323.5 KiB11,3708,157

missingH A D07-Jul-20216.7 KiB216143

modsecurity.conf-recommendedH A D05-Jul-202110.3 KiB271222

modsecurity.pc.inH A D05-Jul-2021377 1210

test-driverH A D07-Jul-20214.6 KiB15188

unicode.mappingH A D05-Jul-202151.9 KiB9760

ylwrapH A D07-Jul-20216.7 KiB248143

README.md

1
2<img src="https://github.com/SpiderLabs/ModSecurity/raw/v3/master/others/modsec.png" width="50%">
3
4![Quality Assurance](https://github.com/SpiderLabs/ModSecurity/workflows/Quality%20Assurance/badge.svg)
5[![Build Status](https://sonarcloud.io/api/project_badges/measure?project=USHvY32Uy62L&metric=alert_status)](https://sonarcloud.io/dashboard?id=USHvY32Uy62L)
6[![](https://sonarcloud.io/api/project_badges/measure?project=USHvY32Uy62L&metric=sqale_rating
7)](https://sonarcloud.io/dashboard?id=USHvY32Uy62L)
8[![](https://sonarcloud.io/api/project_badges/measure?project=USHvY32Uy62L&metric=reliability_rating
9)](https://sonarcloud.io/dashboard?id=USHvY32Uy62L)
10[![](https://sonarcloud.io/api/project_badges/measure?project=USHvY32Uy62L&metric=security_rating
11)](https://sonarcloud.io/dashboard?id=USHvY32Uy62L)
12[![](https://sonarcloud.io/api/project_badges/measure?project=USHvY32Uy62L&metric=vulnerabilities
13)](https://sonarcloud.io/dashboard?id=USHvY32Uy62L)
14
15
16
17Libmodsecurity is one component of the ModSecurity v3 project. The library
18codebase serves as an interface to ModSecurity Connectors taking in web traffic
19and applying traditional ModSecurity processing. In general, it provides the
20capability to load/interpret rules written in the ModSecurity SecRules format
21and apply them to HTTP content provided by your application via Connectors.
22
23If you are looking for ModSecurity for Apache (aka ModSecurity v2.x), it is still under maintenance and available:
24[here](https://github.com/SpiderLabs/ModSecurity/tree/v2/master).
25
26### What is the difference between this project and the old ModSecurity (v2.x.x)?
27
28* All Apache dependencies have been removed
29* Higher performance
30* New features
31* New architecture
32
33Libmodsecurity 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.
34
35As 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.
36
37
38### It is no longer just a module.
39
40The '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/SpiderLabs/ModSecurity-nginx).
41
42Keeping 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.
43
44# Compilation
45
46Before starting the compilation process, make sure that you have all the
47dependencies in place. Read the subsection “Dependencies”  for further
48information.
49
50After the compilation make sure that there are no issues on your
51build/platform. We strongly recommend the utilization of the unit tests and
52regression tests. These test utilities are located under the subfolder ‘tests’.
53
54As a dynamic library, don’t forget that libmodsecurity must be installed to a location (folder) where you OS will be looking for dynamic libraries.
55
56
57
58### Unix (Linux, MacOS, FreeBSD, …)
59
60On unix the project uses autotools to help the compilation process.
61
62```shell
63$ ./build.sh
64$ ./configure
65$ make
66$ sudo make install
67```
68
69Details on distribution specific builds can be found in our Wiki:
70[Compilation Recipes](https://github.com/SpiderLabs/ModSecurity/wiki/Compilation-recipes)
71
72### Windows
73
74Windows build is not ready yet.
75
76
77## Dependencies
78
79This library is written in C++ using the C++11 standards. It also uses Flex
80and Yacc to produce the “Sec Rules Language” parser. Other, mandatory dependencies include YAJL, as ModSecurity uses JSON for producing logs and its testing framework, libpcre (not yet mandatory) for processing regular expressions in SecRules, and libXML2 (not yet mandatory) which is used for parsing XML requests.
81
82All others dependencies are related to operators specified within SecRules or configuration directives and may not be required for compilation. A short list of such dependencies is as follows:
83
84* libinjection is needed for the operator @detectXSS and @detectSQL
85* curl is needed for the directive SecRemoteRules.
86
87If those libraries are missing ModSecurity will be compiled without the support for the operator @detectXSS and the configuration directive SecRemoteRules.
88
89# Library documentation
90
91The 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.
92
93# Library utilization
94
95The library provides a C++ and C interface. Some resources are currently only
96available via the C++ interface, for instance, the capability to create custom logging
97mechanism (see the regression test to check for how those logging mechanism works).
98The objective is to have both APIs (C, C++) providing the same functionality,
99if you find an aspect of the API that is missing via a particular interface, please open an issue.
100
101Inside the subfolder examples, there are simple examples on how to use the API.
102Below some are illustrated:
103
104###  Simple example using C++
105
106```c++
107using ModSecurity::ModSecurity;
108using ModSecurity::Rules;
109using ModSecurity::Transaction;
110
111ModSecurity *modsec;
112ModSecurity::Rules *rules;
113
114modsec = new ModSecurity();
115
116rules = new Rules();
117
118rules->loadFromUri(rules_file);
119
120Transaction *modsecTransaction = new Transaction(modsec, rules);
121
122modsecTransaction->processConnection("127.0.0.1");
123if (modsecTransaction->intervention()) {
124   std::cout << "There is an intervention" << std::endl;
125}
126```
127
128### Simple example using C
129
130```c
131#include "modsecurity/modsecurity.h"
132#include "modsecurity/transaction.h"
133
134
135char main_rule_uri[] = "basic_rules.conf";
136
137int main (int argc, char **argv)
138{
139    ModSecurity *modsec = NULL;
140    Transaction *transaction = NULL;
141    Rules *rules = NULL;
142
143    modsec = msc_init();
144
145    rules = msc_create_rules_set();
146    msc_rules_add_file(rules, main_rule_uri);
147
148    transaction = msc_new_transaction(modsec, rules);
149
150    msc_process_connection(transaction, "127.0.0.1");
151    msc_process_uri(transaction, "http://www.modsecurity.org/test?key1=value1&key2=value2&key3=value3&test=args&test=test");
152    msc_process_request_headers(transaction);
153    msc_process_request_body(transaction);
154    msc_process_response_headers(transaction);
155    msc_process_response_body(transaction);
156
157    return 0;
158}
159
160```
161
162# Contributing
163
164You 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
165functionalities, fixes, bug report, support for beginning users, or anything that you
166are willing to help with.
167
168## Providing patches
169
170We prefer to have your patch within the GitHub infrastructure to facilitate our
171review work, and our Q.A. integration. GitHub provides excellent
172documentation on how to perform “Pull Requests”, more information available
173here: https://help.github.com/articles/using-pull-requests/
174
175Please respect the coding style. Pull requests can include various commits, so
176provide one fix or one piece of functionality per commit. Please do not change anything outside
177the scope of your target work (e.g. coding style in a function that you have
178passed by). For further information about the coding style used in this
179project, please check: https://www.chromium.org/blink/coding-style
180
181Provides explanative commit messages. Your first line should  give the highlights of your
182patch, 3rd and on give a more detailed explanation/technical details about your
183patch. Patch explanation is valuable during the review process.
184
185### Don’t know where to start?
186
187Within our code there are various items marked as TODO or FIXME that may need
188your attention. Check the list of items by performing a grep:
189
190```
191$ cd /path/to/modsecurity-nginx
192$ egrep -Rin "TODO|FIXME" -R *
193```
194
195A TODO list is also available as part of the Doxygen documentation.
196
197### Testing your patch
198
199Along with the manual testing, we strongly recommend you to use the our
200regression tests and unit tests. If you have implemented an operator, don’t
201forget to create unit tests for it. If you implement anything else, it is encouraged that you develop complimentary regression tests for it.
202
203The regression test and unit test utilities are native and do not demand any
204external tool or script, although you need to fetch the test cases from other
205repositories, as they are shared with other versions of ModSecurity, those
206others repositories git submodules. To fetch the submodules repository and run
207the utilities, follow the commands listed below:
208
209```shell
210$ cd /path/to/your/ModSecurity
211$ git submodule foreach git pull
212$ cd test
213$ ./regression-tests
214$ ./unit-tests
215 ```
216
217### Debugging
218
219
220Before start the debugging process, make sure of where your bug is. The problem
221could be on your connector or in libmodsecurity. In order to identify where the
222bug is, it is recommended that you develop a regression test that mimics the
223scenario where the bug is happening. If the bug is reproducible with the
224regression-test utility, then it will be far simpler to debug and ensure that it never occurs again. On Linux it is
225recommended that anyone undertaking debugging utilize gdb and/or valgrind as needed.
226
227During the configuration/compilation time, you may want to disable the compiler
228optimization making your “back traces” populated with readable data. Use the
229CFLAGS to disable the compilation optimization parameters:
230
231```shell
232$ export CFLAGS="-g -O0"
233$ ./build.sh
234$ ./configure
235$ make
236$ sudo make install
237```
238
239
240## Reporting Issues
241
242If you are facing a configuration issue or something is not working as you
243expected to be, please use the ModSecurity user’s mailing list. Issues on GitHub
244are also welcomed, but we prefer to have user ask questions on the mailing list first so that you can reach an entire community. Also don’t forget to look for existing issues before open a new one.
245
246If you are going to open a new issue on GitHub, don’t forget to tell us the
247version of your libmodsecurity and the version of a specific connector if there
248is one.
249
250
251### Security issue
252
253Please do not make public any security issue. Contact us at:
254security@modsecurity.org reporting the issue. Once the problem is fixed your
255credit will be given.
256
257## Feature request
258
259We are open to discussing any new feature request with the community via the mailing lists. You can alternativly,
260feel free to open GitHub issues requesting new features. Before opening a
261new issue, please check if there is one already opened on the same topic.
262
263## Bindings
264
265The libModSecurity design allows the integration with bindings. There is an effort to avoid breaking API [binary] compatibility to make an easy integration with possible bindings. Currently, there are two notable projects maintained by the community:
266   * Python - https://github.com/actions-security/pymodsecurity
267   * Varnish - https://github.com/xdecock/vmod-modsecurity
268
269## Packaging
270
271Having our packages in distros on time is a desire that we have, so let us know
272if there is anything we can do to facilitate your work as a packager.
273
274## Sponsor Note
275
276Development of ModSecurity is sponsored by Trustwave. Trustwave offers a Commercial Ruleset for ModSecurity to Large Enterprise customers. Contact the Trustwave sales department for more information
277