625 Commits

Author SHA1 Message Date
Ervin Hegedus
d8574c8c08
Fix date format pattern in auditlog's regression test 2025-08-01 11:38:39 +02:00
Ervin Hegedus
79d55037c0
Refactoring the cleaning of MATCHED_VAR* variables 2025-07-25 14:33:24 +02:00
Ervin Hegedus
6089b6b06b
Fix @pmFromFile with multiple files issue 2025-06-19 21:49:05 +02:00
Tilman Keskinöz
de624f9460
Attempt to fix bogus change.
Reported by: CI via Ervin Hegedus
2025-05-23 10:28:38 +02:00
Tilman Keskinöz
0bcabf3208
buildfix for srcdir != builddir 2025-05-22 18:59:51 +02:00
Ervin Hegedus
aab47091b1
Merge pull request #3364 from JakubOnderka/json-logging
Simplify code for JSON audit log
2025-05-11 10:54:47 +02:00
Ervin Hegedus
89442ede16
Change directives in tests; add multibyte test case 2025-04-28 22:35:22 +02:00
Ervin Hegedus
0b62b7eb85
Align debug messages to fix regression tests 2025-04-27 21:09:49 +02:00
Jakub Onderka
6408bf9237 Test for JSON audit log 2025-04-22 21:09:42 +02:00
Ervin Hegedus
9e41a53760
Finish XMLArgs processing in v3 2025-04-20 18:21:28 +02:00
Ervin Hegedus
1a2b13967f
Merge pull request #3321 from gberkes/refactor/default-pcre2
Refactor/default pcre2
2025-03-12 18:16:35 +01:00
Ervin Hegedus
c82e831b66
fix: fixed htmlEntityDecode methods 2025-02-24 16:44:17 +01:00
Gabor Berkes
e92507868e Fix macOS GitHub Actions build: add PCRE2_CFLAGS/LDADD/LDFLAGS
Introduced PCRE2_CFLAGS, PCRE2_LDADD, and PCRE2_LDFLAGS in all relevant Makefile.am files to align with the existing PCRE_* variable usage. This change addresses potential issues with linking and configuration for builds on macOS GitHub runners.

These modifications aim to resolve the build failure observed exclusively in the macOS environment while maintaining compatibility across other platforms. Testing will confirm if this adjustment corrects the issue.
2024-12-11 12:48:20 +00:00
Ervin Hegedus
daf550ef5f
Fix regex for test 2024-11-24 14:06:50 +01:00
Ervin Hegedus
db7e4cb67b
Align TIME_MON variable's behavior 2024-11-23 10:58:35 +01:00
Ervin Hegedus
41fd21b0fb
Merge pull request #3298 from airween/v3/sethostnamefix
Fix m_requestHostName variable behavior
2024-11-19 20:49:00 +00:00
Ervin Hegedus
d422b36966
Add condition before set hostname; move setRequestHostName() before processConnection() 2024-11-12 16:55:02 +01:00
Hiroaki Nakamura
42a401892b
Fix modsecurity-regression-test-secremoterules.txt URL in example 2024-11-06 14:33:28 +09:00
Hiroaki Nakamura
742f97ccc0
Add regression rules for test
Copied from:
- faa96c7838/modsecurity-regression-rules.txt
- b9321f190e/modsecurity-regression-ip-list.txt

diff --git a/test/test-cases/regression/operator-ipMatchFromFile.json b/test/test-cases/regression/operator-ipMatchFromFile.json
index 4a225954..1eb4d44a 100644
--- a/test/test-cases/regression/operator-ipMatchFromFile.json
+++ b/test/test-cases/regression/operator-ipMatchFromFile.json
@@ -129,7 +129,7 @@
     },
     "rules":[
       "SecRuleEngine On",
-      "SecRule REMOTE_ADDR \"@ipMatchFromFile b9321f190e/modsecurity-regression-ip-list.txt\" \"id:1
2024-11-02 20:17:24 +09:00
Eduardo Arias
b0497d9cb9 Avoid this unnecessary copy by using a "const" reference.
- Reported by Sonarcloud
2024-10-19 15:27:39 -03:00
Eduardo Arias
bbef22b3b5 Added const reported by cppcheck 2.14 2024-10-19 11:48:05 -03:00
Eduardo Arias
d053ec6de6 Add cppcheck suppressions for false positives 2024-10-19 11:48:05 -03:00
Eduardo Arias
c2b86ddc49 Suppress warnings on seclang-parser.hh
warning: seclang-parser.hh,2116,warning,duplInheritedMember,The struct 'basic_symbol < by_kind >' defines member function with name 'clear' also defined in its parent struct 'by_kind'.
warning: seclang-parser.hh,2376,warning,duplInheritedMember,The struct 'basic_symbol < by_kind >' defines member function with name 'type_get' also defined in its parent struct 'by_kind'.
warning: seclang-parser.hh,2116,warning,duplInheritedMember,The struct 'basic_symbol < by_state >' defines member function with name 'clear' also defined in its parent struct 'by_state'.
warning: seclang-parser.hh,2120,style,constVariableReference,Variable 'yysym' can be declared as reference to const
2024-10-19 11:48:05 -03:00
Eduardo Arias
1eed8b9288 Ignore cppcheck warnings: normalCheckLevelMaxBranches (Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.) 2024-10-19 10:32:33 -03:00
Eduardo Arias
75d31a4d1e Simplified lifetime management of tests
- Addresses Sonarcloud issues:
  - Rewrite the code so that you no longer need this "delete".
  - Make the type of this variable a reference-to-const.
2024-10-07 11:45:10 -03:00
Eduardo Arias
b7b2d9a40d Minor codebase improvements suggested by Sonarcloud
- src/modsecurity.cc
  - Replace the redundant type with "auto".
- src/transaction.cc
  - Avoid this unnecessary copy by using a "const" reference.
- test/common/custom_debug_log.cc
  - Use "=default" instead of the default implementation of this special
    member functions.
    - Removed the unnecessary destructor override instead.
  - Annotate this function with "override" or "final".
    - Removed the unnecessary destructor override instead.
  - Remove this "const" qualifier from the return type in all
    declarations.
- test/common/modsecurity_test_context.h
  - Replace the redundant type with "auto".
- test/regression/regression.cc
  - Use the "nullptr" literal.
  - Replace this declaration by a structured binding declaration.
  - Replace "reinterpret_cast" with a safer operation.
2024-10-07 11:45:10 -03:00
eduar-hte
4df297b596 Avoid passing RuleMessage by std::shared_ptr and use a reference instead.
- Avoids copying std::shared_ptr when lifetime of the RuleMessage
  is controlled by the caller.
  - The RuleMessage instance is created in RuleWithActions::evaluate and
    then used to call the overloaded version of this method that is
    specialized by subclasses.
  - Once the call to the overloaded method returns, the std::shared_ptr
    is destroyed as it's not stored by any of the callers, so it can
    be replaced with a stack variable and avoid paying the cost of
    copying the std::shared_ptr (and its control block that is
    guaranteed to be thread-safe and thus is not a straightforward
    pointer copy)
- Introduced RuleMessage::reset because this is required by
  RuleWithActions::performLogging when it's not the 'last log', the rule
  has multimatch and it's to be logged.
  - The current version is creating allocating another instance of
    RuleMessage on the heap to copy the Rule & Transaction related state
    while all the other members in the RuleMessage are set to their
    default values.
  - The new version leverages the existent, unused and incomplete
    function 'clean' (renamed as 'reset') to do this on the current
    instance.
    - Notice that the current code preserves the value of m_saveMessage,
      so 'reset' provides an argument for the caller to control whether
      this member should be reinitialized.
2024-10-07 11:45:00 -03:00
eduar-hte
e313ac7de7 Introduce ModSecurityTestContext to encapsulate setup of objects required to execute transactions
- Simplifies memory management on error conditions
- Context will be used in unit tests too, in order to provide
  Transaction related instances.
2024-10-07 11:45:00 -03:00
Ervin Hegedus
a4604b66f7 Added new tests to op @pm 2024-08-28 10:45:59 -03:00
Eduardo Arias
5d39890783 Updated Transformation::evaluate signature to allow for in-place updates, removing unnecessary heap allocated copies.
- Renamed Transformation::evaluate to Transformation::transform to avoid
  confusion with Action's overload methods.
- Updated Transformation::transform signature to receive the value by
  reference and perform the transformation inline, if possible.
  - Some transformations still need to use a temporary std::string to
    perform their work, and then copy the result back.
- Made Transformation::transform methods const and updated Transaction
  parameter to be const.
  - Transaction parameter could not be removed because it's used by just
    a single transformation, UrlDecodeUni.
- Removed std::string Action::evaluate(const std::string &exp,
  Transaction *transaction); which was only implemented by
  Transformation but was not used from the base class, but only after
  downcasting to Transformation, so it can just be declared there (and
  not pollute other actions with a default member implementation -that
  does nothing- which is never called).
2024-08-27 10:00:17 -03:00
Eduardo Arias
a5f223cb52 Individual test result should not be printed for automake output
- Test results output escape characters to highlight whether the test
  passed or failed. Additionally, the input & output for each test can
  include non-ASCII characters. These characters break parsing of
  results (.log & .trs files) with grep, as the files are interpreted
  to be binary.
2024-08-18 19:19:23 +00:00
Ervin Hegedus
c9af0c747e
Merge pull request #3221 from eduar-hte/unittest-multithreaded
Add support to run unit tests in a multithreaded context
2024-08-14 12:18:07 +02:00
Eduardo Arias
ee5f95eb04 Added support to run unit tests in a multithreaded context
- This is controlled by specifying the 'mtstress' argument when running
  `unit_test`.
- The goal is to detect if the operator/transformation  fails in this
  context.
- In this mode, the test will be executed 5'000 times in 50 threads
  concurrently.
- Allocation & initialization of the operator/transformation is
  performed once in the main thread, while the evaluation is executed in
  the threads.
  - This is consistent with the library's support for multithreading,
    where initialization and loading of rules is expected to run once.
    See issue #3215.
2024-08-13 14:06:23 -07:00
Ervin Hegedus
6388d88f38
Check if the MP header contains invalid character 2024-08-13 18:26:18 +02:00
Ervin Hegedus
eb26b7960c
Fix regression test result; Add test to main test-suite list 2024-08-12 18:46:19 +02:00
Ervin Hegedus
3a83196a71
Merge pull request #3219 from eduar-hte/cpp17
Simplifiy configuration to build using std C++17
2024-08-09 17:34:02 +02:00
Eduardo Arias
c917d6a2dc Initialize variable in if statement to avoid doing dynamic_cast twice
- Refactored duplicate code in RuleWithOperator::getVariablesExceptions
- Leveraged auto to simplify declaration of dynamic_cast pointers.
2024-08-08 13:37:23 -07:00
Ervin Hegedus
a23e88f79f
Merge pull request #3114 from airween/v3/sonarmemleakfix
fix: Sonarcloud memleak fixes
2024-08-08 21:02:15 +02:00
Eduardo Arias
59254fe3bd Simplifiy configuration to build libModSecurity with std C++17
- Leveraged autoconf again to check whether the C++ compiler supports
  the required standard version and build using it.
- Replaced the outdaded `ax_cxx_compile_stdcxx_11.m4` macro with the
  latest version of `ax_cxx_compile_stdcxx` which supports C++17.
  - https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
  - https://raw.githubusercontent.com/autoconf-archive/autoconf-archive/e4e5269db2764b9f53d759c24750ac6ca38e02ea/m4/ax_cxx_compile_stdcxx.m4
- This should also streamline updating to C++20 in the future.
2024-08-08 11:23:35 -07:00
Eduardo Arias
c802b46b7e Simplify parser error detection in testcase
- After the GitHub macOS runner images were upgraded to macOS 14.6
  (Sonoma), the test 'Include remote rules - failed download (Abort)'
  started failing because the error message reported by curl/OS is no
  longer 'HTTP response code said error'.
2024-08-06 14:40:59 -07:00
Eduardo Arias
0dce46062b Fixed potential memory leak when there is an intervention and log or url is set. 2024-08-05 12:18:11 -07:00
Ervin Hegedus
6cffa8f904
Add _putenv() in case of WIN32 port instead of setenv() 2024-08-05 14:30:26 +02:00
Ervin Hegedus
82801752d4
Merge branch 'v3/master' into v3/sonarmemleakfix 2024-08-05 14:04:04 +02:00
Ervin Hegedus
937fc5ae59
Provide a function to set 'hostname' field in log 2024-07-29 22:07:26 +02:00
Eduardo Arias
eb62cac7fa Add script to download OWASP CRS v4 to run benchmark
- Simplified clone & checkout of CRS repository
- Removed no longer maintained OWASP Core Ruleset v2
2024-07-17 00:49:27 +00:00
Eduardo Arias
a3f40ef03c Replace Mbed TLS source code in repository with a submodule
- Updated to latest Mbed TLS version (v3.6.0)
2024-05-31 00:41:10 +00:00
Eduardo Arias
7732b5e8f3 Update libinjection to version v3.9.2-92-gb9fcaaf 2024-05-31 00:41:10 +00:00
Eduardo Arias
7267c1dc21 Added support to run regression tests without libxml2
- Annotated regression tests that depend on libxml2 support
- Added Windows build without libxml2
2024-05-19 18:55:34 +00:00
Eduardo Arias
e6e2989bd5 Configure test fixture using CTest for Windows build
- Added new test/test_suite.in with list of regression and unit tests
  previously in Makefile.am, to be shared between Unix and Windows
  builds.
- Updated regression.cc & unit.cc to return the number of failed tests
  to indicate to CTest that the test failed. Similarly, a crash or
  unhandled exception terminates the process with a non-zero exit code.
  - This change doesn't affect running the tests with autotest in Unix
    builds because this processes test output from custom-test-driver &
    test-suite.sh, and ignores the exit code of the test runner.
- Removed comment in test/test-cases/regression-offset-variable.json as
  this is not supported by JSON and prevents strict parsers to read and
  process the file.
- Minor change in regression.cc's clearAuditLog to replace std::ifstream
  with std::ofstream as the mode to open the flag applies to an output
  stream.
- Minor change in unit.cc to simplify code that deletes tests.
- Minor changes to test/custom-test-driver to correct usage information.
2024-05-13 10:22:12 -07:00
Eduardo Arias
7bff2f77aa Updated references to coreruleset repository
- For OWASP v2 rules, switch to a v2 tag for the paths referenced in
  the rest of the script to apply.
2024-05-03 23:05:34 -03:00