diff --git a/CHANGES b/CHANGES index 19d325ccf..13375d26a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ v3.0.x - YYYY-MMM-DD (To be released) ------------------------------------- + - Adds capture action to detectXSS + [Issue #1698 - @victorhora] - Temporarily accept invalid MULTIPART_SEMICOLON_MISSING operator [Issue #1701 - @victorhora] - Adds capture action to detectSQLi diff --git a/src/operators/detect_xss.cc b/src/operators/detect_xss.cc index 5b895823f..6d867fc11 100644 --- a/src/operators/detect_xss.cc +++ b/src/operators/detect_xss.cc @@ -25,22 +25,33 @@ namespace modsecurity { namespace operators { -bool DetectXSS::evaluate(Transaction *transaction, const std::string &input) { +bool DetectXSS::evaluate(Transaction *t, Rule *rule, + const std::string& input, std::shared_ptr ruleMessage) { int is_xss; is_xss = libinjection_xss(input.c_str(), input.length()); - if (transaction) { -#ifndef NO_LOGS + if (t) { if (is_xss) { - transaction->debug(5, "detected XSS using libinjection."); +#ifndef NO_LOGS + t->debug(5, "detected XSS using libinjection."); +#endif + if (rule && t + && rule->getActionsByName("capture").size() > 0) { + t->m_collections.m_tx_collection->storeOrUpdateFirst( + "0", std::string(input)); +#ifndef NO_LOGS + t->debug(7, "Added DetectXSS match TX.0: " + \ + std::string(input)); +#endif + } } else { - transaction->debug(9, "libinjection was not able to " \ - "find any XSS in: " + input); - } +#ifndef NO_LOGS + t->debug(9, "libinjection was not able to " \ + "find any XSS in: " + input); #endif + } } - return is_xss != 0; } diff --git a/src/operators/detect_xss.h b/src/operators/detect_xss.h index 07a29f49e..5d1c93f8b 100644 --- a/src/operators/detect_xss.h +++ b/src/operators/detect_xss.h @@ -31,7 +31,9 @@ class DetectXSS : public Operator { m_match_message.assign("detected XSS using libinjection."); } - bool evaluate(Transaction *transaction, const std::string &input); + bool evaluate(Transaction *t, Rule *rule, + const std::string& input, + std::shared_ptr ruleMessage) override; }; } // namespace operators diff --git a/test/test-cases/regression/operator-detectxss.json b/test/test-cases/regression/operator-detectxss.json new file mode 100644 index 000000000..f5ecc88ba --- /dev/null +++ b/test/test-cases/regression/operator-detectxss.json @@ -0,0 +1,46 @@ +[ + { + "enabled":1, + "version_min":300000, + "title":"Testing Operator :: @detectXSS", + "client":{ + "ip":"200.249.12.31", + "port":123 + }, + "server":{ + "ip":"200.249.12.31", + "port":80 + }, + "request":{ + "headers":{ + "Host":"localhost", + "User-Agent":"curl/7.38.0", + "Accept":"*/*", + "Content-Length": "27", + "Content-Type": "application/x-www-form-urlencoded" + }, + "uri":"/", + "method":"POST", + "body": [ + "param1=