Skip to content

Commit

Permalink
Allow no-key, single-value JSON body
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhsv committed May 3, 2022
1 parent 7334271 commit 4a98032
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,6 +1,8 @@
DD mmm YYYY - 2.9.x (to be released)
-------------------

* Allow no-key, single-value JSON body
[Issue #2735 - @marcstern, @martinhsv]
* Set SecStatusEngine Off in modsecurity.conf-recommended
[Issue #2717 - @un99known99, @martinhsv]
* Fix memory leak that occurs on JSON parsing error
Expand Down
3 changes: 1 addition & 2 deletions apache2/msc_json.c
Expand Up @@ -27,8 +27,7 @@ int json_add_argument(modsec_rec *msr, const char *value, unsigned length)
* to reference this argument; for now we simply ignore these
*/
if (!msr->json->current_key) {
msr_log(msr, 3, "Cannot add scalar value without an associated key");
return 1;
msr->json->current_key = "";
}

arg = (msc_arg *) apr_pcalloc(msr->mp, sizeof(msc_arg));
Expand Down
2 changes: 1 addition & 1 deletion apache2/msc_json.h
Expand Up @@ -39,7 +39,7 @@ struct json_data {

/* prefix is used to create data hierarchy (i.e., 'parent.child.value') */
unsigned char *prefix;
unsigned char *current_key;
const unsigned char *current_key;
long int current_depth;
int depth_limit_exceeded;
};
Expand Down
34 changes: 34 additions & 0 deletions tests/regression/rule/15-json.t
Expand Up @@ -224,6 +224,40 @@
),
),
),
},
{
type => "rule",
comment => "json parser - no-key single value",
conf => qq(
SecRuleEngine On
SecRequestBodyAccess On
SecDebugLog $ENV{DEBUG_LOG}
SecAuditEngine RelevantOnly
SecAuditLog "$ENV{AUDIT_LOG}"
SecDebugLogLevel 9
SecRequestBodyJsonDepthLimit 3
SecRule REQUEST_HEADERS:Content-Type "application/json" \\
"id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON"
SecRule REQBODY_ERROR "!\@eq 0" "id:'200444',phase:2,log,deny,status:403,msg:'Failed to parse request body'"
SecRule ARGS "\@streq 25" "id:'200445',phase:2,log,deny,status:403"
),
match_log => {
audit => [ qr/200445/s, 1 ],
},
match_response => {
status => qr/^403$/,
},
request => new HTTP::Request(
POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
[
"Content-Type" => "application/json",
],
normalize_raw_request_data(
q(
25
),
),
),
}


0 comments on commit 4a98032

Please sign in to comment.