Skip to content

Commit 22334c9

Browse files
victorhoraFelipe Zimmerle
authored andcommitted
Adds capture action to detectXSS
1 parent b59d19e commit 22334c9

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

CHANGES

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

4+
- Adds capture action to detectXSS
5+
[Issue #1698 - @victorhora]
46
- Temporarily accept invalid MULTIPART_SEMICOLON_MISSING operator
57
[Issue #1701 - @victorhora]
68
- Adds capture action to detectSQLi

src/operators/detect_xss.cc

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,33 @@ namespace modsecurity {
2525
namespace operators {
2626

2727

28-
bool DetectXSS::evaluate(Transaction *transaction, const std::string &input) {
28+
bool DetectXSS::evaluate(Transaction *t, Rule *rule,
29+
const std::string& input, std::shared_ptr<RuleMessage> ruleMessage) {
2930
int is_xss;
3031

3132
is_xss = libinjection_xss(input.c_str(), input.length());
3233

33-
if (transaction) {
34-
#ifndef NO_LOGS
34+
if (t) {
3535
if (is_xss) {
36-
transaction->debug(5, "detected XSS using libinjection.");
36+
#ifndef NO_LOGS
37+
t->debug(5, "detected XSS using libinjection.");
38+
#endif
39+
if (rule && t
40+
&& rule->getActionsByName("capture").size() > 0) {
41+
t->m_collections.m_tx_collection->storeOrUpdateFirst(
42+
"0", std::string(input));
43+
#ifndef NO_LOGS
44+
t->debug(7, "Added DetectXSS match TX.0: " + \
45+
std::string(input));
46+
#endif
47+
}
3748
} else {
38-
transaction->debug(9, "libinjection was not able to " \
39-
"find any XSS in: " + input);
40-
}
49+
#ifndef NO_LOGS
50+
t->debug(9, "libinjection was not able to " \
51+
"find any XSS in: " + input);
4152
#endif
53+
}
4254
}
43-
4455
return is_xss != 0;
4556
}
4657

src/operators/detect_xss.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class DetectXSS : public Operator {
3131
m_match_message.assign("detected XSS using libinjection.");
3232
}
3333

34-
bool evaluate(Transaction *transaction, const std::string &input);
34+
bool evaluate(Transaction *t, Rule *rule,
35+
const std::string& input,
36+
std::shared_ptr<RuleMessage> ruleMessage) override;
3537
};
3638

3739
} // namespace operators
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"enabled":1,
4+
"version_min":300000,
5+
"title":"Testing Operator :: @detectXSS",
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+
},
22+
"uri":"/",
23+
"method":"POST",
24+
"body": [
25+
"param1=<script>alert(1)</script&param2=value2"
26+
]
27+
},
28+
"response":{
29+
"headers":{
30+
"Date":"Mon, 13 Jul 2015 20:02:41 GMT",
31+
"Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT",
32+
"Content-Type":"text/html"
33+
},
34+
"body":[
35+
"no need."
36+
]
37+
},
38+
"expected":{
39+
"debug_log":"Added DetectXSS match TX.0: f\\(f\\(f"
40+
},
41+
"rules":[
42+
"SecRuleEngine On",
43+
"SecRule ARGS \"@detectXSS\" \"id:1,phase:2,capture,pass,t:trim\""
44+
]
45+
}
46+
]

0 commit comments

Comments
 (0)