Skip to content

Commit 23cf656

Browse files
author
Felipe Zimmerle
committed
Adds support to WEBAPPID variable
1 parent 082a3e3 commit 23cf656

File tree

9 files changed

+6801
-6611
lines changed

9 files changed

+6801
-6611
lines changed

CHANGES

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
v3.0.????? - ?
33
---------------------------
44

5-
- Adds support for SecWebAppId
5+
- Adds support to WEBAPPID variable.
6+
[Issue #1027 - @zimmerle, @victorhora]
7+
- Adds support for SecWebAppId.
68
[Issue #1442 - @zimmerle, @victorhora]
79
- Adds support for SecRuleRemoveByTag.
810
[Issue #1476 - @zimmerle, @victorhora]

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,5 @@ TESTS+=test/test-cases/regression/action-exec.json
291291
TESTS+=test/test-cases/regression/directive-sec_rule_script.json
292292
TESTS+=test/test-cases/regression/config-update-target-by-msg.json
293293
TESTS+=test/test-cases/regression/config-remove_by_msg.json
294+
TESTS+=test/test-cases/regression/variable-WEBAPPID.json
294295

src/parser/seclang-parser.cc

Lines changed: 1553 additions & 1543 deletions
Large diffs are not rendered by default.

src/parser/seclang-parser.hh

Lines changed: 1117 additions & 1105 deletions
Large diffs are not rendered by default.

src/parser/seclang-parser.yy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class Driver;
223223
#include "src/variables/server_name.h"
224224
#include "src/variables/server_port.h"
225225
#include "src/variables/session_id.h"
226+
#include "src/variables/web_app_id.h"
226227
#include "src/variables/time_day.h"
227228
#include "src/variables/time_epoch.h"
228229
#include "src/variables/time.h"
@@ -432,6 +433,7 @@ using modsecurity::operators::Operator;
432433
VARIABLE_UNIQUE_ID "UNIQUE_ID"
433434
VARIABLE_URL_ENCODED_ERROR "URLENCODED_ERROR"
434435
VARIABLE_USER_ID "USERID"
436+
VARIABLE_WEB_APP_ID "WEBAPPID"
435437
VARIABLE_STATUS "VARIABLE_STATUS"
436438
VARIABLE_IP "VARIABLE_IP"
437439
VARIABLE_GLOBAL "VARIABLE_GLOBAL"
@@ -2138,6 +2140,10 @@ var:
21382140
{
21392141
VARIABLE_CONTAINER($$, new Variables::Status());
21402142
}
2143+
| VARIABLE_WEB_APP_ID
2144+
{
2145+
VARIABLE_CONTAINER($$, new Variables::WebAppId());
2146+
}
21412147
| RUN_TIME_VAR_DUR
21422148
{
21432149
std::string name($1);

src/parser/seclang-scanner.cc

Lines changed: 3975 additions & 3962 deletions
Large diffs are not rendered by default.

src/parser/seclang-scanner.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ VARIABLE_IP (?i:(IP))
195195
VARIABLE_USER (?i:(USER))
196196
VARIABLE_STATUS (?i:(STATUS[^:]))
197197
VARIABLE_TX (?i:TX)
198+
VARIABLE_WEB_APP_ID (?i:WEBAPPID)
198199
RUN_TIME_VAR_BLD (?i:MODSEC_BUILD)
199200
RUN_TIME_VAR_DUR (?i:DURATION)
200201
RUN_TIME_VAR_ENV (?i:ENV)
@@ -771,6 +772,7 @@ p::make_CONFIG_SEC_RULE_REMOVE_BY_TAG(parserSanitizer(strchr(yytext, ' ') + 1),
771772
{VARIABLE_UNIQUE_ID} { return p::make_VARIABLE_UNIQUE_ID(*driver.loc.back()); }
772773
{VARIABLE_URL_ENCODED_ERROR} { return p::make_VARIABLE_URL_ENCODED_ERROR(*driver.loc.back()); }
773774
{VARIABLE_USER_ID} { return p::make_VARIABLE_USER_ID(*driver.loc.back()); }
775+
{VARIABLE_WEB_APP_ID} { return p::make_VARIABLE_WEB_APP_ID(*driver.loc.back()); }
774776
{VARIABLE_ARGS} { return p::make_VARIABLE_ARGS(*driver.loc.back()); }
775777
{VARIABLE_ARGS}[:] { BEGIN(EXPECTING_VAR_PARAMETER); return p::make_VARIABLE_ARGS(*driver.loc.back()); }
776778
{VARIABLE_ARGS_GET} { return p::make_VARIABLE_ARGS_GET(*driver.loc.back()); }

src/variables/web_app_id.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address security@modsecurity.org.
13+
*
14+
*/
15+
16+
#include <iostream>
17+
#include <string>
18+
#include <vector>
19+
#include <list>
20+
#include <utility>
21+
22+
#ifndef SRC_VARIABLES_WEB_APP_ID_H_
23+
#define SRC_VARIABLES_WEB_APP_ID_H_
24+
25+
#include "src/variables/variable.h"
26+
#include "modsecurity/rule.h"
27+
28+
namespace modsecurity {
29+
30+
class Transaction;
31+
namespace Variables {
32+
33+
class WebAppId : public Variable {
34+
public:
35+
explicit WebAppId()
36+
: Variable("WEBAPPID") { }
37+
38+
void evaluate(Transaction *transaction,
39+
Rule *rule,
40+
std::vector<const collection::Variable *> *l) override {
41+
const std::string name("WEBAPPID");
42+
const std::string rname = transaction->m_rules->m_secWebAppId.m_value;
43+
l->push_back(new collection::Variable(&m_name, &rname));
44+
}
45+
};
46+
47+
} // namespace Variables
48+
} // namespace modsecurity
49+
50+
#endif // SRC_VARIABLES_WEB_APP_ID_H_
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[
2+
{
3+
"enabled":1,
4+
"version_min":300000,
5+
"title":"Testing Variables :: WEBAPPID (1)",
6+
"client":{
7+
"ip":"200.249.12.31",
8+
"port":123
9+
},
10+
"server":{
11+
"ip":"200.249.12.31",
12+
"port":80
13+
},
14+
"request":{
15+
"headers":{
16+
"Host":"localhost",
17+
"User-Agent":"curl/7.38.0",
18+
"Accept":"*/*",
19+
"Content-Length": "27",
20+
"Content-Type": "application/x-www-form-urlencoded",
21+
"Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
22+
},
23+
"uri":"/",
24+
"method":"POST",
25+
"body": [
26+
"param1=value1&param2=value2"
27+
]
28+
},
29+
"response":{
30+
"headers":{
31+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
32+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
33+
"Content-Type":"text/html"
34+
},
35+
"body":[
36+
"no need."
37+
]
38+
},
39+
"expected":{
40+
"debug_log":"t:trim: \"\""
41+
},
42+
"rules":[
43+
"SecRuleEngine On",
44+
"SecRule WEBAPPID \"@contains test \" \"id:1,phase:3,pass,t:trim\""
45+
]
46+
},
47+
{
48+
"enabled":1,
49+
"version_min":300000,
50+
"title":"Testing Variables :: WEBAPPID (2)",
51+
"client":{
52+
"ip":"200.249.12.31",
53+
"port":123
54+
},
55+
"server":{
56+
"ip":"200.249.12.31",
57+
"port":80
58+
},
59+
"request":{
60+
"headers":{
61+
"Host":"localhost",
62+
"User-Agent":"curl/7.38.0",
63+
"Accept":"*/*",
64+
"Content-Length": "27",
65+
"Content-Type": "application/x-www-form-urlencoded",
66+
"AuThOrIzAtIoN": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="
67+
},
68+
"uri":"/",
69+
"method":"POST",
70+
"body": [
71+
"param1=value1&param2=value2"
72+
]
73+
},
74+
"response":{
75+
"headers":{
76+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
77+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
78+
"Content-Type":"text/html"
79+
},
80+
"body":[
81+
"no need."
82+
]
83+
},
84+
"expected":{
85+
"debug_log":"Target value: \"bisteka\""
86+
},
87+
"rules":[
88+
"SecRuleEngine On",
89+
"SecWebAppId bisteka",
90+
"SecRule WEBAPPID \"@contains test \" \"id:1,phase:3,pass,t:trim\""
91+
]
92+
}
93+
]
94+

0 commit comments

Comments
 (0)