owasp-modsecurity / ModSecurity

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 which provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring, logging and real-time analysis.
https://www.modsecurity.org
Apache License 2.0
8.05k stars 1.58k forks source link

Review and document multi-threading support and limitations #3215

Open eduar-hte opened 1 month ago

eduar-hte commented 1 month ago

The goal of this issue is to collect and centralize information about multi-threading support of the current version of modSecurity , as the topic has come up in a number of issues and there are documented guidelines about usage in this context.

Multi-threading support

The library is expected to work in multi-threaded scenarios, as stated in #1726. This means that any issues should be related to incorrect usage or bugs in the current implementation.

"The modSecurity life cycle is divided into different stages. The stage that the rules are loaded is not threading safe by design. (...) Once the rules are loaded multiple requests can share the same RulesSet object, leading to parallelism while addressing different requests in different processes or threads." (Source: #2536, here)

Notes

Examples

The repository currently includes an example of usage of the library in a multi-threaded context, see reading_logs_via_rule_message in the examples directory.

Potential issues/limitations

Reviewed/addressed issues

Misc

eduar-hte commented 1 month ago

"The modSecurity life cycle is divided into different stages. The stage that the rules are loaded is not threading safe by design. (...) Once the rules are loaded multiple requests can share the same RulesSet object, leading to parallelism while addressing different requests in different processes or threads." (Source: #2536, here)

@airween: I think #3138 could be closed with a reference to this.

eduar-hte commented 1 month ago

Created PR #3216 to try to correct this.

eduar-hte commented 1 month ago
  • MODSEC_MUTEX_ON_PM define & --enable-mutex-on-pm configure flag

The need for this optional lock was reviewed and confirmed not to be necessary. PR #3227 was submitted to remove it.

eduar-hte commented 1 month ago
  • string.h's ascTime uses std::ctime, which is not safe in multi-threaded contexts

Created PR #3228 to address this.