Skip to content

Commit d2b14de

Browse files
author
Felipe Zimmerle
committed
Allow 0 length JSON requests
As discussed at: #1822
1 parent d29f2a8 commit d2b14de

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

CHANGES

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

4+
- Allow 0 length JSON requests.
5+
[Issue #1822 - @allanbomsft, @zimmerle, @victorhora, @marcstern]
46
- Fix "make dist" target to include default configuration
57
[Issue #1966 - @defanator]
68
- Replaced log locking using mutex with fcntl lock

src/transaction.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ int Transaction::processRequestBody() {
734734
&error);
735735
m_json->complete(&error);
736736
}
737-
if (error.empty() == false) {
737+
if (error.empty() == false && m_requestBody.str().size() > 0) {
738738
m_variableReqbodyError.set("1", m_variableOffset);
739739
m_variableReqbodyProcessorError.set("1", m_variableOffset);
740740
m_variableReqbodyErrorMsg.set("JSON parsing error: " + error,

test/test-cases/regression/request-body-parser-json.json

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"enabled":1,
44
"version_min":300000,
5-
"title":"Testing JSON request body parser 1/1",
5+
"title":"Testing JSON request body parser 1/2",
66
"expected":{
77
"debug_log": "Target value: \"bar\" \\(Variable: ARGS:json.foo\\)"
88
},
@@ -41,7 +41,7 @@
4141
{
4242
"enabled":1,
4343
"version_min":300000,
44-
"title":"Testing JSON request body parser 1/1",
44+
"title":"Testing JSON request body parser 2/2",
4545
"expected":{
4646
"debug_log": "Target value: \"bar\" \\(Variable: ARGS:json.first_level.first_key\\)"
4747
},
@@ -79,6 +79,77 @@
7979
"SecRule REQUEST_HEADERS:Content-Type \"application/json\" \"id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON\"",
8080
"SecRule ARGS \"bar\" \"id:'200441',phase:3,log\""
8181
]
82+
},
83+
{
84+
"enabled":1,
85+
"version_min":300000,
86+
"title":"Testing JSON request body parser - issue #1822 (1/2)",
87+
"expected":{
88+
"debug_log": "Target value: \"0\" .Variable: REQBODY_ERROR."
89+
},
90+
"client":{
91+
"ip":"200.249.12.31",
92+
"port":123
93+
},
94+
"request":{
95+
"headers":{
96+
"Host":"localhost",
97+
"User-Agent":"curl/7.38.0",
98+
"Accept":"*/*",
99+
"Cookie": "PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120",
100+
"Content-Type": "application/json"
101+
},
102+
"uri":"/?key=value&key=other_value",
103+
"method":"POST",
104+
"body": [
105+
]
106+
},
107+
"server":{
108+
"ip":"200.249.12.31",
109+
"port":80
110+
},
111+
"rules":[
112+
"SecRuleEngine On",
113+
"SecRequestBodyAccess On",
114+
"SecRule REQUEST_HEADERS:Content-Type \"application/json\" \"id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON\"",
115+
"SecRule REQBODY_ERROR \"0\" \"id:'200441',phase:3,log\""
116+
]
117+
},
118+
{
119+
"enabled":1,
120+
"version_min":300000,
121+
"title":"Testing JSON request body parser - issue #1822 (2/2)",
122+
"expected":{
123+
"debug_log": "Target value: \"1\" .Variable: REQBODY_ERROR."
124+
},
125+
"client":{
126+
"ip":"200.249.12.31",
127+
"port":123
128+
},
129+
"request":{
130+
"headers":{
131+
"Host":"localhost",
132+
"User-Agent":"curl/7.38.0",
133+
"Accept":"*/*",
134+
"Cookie": "PHPSESSID=rAAAAAAA2t5uvjq435r4q7ib3vtdjq120",
135+
"Content-Type": "application/json"
136+
},
137+
"uri":"/?key=value&key=other_value",
138+
"method":"POST",
139+
"body": [
140+
"a"
141+
]
142+
},
143+
"server":{
144+
"ip":"200.249.12.31",
145+
"port":80
146+
},
147+
"rules":[
148+
"SecRuleEngine On",
149+
"SecRequestBodyAccess On",
150+
"SecRule REQUEST_HEADERS:Content-Type \"application/json\" \"id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON\"",
151+
"SecRule REQBODY_ERROR \"0\" \"id:'200441',phase:3,log\""
152+
]
82153
}
83154
]
84155

0 commit comments

Comments
 (0)