2853 Commits

Author SHA1 Message Date
WGH
9e32945bc4
Add proper error handling to @rx operator 2019-02-11 10:25:25 -03:00
WGH
9c3c4dc587
Update operator verifyCC to use Regex class 2019-02-11 10:25:25 -03:00
WGH
55b81f0e10
Refactor Regex classes further
This commit changes Regex interface rather dramatically.

Most importantly, RegexMatch class now contains a list of matched groups,
with group(0) being entire match, group(1) - first capturing group,
and so on.

Secondly, searchAll now returns a list of RegexMatch objects instead
of reversed flattened list of groups from all matches.
2019-02-11 10:25:24 -03:00
WGH
a2dc896520
Fix build/re2.m4 file lookup
There's no such include file as "re2/re2_parse.h",
and there was a typo in RE2_POSSIBLE_PATHS.
2019-02-11 10:25:24 -03:00
WGH
d349fa0c56
Enable RE2 testing with Travis
Ubuntu 14.04 doesn't have RE2 package altogether,
and Ubuntu 16.04 RE2 package is too old.

Ubuntu 18.04 RE2 package might work, but this Ubuntu verison it's not
supported by Travis yet.

So build RE2 from source.
2019-02-11 10:25:24 -03:00
WGH
211c081c7d
Implement RE2 fallback to libpcre
RE2 doesn't support certain features, like negative lookaround,
so when a regular expression cannot be compiled with RE2, it's
compiled with libpcre instead.

This has some runtime cost, as this fallback is implemented
with an extra heap object and virtual function calls.

When RE2 is not enabled, however, everything works as it did before.
2019-02-11 10:25:24 -03:00
WGH
8c7e71b22a
Add RE2 regex backend 2019-02-11 10:25:24 -03:00
WGH
0e0d182c67
Fix Pcre::searchAll behaviour wrt empty capturing groups
Previously, searchAll would stop search when it encountered an empty
matching group in any position. This means that, for example,
regular expression "(a)(b?)(c)" would match string "ac", but the
resulting group list would be ["ac", "a"].

After this change, the resulting list for the aforementioned regular
expression becomes ["ac", "a", "", "c"] like it should've been.

Additionally, this also changes behaviour for multiple matches. For
example, when "aaa00bbb" is matched by "[a-z]*", previously only "aaa"
would be returned. Now the matching list is ["aaa", "", "", "bbb", ""].

The old behaviour was confusing and almost certainly a bug. The new
behaviour is the same as in Python's re.findall.

For reference, though, Go does it somewhat differently: empty matches
at the end of non-empty matches are ignored, so in Go above example is
["aaa", "", "bbb"] instead.
2019-02-11 10:25:24 -03:00
WGH
cce85c4d31
Add support for capturing group test cases
This enables unit tests to compare the matching groups as well,
not just binary match-no match.
2019-02-11 10:25:24 -03:00
Felipe Zimmerle
22136788c8
Makes re2 detectable by the build scripts 2019-02-11 10:25:23 -03:00
Felipe Zimmerle
a5ee59f5d0
regex: Organizes the classes per file
moves Pcre to backends/pcre.cc
moves PegexMatch to regex_match.h
2019-02-11 10:25:23 -03:00
Felipe Zimmerle
686b6ffff7
Removes unecessary static methods from regex class 2019-02-11 10:25:23 -03:00
Felipe Zimmerle
57fc3b5084
Renames SMatch to RegexMatch 2019-02-11 10:25:23 -03:00
Felipe Zimmerle
d3f9974d52
Moving regex from utils to its own namespace 2019-02-11 10:25:23 -03:00
Felipe Zimmerle
3dda0ea2c6
Adds a regression test strdup to valgrind suppressions list 2019-02-11 10:22:28 -03:00
Felipe Zimmerle
2dff768262
Removes a memory leak on the JSON parser 2019-02-11 10:17:02 -03:00
Felipe Zimmerle
145f2f35b7
tests: Updates secrules-language-tests 2019-02-05 11:26:03 -03:00
Felipe Zimmerle
f77db2cc2e
CHANGES: dds info about #2011 2019-01-28 16:43:31 -03:00
WGH
bd6a02d69b
Fix test issue-1831.json on LMDB
When LMDB is enabled, ModSecurity stores its persistent variables in
"./modsec-shared-collections" file. Since this file wasn't cleared between
tests, tests behaved differently on "in-memory per-process" and LMDB backend.

This test never worked in LMDB configuration. It hasn't been discovered
until now because Travis CI didn't test LMDB configuration when test was
introduced.
2019-01-28 16:20:02 -03:00
WGH
37cf60b8d2
Fix use of deleted Regex copy constructor in LMDB code
Bug introduced in ad28de4f. Fixes #2008.
2019-01-28 16:20:02 -03:00
WGH
79a24ef88d
Enable LMDB in Travis CI configuration
LMBD is not built by default since 6143eb9,
so add explicit --with-lmdb configuration.

Missing --with-lmdb build allowed a bug in PR #2003 to pass
through, causing issue #2008.
2019-01-28 16:20:01 -03:00
Felipe Zimmerle
dc78c0e180
Fix: Extra whitespace in some configuration directives causing error
Issue #2006
2019-01-21 14:44:31 -03:00
Felipe Zimmerle
df3c3f62b7 Cosmetics: coding style 2019-01-18 11:02:22 -03:00
WGH
ad28de4f14 Refactor regex code
This commit fixes quite a few odd things in regex code:
 * Lack of encapsulation.
 * Non-method functions for matching without retrieving all groups.
 * Regex class being copyable without proper copy-constructor (potential UAF
   and double free due to pointer members m_pc and m_pce).
 * Redundant SMatch::m_length, which always equals to match.size() anyway.
 * Weird SMatch::size_ member which is initialized only by one of the three matching
   functions, and equals to the return value of that function anyways.
 * Several places in code having std::string value instead of reference.
2019-01-18 10:34:01 -03:00
Felipe Zimmerle
e0a0fa05cc
CHANGES: Info on #2002 2019-01-14 16:29:48 -03:00
Andrei Belov
ae02076340
Fixed buffer overflow in Utils::Md5::hexdigest()
Found via failed test (auditlog.json) on Alpine Linux 3.8.2.
2019-01-14 16:29:07 -03:00
Felipe Zimmerle
3c1fba278c
CHANGES: Adds info about #1990 2019-01-08 10:35:33 -03:00
Andrei Belov
7c19ffea64
Implemented merge_bodylimitaction_value() for BodyLimitAction
This change makes the following directives to be merged properly:

SecRequestBodyLimitAction
SecResponseBodyLimitAction
2019-01-08 10:34:22 -03:00
Andrei Belov
3c41751eda
Implemented merge_ruleengine_value() for RuleEngine
This change makes the SecRuleEngine directive to be merged properly.
2019-01-08 10:34:22 -03:00
Andrei Belov
161c256333
Implemented merge_boolean_value() for ConfigBoolean
This change makes the following directives to be merged properly:

SecRequestBodyAccess
SecResponseBodyAccess
SecXmlExternalEntity
SecUploadKeepFiles
SecTmpSaveUploadedFiles
2019-01-08 10:34:22 -03:00
Andrei Belov
2d11ff1a14
Implemented merge() method for ConfigInt, ConfigDouble, ConfigString
This change makes the following directives to be merged properly:

SecRequestBodyLimit
SecResponseBodyLimit
SecUploadFileLimit
SecUploadFileMode
SecUploadDir
SecTmpDir
SecArgumentSeparator
SecWebAppId
SecHttpBlKey
2019-01-08 10:34:22 -03:00
Felipe Zimmerle
78b7fa4e2c
Adds missing drop.h 2018-12-26 11:05:54 -03:00
Felipe Zimmerle
d00ea5111d
Adds initial support to drop action 2018-12-24 16:35:41 -03:00
Felipe Zimmerle
ba4273b8ec
CHANGES: Adds info on #1978 2018-12-24 13:59:21 -03:00
Andrei Belov
9b24199a22
Complete merging of particular rule properties
Closes SpiderLabs/ModSecurity-nginx#142 issue.
2018-12-24 13:58:28 -03:00
Felipe Zimmerle
4283883695
CHANGES: Adds info on #1984 2018-12-17 10:21:25 -03:00
chuckwolber
8af8cad907
Use of AC_CHECK_FILE prevents cross compilation.
The use of AC_CHECK_FILE causes the following error when cross compiling:

  configure: error: cannot check for file existence when cross compiling

The solution is to check for the file directly instead of using a macro.

Resolves: #1983
2018-12-17 10:19:55 -03:00
Felipe Zimmerle
a9e9da8694
CHANGES: Adds info on #1980 2018-12-10 15:09:09 -03:00
Ervin Hegedus
77854ed1b5
Fix inet addr handling on 64 bit big endian systems 2018-12-10 15:03:09 -03:00
Felipe Zimmerle
dccb5e9e5f
GitHub: Adds issue template 2018-12-05 14:54:43 -03:00
Felipe Zimmerle
1ecd971306
CHANGES: Updates issue #1973 2018-12-04 10:50:16 -03:00
Andrei Belov
0a85b599b6
Fix tests on FreeBSD
FreeBSD has different prefix for bash (which is non-standard shell there),
thus "make check-TESTS" actually was doing nothing:

$ gmake check-TESTS
(   0/  0/   0): test/test-cases/regression/issue-1591.json
(   0/  0/   0): test/test-cases/regression/issue-1785.json
(   0/  0/   0): test/test-cases/regression/issue-1812.json
(   0/  0/   0): test/test-cases/regression/issue-1831.json
(   0/  0/   0): test/test-cases/regression/issue-1844.json
(   0/  0/   0): test/test-cases/regression/issue-1850.json
[..]
Testsuite summary for modsecurity 3.0
2018-12-04 10:49:25 -03:00
Felipe Zimmerle
e756dd039d
README: Adds link to v2 repo
Making a reference to v2/repo.
2018-12-03 09:06:28 -03:00
Felipe Zimmerle
07330e53f1
CHANGES: Updates issue #1969 2018-11-29 21:49:41 -03:00
Felipe Zimmerle
25bb1f1bcc
Changes ENV test case to read the default MODSECURTIY env var 2018-11-29 15:21:28 -03:00
Felipe Zimmerle
b736f0292d
Regression: Sets MODSECURITY env var during the tests execution 2018-11-29 15:19:58 -03:00
Felipe Zimmerle
407b6c0f4b
Fix setenv action to strdup key=variable 2018-11-29 15:18:15 -03:00
Felipe Zimmerle
af137442d5
CHANGES: Adds @steven-j-wojcik to 0xb7c36 and 0x5ac20. 2018-11-29 13:31:46 -03:00
Felipe Zimmerle
d2b14de268
Allow 0 length JSON requests
As discussed at: #1822
2018-11-29 10:39:46 -03:00
Felipe Zimmerle
d29f2a8986
CHANGES: Adds info about #1966 2018-11-29 10:00:38 -03:00