3671 Commits

Author SHA1 Message Date
gberkes
ab78d4af79 Refactor: used the init-statement to declare "pos" inside the if statement.
C++17 introduced a construct to create and initialize a variable within the
condition of if and switch statements, and C++20 added this construct to
range-based for loops. Using this new feature simplifies common code patterns
and helps in giving variables the right scope.

Reference: https://sonarcloud.io/project/issues?open=AZDCieK2zGtqRpL2rnl-&id=owasp-modsecurity_ModSecurity
2024-08-07 13:05:02 +02:00
gberkes
c46f470d6b Refactor: moved 3 #include directives to the top of the file.
To aid code readability, all #include directives in a code file
should be grouped together near the top. The only items that may
precede an #include in a file are other preprocessor directives or comments.

Reference: https://sonarcloud.io/project/issues?sinceLeakPeriod=true&issueStatuses=OPEN%2CCONFIRMED&id=owasp-modsecurity_ModSecurity&open=AY8-ffgqm_fzkWiCOtCs&tab=code

Deleted some unnecessary trailing spaces as well.
2024-08-07 10:39:06 +02:00
Ervin Hegedus
0feaeacce5
Merge pull request #3211 from eduar-hte/secremoterules-regression
Fix SecRemoteRules regression test not to depend on a specific error message
2024-08-07 09:56:08 +02: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
0b5493d4e7 Minor performance improvements setting up intervention's log
- Initialize `log` temporary value on construction instead of doing
  default initialization and then calling `append`.
- Leverage `std::string_view` to replace `const std::string&` parameters
  in `utils::string::replaceAll` to avoid creating a `std::string`
  object (and associated allocation and copy) for the string literal`%d`
2024-08-06 14:40:45 -07:00
Eduardo Arias
c947f5e40d Do not assume ModSecurityIntervention argument to transaction::intervention has been initialized/cleaned
- Keep m_it->disruptive value and use it as return value to guarantee
  that the value is correct.
  - If m_it->disruptive is false and the 'it' argument has not been
    initialized/cleaned, the function may incorrectly return a non-zero
    value.
- When a disruptive intervention is being reported by the function,
  defensively initialize log & url to NULL if there's no such data to
  provide to the caller.
  - If the caller has not initialized/cleaned those fields in the 'it'
    argument, after returning from transaction::intervention, the user
    can safely read the log & url fields and in all scenarios they'll
    have valid values.
2024-08-06 14:40:45 -07:00
Ervin Hegedus
80dd45703b
Update CHANGES - added PR 3210 2024-08-06 17:37:52 +02:00
Ervin Hegedus
68d551c5f9
Merge pull request #3210 from eduar-hte/shared-files-deadlock
Fixed shared files deadlock in a multi-threaded Windows application
2024-08-06 17:35:41 +02:00
Ervin Hegedus
ff303c761f
Add newest changes 2024-08-06 15:43:39 +02:00
Ervin Hegedus
630751eee6
Merge pull request #3209 from eduar-hte/cleanup_api
Add cleanup methods to complete C based ABI
2024-08-06 15:40:48 +02:00
Ervin Hegedus
8ec69bedd0
Merge pull request #3208 from eduar-hte/macos-apple-silicon
Build on macOS with Apple silicon (arm64)
2024-08-06 14:40:34 +02:00
Eduardo Arias
4b5f719906 Fixed shared files deadlock in a multi-threaded Windows application
- The shared files Windows implementation introduced in PR #3132 works
  in multi-process single-threaded contexts but it doesn't work
  correctly in single-process multi-threaded contexts.
- The issue is that the LockFileEx Win32 function works on a per-handle
  basis.
  - In a multi-process context, each process will have called
    SharedFiles::add_new_handler when initializing the SharedFile and
    obtained a handle, and thus locking will work.
  - When running ModSecurity in a single process using multiple threads,
    the initialization of the SharedFile will happen once and the handle
    will be shared by all threads. Then, if two threads try to write to
    the same shared file concurrently, they may deadlock as one of them
    will lock the file (by calling LockFileEx) and then proceed to write
    to the file. If before writing to the file and unlocking it, another
    thread calls LockFileEx on the same handle, the attempt to write to
    the file will lock generating a deadlock.
- The new implementation replaces usage of LockFileEx/UnlockFileEx with
  a named mutex to lock access to the shared file.
  - A named mutex is used to support multi-process scenarios.
  - The mutex name is generated using the filename to support multiple
    shared files (such as that for the debug and audit logs).
    - This assumes that both process will initialize the SharedFile
      instance using the same filename (which is expected as they'd be
      using the same configuration file)
2024-08-05 13:04:09 -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
Eduardo Arias
dab9bb6a11 Added methods to free buffers allocated by ModSecurity APIs
- The following methods are introduced to allow clients of
  libModSecurity that are not able to link and call the C/C++ standard
  library to be able to free the buffers allocated by libModSecurity.
- msc_intervention_cleanup: Frees the buffers in a
  ModSecurityIntervention structure that have been allocated by calls to
  msc_intervention.
- msc_rules_error_cleanup: Frees an error message buffer allocated by
  the msc_rules_xxx functions to detail the condition that triggered
  the error.
2024-08-05 12:18:11 -07:00
Eduardo Arias
e31ff7e60b Build on macOS 14 arm64 2024-08-05 11:49:58 -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
2048730012
Update CHANGES 2024-08-05 09:32:40 +02:00
Ervin Hegedus
f04dcc0262
Merge pull request #3207 from gberkes/v3/remove_this_throw_call_transaction_h_mk2
V3/remove this throw call transaction h mk2
2024-08-05 09:30:08 +02:00
gberkes
b4cb24327c Fixed extra whitespace. 2024-08-04 23:00:39 +02:00
gberkes
dc3f80a155 Fixed missing whitespace. 2024-08-04 22:55:42 +02:00
gberkes
d47185d771 Build System: Introduce Configurable Assertion Handling
Implemented a new configuration option --enable-assertions=[yes|no] within config.ac, enabling controlled inclusion of -DNDEBUG in CPPFLAGS. The default setting suppresses assertions (by adding -DNDEBUG to CPPFLAGS), preserving the original behavior. This enhancement allows for the optional enabling of assertions during development or debugging by setting --enable-assertions=yes, thereby excluding -DNDEBUG from CPPFLAGS.
2024-08-04 22:47:15 +02:00
gberkes
053e3b5266 Document the usage and the importance of assertions. 2024-08-04 22:13:58 +02:00
gberkes
b4659959cd Refactor: Ensure safe error handling by removing isolated throw; statements.
- SonarCloud analysis identified standalone `throw;` calls without accompanying `try-catch` blocks, used inconsistently as placeholders or for premature termination under specific conditions.
- Removed these `throw;` instances to prevent potential runtime issues in future development phases, where such configurations might inadvertently be created.
- Introduced `assert` statements as a more appropriate mechanism for asserting preconditions in the affected class member functions, ensuring clearer intent and safer code behavior during development.
- Refactor action_kind processing to use switch() instead of if-else chains; add assertion in default case.
- Fix SonarCloud issue: Make this variable a const reference.
https://sonarcloud.io/project/issues?resolved=false&pullRequest=3104&id=owasp-modsecurity_ModSecurity&open=AY8Vpgy4f6U6E7VKL4Cn
2024-08-04 22:04:07 +02:00
Ervin Hegedus
5fa470189b
Add PR's to CHANGES 2024-08-03 16:23:26 +02:00
Ervin Hegedus
b6d218f72d
Merge pull request #3116 from gberkes/v3/remove_this_conditional_structure
Deleted redundant code in 'ModSecurity::serverLog(...)'.
2024-08-02 16:33:07 +02:00
Ervin Hegedus
97c3d15f31
Merge pull request #3203 from airween/v3/sethostname
feat(api) new function: set hostname
2024-08-02 09:44:13 +02:00
Ervin Hegedus
c7efeb6d06
Merge branch 'owasp-modsecurity:v3/master' into v3/sethostname 2024-08-01 22:35:44 +02:00
Ervin Hegedus
a14cdc4ff5
Merge pull request #3182 from airween/v3/readmeupdate
Update README.md: use submodule and use benchmark tool
2024-07-31 16:41:55 +02:00
Ervin Hegedus
4b38435a6e
Merge pull request #3117 from airween/v3/eualrangebyfind
fix: Changed 'equal_range()' + loop by 'find()' in resolveFirst() methods
2024-07-31 15:46:54 +02:00
Ervin Hegedus
6449310831
Fix typos 2024-07-31 14:23:52 +02:00
Ervin Hegedus
937fc5ae59
Provide a function to set 'hostname' field in log 2024-07-29 22:07:26 +02:00
Ervin Hegedus
adba86e2bd
Merge pull request #3185 from eduar-hte/git-describe
Simplify checkout of submodules in GitHub workflows (with support for git describe)
2024-07-25 18:10:52 +02:00
Ervin Hegedus
de8646e383
Merge pull request #3189 from bitbehz/fix/typo-build-win32-dockerfile
Fixing typo in Dockerfile
2024-07-25 18:08:08 +02:00
Behzad Eslami Tehrani
4fce2e3c1d Fixing typo in Dockerfile
Fixing typo in environment variable SRC_DIR.
SCR_DIR -> SRC_DIR
2024-07-22 10:09:27 +03:30
Eduardo Arias
f4d35383e9 fixed typo 2024-07-17 23:22:09 +00:00
Eduardo Arias
5fe777aeb8 simplify submodules checkout (but fetch tags for git describe to work) 2024-07-17 23:19:10 +00:00
Ervin Hegedus
3dda900ee9
Merge pull request #3164 from eduar-hte/variable-origin
Improve performance of VariableOrigin instances
2024-07-17 23:08:30 +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
6faf6d7ec0 Removed unnecessary usage of heap-allocated VariableValue (m_var)
- Removed unused methods
2024-07-17 00:49:27 +00:00
Eduardo Arias
dc0a06fc70 Improve performance of VariableOrigin instances
- The previous approach would create a std::unique_ptr and store it in
  a std::list in VariableValue (Origins)
- The new approach now stores Origins in a std::vector and constructs
  VariableOrigin elements in-place on insertion.
- Instead of having two heap-allocations for every added VariableOrigin
  instance, this performs only one.
- If multiple origins are added, std::vector's growth strategy may even
  prevent a heap-allocation. There's a cost on growing the size of the
  vector, because a copy of current elements will be necessary.
  - Introduced reserveOrigin method to notify that multiple insertions
    will be made, so that we can use std::vector's reserve and do a
    single allocation (and copy of previous elements), and then just
    initialize the new elements in-place.
2024-07-17 00:49:27 +00:00
Ervin Hegedus
8d06e4c47b
Typo fixes 2024-07-12 18:09:33 +02:00
Ervin Hegedus
baa7e694f9
Typo fixes 2024-07-12 11:28:52 +02:00
Ervin Hegedus
714e531134
Content improve 2024-07-12 09:15:19 +02:00
Ervin Hegedus
30ddc32c6f
Update README.md: use submodule and use benchmark tool 2024-07-11 22:07:16 +02:00
Ervin Hegedus
7c174e95fa
Merge pull request #3161 from eduar-hte/others-update
Update libinjection & Mbed TLS
2024-07-10 16:35:40 +02: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
Ervin Hegedus
dc8af8f23d
Merge pull request #3160 from fzipi/v3/add-pull-request-template
chore: add PR template (v3)
2024-05-30 15:36:53 +02:00
Felipe Zipitria
98c672ddb4
chore: add PR template
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
2024-05-30 09:51:06 -03:00