Skip to content

Commit 569abcd

Browse files
author
Marc Stern
committed
Merge branch 'v2/master' of https://github.com/marcstern/ModSecurity into v2/master
2 parents 43e4be4 + 17b76b9 commit 569abcd

File tree

16 files changed

+885
-914
lines changed

16 files changed

+885
-914
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
DD mmm YYYY - 2.9.x (to be released)
22
-------------------
33

4+
* Set the minimum security protocol version for SecRemoteRules
5+
[Issue security/code-scanning/2 - @airween]
46
* Allow lua version 5.4
57
[Issue #2996 - @3eka, @martinhsv]
68
* Configure: do not check for pcre1 if pcre2 requested

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Copyright (c) 2004-2013 Trustwave Holdings, Inc. (http://www.trustwave.com/)
77

88
You may not use this file except in compliance with the License. You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
99

10-
If any of the files related to licensing are missing or if you have any other questions related to licensing please contact Trustwave Holdings, Inc. directly using the email address: security@modsecurity.org.
10+
If any of the files related to licensing are missing or if you have any other questions related to licensing please contact Trustwave Holdings, Inc. directly using the email address: modsecurity@owasp.org.
1111

1212

1313
## Documentation
1414

15-
Please refer to: [the documentation folder](https://github.com/SpiderLabs/ModSecurity/tree/v2/master/doc) for the reference manual.
15+
Please refer to: [the documentation folder](https://github.com/owasp-modsecurity/ModSecurity/tree/v2/master/doc) for the reference manual.
1616

1717
## Sponsor Note
1818

apache2/msc_json.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,17 @@ int json_init(modsec_rec *msr, char **error_msg) {
354354
int json_process_chunk(modsec_rec *msr, const char *buf, unsigned int size, char **error_msg) {
355355
if (error_msg == NULL) return -1;
356356
*error_msg = NULL;
357-
base_offset=buf;
357+
// Take a copy in case libyajl decodes the buffer inline
358+
base_offset = apr_pstrmemdup(msr->mp, buf, size);
359+
if (!base_offset) return -1;
358360

359361
/* Feed our parser and catch any errors */
360-
msr->json->status = yajl_parse(msr->json->handle, buf, size);
362+
msr->json->status = yajl_parse(msr->json->handle, (unsigned char*)base_offset, size);
361363
if (msr->json->status != yajl_status_ok) {
362364
if (msr->json->depth_limit_exceeded) {
363365
*error_msg = "JSON depth limit exceeded";
364366
} else {
365-
char *yajl_err = yajl_get_error(msr->json->handle, 0, buf, size);
367+
char *yajl_err = yajl_get_error(msr->json->handle, 0, base_offset, size);
366368
*error_msg = apr_pstrdup(msr->mp, yajl_err);
367369
yajl_free_error(msr->json->handle, yajl_err);
368370
}

apache2/msc_logging.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,7 @@ static char *construct_auditlog_filename(apr_pool_t *mp, const char *uniqueid) {
234234
* This is required for mpm-itk & mod_ruid2, though should be harmless for other implementations
235235
* It also changes the return statement.
236236
*/
237-
char *userinfo;
238-
apr_status_t rc;
239-
apr_uid_t uid;
240-
apr_gid_t gid;
241-
apr_uid_current(&uid, &gid, mp);
242-
rc = apr_uid_name_get(&userinfo, uid, mp);
243-
if (rc != APR_SUCCESS) {
244-
userinfo = apr_psprintf(mp, "%u", uid);
245-
}
237+
char *userinfo = get_username(mp);
246238

247239
apr_time_exp_lt(&t, apr_time_now());
248240

apache2/msc_pcre.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ static apr_status_t msc_pcre_cleanup(msc_regex_t *regex) {
3131
}
3232
#else
3333
if (regex->pe != NULL) {
34-
#if defined(VERSION_NGINX)
3534
pcre_free(regex->pe);
36-
#else
37-
free(regex->pe);
38-
#endif
3935
regex->pe = NULL;
4036
}
4137
if (regex->re != NULL) {
@@ -152,19 +148,15 @@ void *msc_pregcomp_ex(apr_pool_t *pool, const char *pattern, int options,
152148

153149
#ifdef WITH_PCRE_STUDY
154150
#ifdef WITH_PCRE_JIT
155-
pe = pcre_study(regex->re, PCRE_STUDY_JIT_COMPILE, &errptr);
151+
pe = pcre_study(regex->re, PCRE_STUDY_EXTRA_NEEDED|PCRE_STUDY_JIT_COMPILE, &errptr);
156152
#else
157-
pe = pcre_study(regex->re, 0, &errptr);
153+
pe = pcre_study(regex->re, PCRE_STUDY_EXTRA_NEEDED, &errptr);
158154
#endif
159155
#endif
160156

161157
/* Setup the pcre_extra record if pcre_study did not already do it */
162158
if (pe == NULL) {
163-
#if defined(VERSION_NGINX)
164-
pe = pcre_malloc(sizeof(pcre_extra));
165-
#else
166-
pe = malloc(sizeof(pcre_extra));
167-
#endif
159+
pe = (pcre_extra*)pcre_malloc(sizeof(pcre_extra));
168160
if (pe == NULL) {
169161
return NULL;
170162
}

apache2/msc_remote_rules.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ int msc_remote_download_content(apr_pool_t *mp, const char *uri, const char *key
331331
headers_chunk = curl_slist_append(headers_chunk, header_key);
332332
}
333333

334-
/* Make it TLS 1.x only. */
335-
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
334+
/* Make it TLS 1.2 at least. */
335+
curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
336336

337337
#ifdef WIN32
338338
res_len = SearchPathA(NULL, "curl-ca-bundle.crt", NULL, (2048 + 1), buf, &ptr);

apache2/msc_util.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,3 +2843,14 @@ char* strtok_r(
28432843
}
28442844
#endif
28452845

2846+
// Function compatible with Linux & Windows, also with mpm-itk & mod_ruid2
2847+
char* get_username(apr_pool_t* mp) {
2848+
char* username;
2849+
apr_uid_t uid;
2850+
apr_gid_t gid;
2851+
int rc = apr_uid_current(&uid, &gid, mp);
2852+
if (rc != APR_SUCCESS) return "apache";
2853+
rc = apr_uid_name_get(&username, uid, mp);
2854+
if (rc != APR_SUCCESS) return "apache";
2855+
return username;
2856+
}

apache2/msc_util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ int DSOLOCAL tree_contains_ip(apr_pool_t *mp, TreeRoot *rtree,
159159
int DSOLOCAL ip_tree_from_param(apr_pool_t *pool,
160160
char *param, TreeRoot **rtree, char **error_msg);
161161

162+
char DSOLOCAL *get_username(apr_pool_t* mp);
163+
162164
#ifdef WITH_CURL
163165
int ip_tree_from_uri(TreeRoot **rtree, char *uri,
164166
apr_pool_t *mp, char **error_msg);

0 commit comments

Comments
 (0)