Skip to content

V2/json empty #2363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
18 Jul 2017 - 2.9.2
-------------------

* Include unanmed JSON values in unnamed ARGS
[Issue #1576 - Marc Stern]
* IIS build refactoring and dependencies update
[Issue #1487 - @victorhora]
* Best practice: Initialize msre_var pointers
Expand Down
3 changes: 1 addition & 2 deletions apache2/msc_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,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
60 changes: 60 additions & 0 deletions tests/regression/misc/00-json-parser.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
### JSON parser tests

# Normal
{
type => "misc",
comment => "JSON parser (normal)",
conf => qq(
SecRuleEngine On
SecDebugLog $ENV{DEBUG_LOG}
SecDebugLogLevel 9
SecRequestBodyAccess On
SecRule REQBODY_PROCESSOR_ERROR "\@eq 1" "phase:2,deny,id:500657"
),
match_response => {
status => qr/^200$/,
},
request => new HTTP::Request(
POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
[
"Content-Type" => q(application/json),
],
normalize_raw_request_data(
q(
{
"key1": "value",
"key2": 10,
"key3": [1, 2],
"key4": {"key1": "value", "key2": 10, "key3": [1, 2]}
}
),
),
),
},

# Empty key -> should still work
{
type => "misc",
comment => "JSON parser (Empty key)",
conf => qq(
SecRuleEngine On
SecDebugLog $ENV{DEBUG_LOG}
SecDebugLogLevel 9
SecRequestBodyAccess On
SecRule REQBODY_PROCESSOR_ERROR "\@eq 1" "phase:2,deny,id:500660"
),
match_response => {
status => qr/^200$/,
},
request => new HTTP::Request(
POST => "http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/test.txt",
[
"Content-Type" => q(application/json),
],
normalize_raw_request_data(
q(
25
),
),
),
},