Skip to content

Commit 784693b

Browse files
authored
Merge pull request #2735 from martinhsv/v2/master
Allow no-key, single-value JSON body
2 parents 7334271 + 4a98032 commit 784693b

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

Diff for: CHANGES

+2
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+
* Allow no-key, single-value JSON body
5+
[Issue #2735 - @marcstern, @martinhsv]
46
* Set SecStatusEngine Off in modsecurity.conf-recommended
57
[Issue #2717 - @un99known99, @martinhsv]
68
* Fix memory leak that occurs on JSON parsing error

Diff for: apache2/msc_json.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ int json_add_argument(modsec_rec *msr, const char *value, unsigned length)
2727
* to reference this argument; for now we simply ignore these
2828
*/
2929
if (!msr->json->current_key) {
30-
msr_log(msr, 3, "Cannot add scalar value without an associated key");
31-
return 1;
30+
msr->json->current_key = "";
3231
}
3332

3433
arg = (msc_arg *) apr_pcalloc(msr->mp, sizeof(msc_arg));

Diff for: apache2/msc_json.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct json_data {
3939

4040
/* prefix is used to create data hierarchy (i.e., 'parent.child.value') */
4141
unsigned char *prefix;
42-
unsigned char *current_key;
42+
const unsigned char *current_key;
4343
long int current_depth;
4444
int depth_limit_exceeded;
4545
};

Diff for: tests/regression/rule/15-json.t

+34
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,40 @@
224224
),
225225
),
226226
),
227+
},
228+
{
229+
type => "rule",
230+
comment => "json parser - no-key single value",
231+
conf => qq(
232+
SecRuleEngine On
233+
SecRequestBodyAccess On
234+
SecDebugLog $ENV{DEBUG_LOG}
235+
SecAuditEngine RelevantOnly
236+
SecAuditLog "$ENV{AUDIT_LOG}"
237+
SecDebugLogLevel 9
238+
SecRequestBodyJsonDepthLimit 3
239+
SecRule REQUEST_HEADERS:Content-Type "application/json" \\
240+
"id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON"
241+
SecRule REQBODY_ERROR "!\@eq 0" "id:'200444',phase:2,log,deny,status:403,msg:'Failed to parse request body'"
242+
SecRule ARGS "\@streq 25" "id:'200445',phase:2,log,deny,status:403"
243+
),
244+
match_log => {
245+
audit => [ qr/200445/s, 1 ],
246+
},
247+
match_response => {
248+
status => qr/^403$/,
249+
},
250+
request => new HTTP::Request(
251+
POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
252+
[
253+
"Content-Type" => "application/json",
254+
],
255+
normalize_raw_request_data(
256+
q(
257+
25
258+
),
259+
),
260+
),
227261
}
228262

229263

0 commit comments

Comments
 (0)