158 Commits

Author SHA1 Message Date
Ervin Hegedus
38850f912b
Merge pull request #3372 from notroj/v2-gcc-warning-fixes
Fix compiler warnings from GCC
2025-05-17 10:09:29 +02:00
Joe Orton
9d9a727349 Fix compiler warnings. Reported by GCC with flags:
-Wall -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS

Note, e.g. sprintf(digest, "%s%02x", digest, ...) is undefined behaviour because
the destination and source variables overlap, and GCC warnings for this.

acmp.c:258:13: warning: 'acmp_clone_node_no_state' defined but not used [-Wunused-function]
apache2_config.c:806:9: warning: unused variable 'offset' [-Wunused-variable]
apache2_config.c:1886:23: warning: unused variable 'dcfg' [-Wunused-variable]
apache2_config.c:1942:23: warning: unused variable 'dcfg' [-Wunused-variable]
apache2_config.c:2470:23: warning: unused variable 'dcfg' [-Wunused-variable]
apache2_config.c:2538:23: warning: unused variable 'dcfg' [-Wunused-variable]
apache2_util.c:226:11: warning: unused variable 'str' [-Wunused-variable]
apache2_util.c:225:11: warning: unused variable 'saved' [-Wunused-variable]
apache2_util.c:224:11: warning: unused variable 'parse_remote' [-Wunused-variable]
apache2_util.c:223:11: warning: unused variable 'remote' [-Wunused-variable]
msc_status_engine.c:216:17: warning: unused variable 'i' [-Wunused-variable]
msc_status_engine.c:375:55: warning: the address of 'pcre' will always evaluate as 'true' [-Waddress]
msc_crypt.c:67:17: warning: unused variable 'bytes' [-Wunused-variable]
msc_crypt.c:1083:33: warning: variable 'enc' set but not used [-Wunused-but-set-variable]
msc_crypt.c:1090:29: warning: variable 'enc' set but not used [-Wunused-but-set-variable]
/usr/include/bits/stdio2.h:30:10: warning: '__sprintf_chk' argument 5 overlaps destination object 'digest' [-Wrestrict]
msc_json.c:405:11: warning: unused variable 'json_data' [-Wunused-variable]
msc_crypt.c:1097:79: warning: '%s' directive argument is null [-Wformat-overflow=]
msc_logging.c:1144:20: warning: unused variable 'now' [-Wunused-variable]
msc_remote_rules.c:729:19: warning: unused variable 'word' [-Wunused-variable]
msc_remote_rules.c:727:17: warning: unused variable 'tmp' [-Wunused-variable]
msc_remote_rules.c:805:1: warning: control reaches end of non-void function [-Wreturn-type]
msc_tree.c:836:19: warning: unused variable 'ip' [-Wunused-variable]
msc_xml.c:29:44: warning: variable 'entity' set but not used [-Wunused-but-set-variable]
msc_util.c:2627:11: warning: unused variable 'start' [-Wunused-variable]
msc_util.c:2626:17: warning: unused variable 'fd' [-Wunused-variable]
msc_util.c:2624:18: warning: unused variable 'rc' [-Wunused-variable]
msc_util.c:1077:19: warning: array subscript 1 is outside array bounds of 'unsigned char[1]' [-Warray-bounds=]
2025-05-16 09:59:32 +01:00
Ervin Hegedus
d7b38f034e
Refactor code and build system to use libpcre2 as the default 2025-05-15 21:13:52 +02:00
Ervin Hegedus
4c043a0889
Change directive format to strict camel case 2025-04-28 21:05:18 +02:00
Ervin Hegedus
c11bd6c6f2
Fix retval logic explanation 2025-04-27 11:25:59 +02:00
Ervin Hegedus
3829d65792
Debug message clarification
Co-authored-by: Max Leske <250711+theseion@users.noreply.github.com>
2025-04-26 20:08:40 +02:00
Ervin Hegedus
0c8cc6e2cf
Finish XMLArgs processing 2025-04-07 14:01:46 +02:00
Rainer Jung
149376377e Move id_log() to msc_util to fix unit tests; it is declared on msc_util.h already 2024-10-01 13:58:22 +02:00
Marc Stern
6be2ee534a Fixed ap_log_perror() usage
Replaces  #3236
2024-08-26 17:17:36 +02:00
Ervin Hegedus
e7e11d972f
Merge pull request #3202 from marcstern/v2/pr/assert
Fixed assert() usage
2024-08-18 22:58:06 +02:00
Marc Stern
60d07a5547 added one more NULL check at run-time 2024-08-16 09:23:11 +02:00
Marc Stern
4b391834ec added more NULL checks at run-time 2024-08-14 19:09:15 +02:00
Marc Stern
0066a67911 added more NULL checks at run-time 2024-08-14 19:00:25 +02:00
Marc Stern
e5bbd89399 re-added some NULL check at run-time, with an error message on stderr 2024-08-14 13:53:52 +02:00
Marc Stern
8dd5d5f46b re_operators.c: removed invalid check (done correctly on line 1067)
copy_rules(): only one return code => void
2024-08-07 09:42:40 +02:00
Marc Stern
7c379c8d59 Fixed assert() usage:
- added some missing
 - removed some invalid
 - removed some that were not relevant in the context of the current function, when done in a called function
2024-07-31 11:17:36 +02:00
Marc Stern
9fb773c1ce Invalid pointer access in case rule id == NOT_SET_P 2024-07-20 18:45:14 +02:00
Marc Stern
4961f46a6f (re)fixed const type 2024-04-16 18:09:00 +02:00
Marc Stern
d35018ef3f another null check 2024-04-16 18:02:06 +02:00
Marc Stern
5122f89005 defined id_log() only once 2024-04-16 13:28:37 +02:00
Marc Stern
a01b9b527e minor fixes 2024-04-10 14:04:34 +02:00
Marc Stern
91da5872c1 Many null pointer checks 2024-02-20 13:15:52 +01:00
Marc Stern
07f4076f46 Check for NULL pointers 2024-02-07 12:04:50 +01:00
Martin Vierula
0981b325a7
Support configurable limit on number of arguments processed 2022-12-14 07:01:23 -08:00
Martin Vierula
f7fa00aadf
Fix: handle error with SecConnReadStateLimit configuration 2022-11-20 10:39:04 -08:00
Erki Aring
b5130acb45 Move APLOG_USE_MODULE out of modsecurity.h 2022-11-15 17:31:18 +02:00
Martin Vierula
8fc0b519b7
Support for PCRE2 2022-11-08 08:06:39 -08:00
Martin Vierula
41918335fa
Support configurable limit on depth of JSON parsing 2021-11-18 17:35:40 -08:00
Victor Hora
aab128f810 Code cosmetics: checks if actionset is not null before use it 2018-09-22 20:21:23 -04:00
Daniel Muey
a677456078 Issue #1671: Only generate SecHashKey when SecHashEngine is On 2018-09-20 17:46:55 -04:00
Marc Stern
7ff0e7e7b2
Added ALLOW_ID_NOT_UNIQUE compile flag to allow duplicate rule ids and no id 2016-11-21 09:58:40 -03:00
Robert Paprocki
5bc75ec871 Do not compile in JSON logging support if yajl is not found 2016-01-29 11:59:52 -03:00
Robert Paprocki
7a39b4b5b9 Make JSON audit logging a configurable option
Remove compile-time setting for generating audit logs
as JSON, creating a new config option (SecAuditLogFormat).
sec_audit_logger is now a wrapper for sec_audit_logger_json
or sec_audit_logger_native. This has the disadvantage of
making the audit log generation code harder to maintain,
but the logger function itself now is no longer pepper
with binary branches.
2016-01-29 11:59:52 -03:00
Felipe Zimmerle
0db247f0e9 Replicates CREATEMODE patch to the secondary auditlog file
At patch 45805be, @littlecho changed the behaviour to set the audit log
index/serial file permission. Before, it was using the default permission now
it is respecting the permission configured via SecAuditLogFileMode. This patch
replicates @littlecho's work to the secundary auditlog file.
2016-01-26 09:20:25 -03:00
littlecho
b175c5cf60 Update apache2_config.c
Change third parameter(which is the apr file permission flag) from CREATEMODE to dcfg->auditlog_fileperms. Due to the user can specify the desired file permission setting for the audit log files with setting the value of SecAuditLogFileMode, we should follow the file permission setting from the config file. Therefore, as the dcfg->auditlog_fileperms will be modified in cmd_audit_log_dirmode function, we can use the value while calling apr_file_open to meet the file permission that specified in modsecurity.conf.
2016-01-26 09:08:13 -03:00
Wesley M
3a7fdf8fc0 Refactoring conditional directives for if wrappers, alternative if statements and incomplete if conditions. 2016-01-05 08:18:44 -03:00
Felipe Zimmerle
23823bb2c3 Makes Curl no longer a mandatory depedency for ModSecurity core
As reported by Rainer Jung, Curl may not be mandatory to build
	ModSecurity core. This patch make it optional by:
	- Concentrate all downloads using curl on msc_remote_rules.c
	- Split Curl build definitions checks into: WITH_CURL, WITH_REMOTE_RULES
	and WITH_CRYPTO.
	  - WITH_CURL: Contains Culr headers and binaries during the build time.
	  - WITH_REMOTE_RULES: Currently enabled if Curl is present.
	  - WITH_CRYPTO: Set if apr tool was compiled with crypto support.
	- Renames msc_remote_grab_content to msc_remote_download_content
2014-12-03 08:28:59 -08:00
Felipe Zimmerle
9fe72b72de Improves the CA validation
On IIS CA validation was not working as libcurl on windows does not look for a
certificate store, unless it is specified. The resource downloads are now
respecting the SecRemoteRulesFailAction.
2014-11-17 19:32:32 -08:00
Felipe Zimmerle
b5398abaf2 Forces downloads using https-only for resources or rules
This commit makes ModSecurity to refuse to download or install rules
(SecRemoteRules) from sites that are not running HTTPS with a valid and
trusted certificate.
2014-11-14 11:53:40 -08:00
Felipe Zimmerle
59fc243503 Adds the `crypto' option to SecRemoteRules directive
Originally the SecRemoteRules fetch the rules from an remote server in an
specific format, using cryptography. This patch adds the possibility to
load rules in plain/text format.
2014-11-14 11:53:40 -08:00
Felipe Zimmerle
c54bb746c6 Adds SecRemoteRules as an build option
SecRemoteRules adds a new dependency to libcurl. Before only mlogc was
depending on libcurl. SecRemoteRules also depends on the apr-tools with
crypto support, which (as reported by our buildbots) is not default in
some environments such as: MacOS X. This commit disable SecRemoteRules
support if apr-tools was not compiled with crypto support.
2014-11-14 11:53:40 -08:00
Felipe Zimmerle
38b9924705 Adds the SecRemoteRulesFailAction directive
This directive allows the user to set a default action whenever the
SecRemoteRules failed to download a set of rules. Current the supported
values are: Warn and Abort. By default `Abort' is selected.
2014-11-14 11:53:40 -08:00
Felipe Zimmerle
9b836b652a Initial support to load rules from a remote server
New directive `SecRemoteRules' was added. It allows the user to load a
set of rules from a given HTTP server.
2014-11-14 11:53:40 -08:00
Felipe Zimmerle
accb1820e0 Adds collection FILES_TMP_CONTENT
The collection is filled with a key-value set where value is the content of
the file which was uploaded. This collection can be used with all supported
operators, however SecUploadKeepFiles should be set to 'On' in order
to have this collection filled.
2014-11-14 11:52:56 -08:00
Felipe Zimmerle
efef989ddd Renames Sec{Read|Write}StateLimits
The Sec{Read|Write}StateLimits are filters related to the connections, when the
server did not know yet which vhost the request goes to. This means that once
those configrations are set it will be applied to entire server. This patch
just renames the Sec{Read|Write}StateLimits to SecConn{Read|Write}StateLimits
to make it more clear to the user. SecConnectionEngine was also renamed to
SecConnEngine.
2014-03-31 16:22:11 -07:00
Felipe Zimmerle
48d85c7d6e Places connection filter engine in a separated configuration
Different from the Rules or other options, the connections filters are applied
to entire server, not to a single vhost, or so. In order to keep it clear to
the user this patches adds "SecConnectionEngine" which works in the same way
that SecRuleEngine does.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
a15f8813e9 Honor the SecRuleEngine while filtering connections
The SecRuleEngine has the capability to Enable, Disable or even to place the
ModSecurity in DetectionOnly mode. The SecReadStateLimit and SecWriteStateLimit
were not honoring such state, due the fact that our configuration belongs to
requests not to connections, the only struct that exists while those filters
are placed. By adding a global variable "conn_limits_filter_state" we are now
able to identify the current state of the ModSecurity, once the configuration
is loaded this variable is set and used by the connections filters.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
0037a0732a Using RadixTree instead of list to storage IPs
Used by the operator @ipMatch and variants, this structure storage all the IPs
addresses for later comparison. Last version was using RadixTree only if the
set of IPs was specified from files. IPs specified as parameters, was using
a chained list. Chained lists may affect the performance, since lookups in
worst case will be O(n). RadixTrees could provide better results depending
on the amount of elements and its contents.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
b9fdc4fe3b Adds support to suspicious and whitelist to Read and Write limits
The operators @ipMatch, @ipMatchF and @ipMatchFromFile were
added to the functions: SecReadStateLimit and SecReadStateLimit,
by using them it is possible to declare a suspicious list. When
a suspicious list is given, the {Read|Write}StateLimit will be
applied just to the IPs that belongs to that restricted list.
Note that the negative of those operators (e.g. !@ipMatch) can be
used to place a whitelist. The {Read|Write}StateLimit
restrictions will not be applied to those in the whitelist.
This current version the Sec{Read|Write}StateLimit can be used
varios times to add elements to both lists, however, the
last informed limit will be applied for the entire group. This
feature is experimental, and suggestions on how to improve it
are very welcome. For further discussion use the issue: #353.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
e131e2222d Adds support to status engine on IIS version
Fixes on the windows versions: build, mac address and machine name retrieval
2014-03-31 07:14:55 -07:00