Skip to content

Commit 1a965a4

Browse files
committed
Fix some name handling for ARGS_*NAMES: regex SecRuleUpdateTargetById, etc.
1 parent 76ce673 commit 1a965a4

File tree

6 files changed

+127
-5
lines changed

6 files changed

+127
-5
lines changed

CHANGES

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

4+
- Fix some name handling for ARGS_*NAMES: regex SecRuleUpdateTargetById, etc.
5+
[Issue #2627, #2648 - @lontchianicet, @victorserbu2709, @martinhsv]
46
- Adjust confusing variable name in setRequestBody method
57
[Issue #2635 @Mesar-Ali, @martinhsv]
68
- Multipart names/filenames may include single quote if double-quote enclosed

headers/modsecurity/anchored_set_variable_translation_proxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class AnchoredSetVariableTranslationProxy {
4444
{
4545
m_translate = [](std::string *name, std::vector<const VariableValue *> *l) {
4646
for (int i = 0; i < l->size(); ++i) {
47-
VariableValue *newVariableValue = new VariableValue(name, &l->at(i)->getKey());
47+
VariableValue *newVariableValue = new VariableValue(name, &l->at(i)->getKey(), &l->at(i)->getKey());
4848
const VariableValue *oldVariableValue = l->at(i);
4949
l->at(i) = newVariableValue;
5050
for (auto &oldOrigin : oldVariableValue->getOrigin()) {

test/test-cases/regression/config-update-target-by-id.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,85 @@
118118
"SecRuleUpdateTargetById 1 !ARGS:mixpanel",
119119
"SecRule ARGS \"@contains value\" \"id:1,t:trim,tag:'test',deny\""
120120
]
121+
},
122+
{
123+
"enabled":1,
124+
"version_min":300000,
125+
"title":"SecRuleUpdateTargetById - exclude from ARGS_NAMES using regex (match)",
126+
"client":{
127+
"ip":"200.249.12.31",
128+
"port":123
129+
},
130+
"server":{
131+
"ip":"200.249.12.31",
132+
"port":80
133+
},
134+
"request":{
135+
"headers":{
136+
"Host":"localhost",
137+
"User-Agent":"curl/7.38.0",
138+
"Accept":"*/*"
139+
},
140+
"uri":"/?xxxyyy=value",
141+
"method":"GET"
142+
},
143+
"response":{
144+
"headers":{
145+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
146+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
147+
"Content-Type":"text/html"
148+
},
149+
"body":[
150+
"no need."
151+
]
152+
},
153+
"expected":{
154+
"http_code": 200
155+
},
156+
"rules":[
157+
"SecRuleEngine On",
158+
"SecRuleUpdateTargetById 1 \"!ARGS:/xxx/\"",
159+
"SecRule ARGS_NAMES \"@contains yyy\" \"id:1,phase:2,deny,status:403\""
160+
]
161+
},
162+
{
163+
"enabled":1,
164+
"version_min":300000,
165+
"title":"SecRuleUpdateTargetById - exclude from ARGS_NAMES using regex (no match)",
166+
"client":{
167+
"ip":"200.249.12.31",
168+
"port":123
169+
},
170+
"server":{
171+
"ip":"200.249.12.31",
172+
"port":80
173+
},
174+
"request":{
175+
"headers":{
176+
"Host":"localhost",
177+
"User-Agent":"curl/7.38.0",
178+
"Accept":"*/*"
179+
},
180+
"uri":"/?xxyyy=value",
181+
"method":"GET"
182+
},
183+
"response":{
184+
"headers":{
185+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
186+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
187+
"Content-Type":"text/html"
188+
},
189+
"body":[
190+
"no need."
191+
]
192+
},
193+
"expected":{
194+
"http_code": 403
195+
},
196+
"rules":[
197+
"SecRuleEngine On",
198+
"SecRuleUpdateTargetById 1 \"!ARGS:/xxx/\"",
199+
"SecRule ARGS_NAMES \"@contains yyy\" \"id:1,phase:2,deny,status:403\""
200+
]
121201
}
122202
]

test/test-cases/regression/variable-ARGS_NAMES.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
]
210210
},
211211
"expected":{
212-
"debug_log":"Target value: \"name1\" \\(Variable: ARGS_NAMES\\)"
212+
"debug_log":"Target value: \"name1\" \\(Variable: ARGS_NAMES:name1\\)"
213213
},
214214
"rules":[
215215
"SecRuleEngine On",

test/test-cases/regression/variable-ARGS_POST_NAMES.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
]
132132
},
133133
"expected":{
134-
"debug_log":"Target value: \"name1\" \\(Variable: ARGS_POST_NAMES\\)"
134+
"debug_log":"Target value: \"name1\" \\(Variable: ARGS_POST_NAMES:name1\\)"
135135
},
136136
"rules":[
137137
"SecRuleEngine On",

test/test-cases/regression/variable-MATCHED_VAR_NAME.json

Lines changed: 42 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 Variables :: MATCHED_VAR_NAME (1/2)",
5+
"title":"Testing Variables :: MATCHED_VAR_NAME (1/3)",
66
"client":{
77
"ip":"200.249.12.31",
88
"port":123
@@ -43,7 +43,7 @@
4343
{
4444
"enabled":1,
4545
"version_min":300000,
46-
"title":"Testing Variables :: MATCHED_VAR_NAME (2/2)",
46+
"title":"Testing Variables :: MATCHED_VAR_NAME (2/3)",
4747
"client":{
4848
"ip":"200.249.12.31",
4949
"port":123
@@ -81,6 +81,46 @@
8181
"SecRule MATCHED_VAR_NAME \"@contains asdf\" \"\"",
8282
"SecRule MATCHED_VAR_NAME \"@contains value\" \"id:29\""
8383
]
84+
},
85+
{
86+
"enabled":1,
87+
"version_min":300000,
88+
"title":"Testing Variables :: MATCHED_VAR_NAME (3/3)",
89+
"client":{
90+
"ip":"200.249.12.31",
91+
"port":123
92+
},
93+
"server":{
94+
"ip":"200.249.12.31",
95+
"port":80
96+
},
97+
"request":{
98+
"headers":{
99+
"Host":"localhost",
100+
"User-Agent":"curl/7.38.0",
101+
"Accept":"*/*"
102+
},
103+
"uri":"/?key1=value&key2=other_value",
104+
"method":"GET"
105+
},
106+
"response":{
107+
"headers":{
108+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
109+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
110+
"Content-Type":"text/html"
111+
},
112+
"body":[
113+
"no need."
114+
]
115+
},
116+
"expected":{
117+
"debug_log":" Target value: \"ARGS_NAMES:key1\" \\(Variable: MATCHED_VAR_NAME\\)"
118+
},
119+
"rules":[
120+
"SecRuleEngine On",
121+
"SecRule ARGS_NAMES \"@contains ey1\" \"chain,id:30,pass\"",
122+
"SecRule MATCHED_VAR_NAME \"@contains key1\" \"id:31\""
123+
]
84124
}
85125
]
86126

0 commit comments

Comments
 (0)