From ec34f676c62a61999a88d4f31120b00da8572bf5 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Wed, 22 Jul 2015 02:05:58 -0300 Subject: [PATCH] Adds support to variables: REQUEST_{METHOD,PROTOCOL,URI,URI_RAW} --- src/assay.cc | 4 ++ .../regression/variable-REQUEST_METHOD.json | 45 +++++++++++++++++++ .../regression/variable-REQUEST_PROTOCOL.json | 45 +++++++++++++++++++ .../regression/variable-REQUEST_URI.json | 45 +++++++++++++++++++ .../regression/variable-REQUEST_URI_RAW.json | 45 +++++++++++++++++++ 5 files changed, 184 insertions(+) create mode 100644 test/test-cases/regression/variable-REQUEST_METHOD.json create mode 100644 test/test-cases/regression/variable-REQUEST_PROTOCOL.json create mode 100644 test/test-cases/regression/variable-REQUEST_URI.json create mode 100644 test/test-cases/regression/variable-REQUEST_URI_RAW.json diff --git a/src/assay.cc b/src/assay.cc index 1f5a09b0..3b6e7bd8 100644 --- a/src/assay.cc +++ b/src/assay.cc @@ -239,6 +239,10 @@ int Assay::processURI(const char *uri, const char *protocol, path_info.length() - offset); store_variable("REQUEST_BASENAME", basename); } + store_variable("REQUEST_METHOD", protocol); + store_variable("REQUEST_PROTOCOL", "HTTP/" + std::string(http_version)); + store_variable("REQUEST_URI", uri); + store_variable("REQUEST_URI_RAW", uri); if (pos != NULL && strlen(pos) > 2) { /** diff --git a/test/test-cases/regression/variable-REQUEST_METHOD.json b/test/test-cases/regression/variable-REQUEST_METHOD.json new file mode 100644 index 00000000..8cd40436 --- /dev/null +++ b/test/test-cases/regression/variable-REQUEST_METHOD.json @@ -0,0 +1,45 @@ +[ + { + "enabled":1, + "version_min":300000, + "title":"Testing Variables :: REQUEST_METHOD", + "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":"*/*" + }, + "uri":"/?key=value&key=other_value", + "protocol":"GET", + "http_version":1.1 + }, + "response":{ + "headers":{ + "Date":"Mon, 13 Jul 2015 20:02:41 GMT", + "Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT", + "Content-Type":"text/html" + }, + "body":[ + "no need." + ] + }, + "expected":{ + "debug_log":"Target value: \"GET\" \\(Variable: REQUEST_METHOD\\)" + }, + "rules":[ + "SecRuleEngine On", + "SecDebugLog \/tmp\/modsec_debug.log", + "SecDebugLogLevel 9", + "SecRule REQUEST_METHOD \"@contains test \" \"pass,t:trim\"" + ] + } +] + diff --git a/test/test-cases/regression/variable-REQUEST_PROTOCOL.json b/test/test-cases/regression/variable-REQUEST_PROTOCOL.json new file mode 100644 index 00000000..2acc034e --- /dev/null +++ b/test/test-cases/regression/variable-REQUEST_PROTOCOL.json @@ -0,0 +1,45 @@ +[ + { + "enabled":1, + "version_min":300000, + "title":"Testing Variables :: REQUEST_PROTOCOL", + "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":"*/*" + }, + "uri":"/?key=value&key=other_value", + "protocol":"GET", + "http_version":1.1 + }, + "response":{ + "headers":{ + "Date":"Mon, 13 Jul 2015 20:02:41 GMT", + "Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT", + "Content-Type":"text/html" + }, + "body":[ + "no need." + ] + }, + "expected":{ + "debug_log":"Target value: \"HTTP/1.1\" \\(Variable: REQUEST_PROTOCOL\\)" + }, + "rules":[ + "SecRuleEngine On", + "SecDebugLog \/tmp\/modsec_debug.log", + "SecDebugLogLevel 9", + "SecRule REQUEST_PROTOCOL \"@contains test \" \"pass,t:trim\"" + ] + } +] + diff --git a/test/test-cases/regression/variable-REQUEST_URI.json b/test/test-cases/regression/variable-REQUEST_URI.json new file mode 100644 index 00000000..21ae4ae4 --- /dev/null +++ b/test/test-cases/regression/variable-REQUEST_URI.json @@ -0,0 +1,45 @@ +[ + { + "enabled":1, + "version_min":300000, + "title":"Testing Variables :: REQUEST_URI", + "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":"*/*" + }, + "uri":"/?key=value&key=other_value", + "protocol":"GET", + "http_version":1.1 + }, + "response":{ + "headers":{ + "Date":"Mon, 13 Jul 2015 20:02:41 GMT", + "Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT", + "Content-Type":"text/html" + }, + "body":[ + "no need." + ] + }, + "expected":{ + "debug_log":"Target value: \"/\\?key=value\\&key=other_value\" \\(Variable: REQUEST_URI\\)" + }, + "rules":[ + "SecRuleEngine On", + "SecDebugLog \/tmp\/modsec_debug.log", + "SecDebugLogLevel 9", + "SecRule REQUEST_URI \"@contains test \" \"pass,t:trim\"" + ] + } +] + diff --git a/test/test-cases/regression/variable-REQUEST_URI_RAW.json b/test/test-cases/regression/variable-REQUEST_URI_RAW.json new file mode 100644 index 00000000..ab5a7677 --- /dev/null +++ b/test/test-cases/regression/variable-REQUEST_URI_RAW.json @@ -0,0 +1,45 @@ +[ + { + "enabled":1, + "version_min":300000, + "title":"Testing Variables :: REQUEST_URI_RAW", + "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":"*/*" + }, + "uri":"/?key=value&key=other_value", + "protocol":"GET", + "http_version":1.1 + }, + "response":{ + "headers":{ + "Date":"Mon, 13 Jul 2015 20:02:41 GMT", + "Last-Modified":"Sun, 26 Oct 2014 22:33:37 GMT", + "Content-Type":"text/html" + }, + "body":[ + "no need." + ] + }, + "expected":{ + "debug_log":"Target value: \"/\\?key=value\\&key=other_value\" \\(Variable: REQUEST_URI_RAW\\)" + }, + "rules":[ + "SecRuleEngine On", + "SecDebugLog \/tmp\/modsec_debug.log", + "SecDebugLogLevel 9", + "SecRule REQUEST_URI_RAW \"@contains test \" \"pass,t:trim\"" + ] + } +] +