mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Fix @pmFromFile with multiple files issue
This commit is contained in:
parent
31507404e6
commit
6089b6b06b
@ -20,7 +20,9 @@
|
|||||||
#include "src/operators/operator.h"
|
#include "src/operators/operator.h"
|
||||||
#include "src/utils/https_client.h"
|
#include "src/utils/https_client.h"
|
||||||
#include "src/utils/system.h"
|
#include "src/utils/system.h"
|
||||||
|
#include "src/utils/string.h"
|
||||||
|
|
||||||
|
using namespace modsecurity::utils::string;
|
||||||
|
|
||||||
namespace modsecurity {
|
namespace modsecurity {
|
||||||
namespace operators {
|
namespace operators {
|
||||||
@ -44,39 +46,47 @@ bool PmFromFile::isComment(const std::string &s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool PmFromFile::init(const std::string &config, std::string *error) {
|
bool PmFromFile::init(const std::string &config, std::string *error) {
|
||||||
std::istream *iss;
|
std::vector<std::string> tokens = split(m_param, ' ');
|
||||||
|
|
||||||
if (m_param.compare(0, 8, "https://") == 0) {
|
for (const auto& token : tokens) {
|
||||||
Utils::HttpsClient client;
|
if (! token.empty()) {
|
||||||
bool ret = client.download(m_param);
|
|
||||||
if (ret == false) {
|
std::istream *iss;
|
||||||
error->assign(client.error);
|
|
||||||
return false;
|
if (token.compare(0, 8, "https://") == 0) {
|
||||||
}
|
Utils::HttpsClient client;
|
||||||
iss = new std::stringstream(client.content);
|
bool ret = client.download(token);
|
||||||
} else {
|
if (ret == false) {
|
||||||
std::string err;
|
error->assign(client.error);
|
||||||
std::string resource = utils::find_resource(m_param, config, &err);
|
return false;
|
||||||
iss = new std::ifstream(resource, std::ios::in);
|
}
|
||||||
|
iss = new std::stringstream(client.content);
|
||||||
|
} else {
|
||||||
|
std::string err;
|
||||||
|
std::string resource = utils::find_resource(token, config, &err);
|
||||||
|
iss = new std::ifstream(resource, std::ios::in);
|
||||||
|
|
||||||
|
if (((std::ifstream *)iss)->is_open() == false) {
|
||||||
|
error->assign("Failed to open file: '" + token + "'. " + err);
|
||||||
|
delete iss;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::string line; std::getline(*iss, line); ) {
|
||||||
|
if (isComment(line) == false) {
|
||||||
|
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (((std::ifstream *)iss)->is_open() == false) {
|
|
||||||
error->assign("Failed to open file: " + m_param + ". " + err);
|
|
||||||
delete iss;
|
delete iss;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::string line; std::getline(*iss, line); ) {
|
|
||||||
if (isComment(line) == false) {
|
|
||||||
acmp_add_pattern(m_p, line.c_str(), NULL, NULL, line.length());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (m_p->is_failtree_done == 0) {
|
while (m_p->is_failtree_done == 0) {
|
||||||
acmp_prepare(m_p);
|
acmp_prepare(m_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete iss;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
test/test-cases/data/pattern-file1.data
Normal file
2
test/test-cases/data/pattern-file1.data
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# comment
|
||||||
|
pattern1
|
2
test/test-cases/data/pattern-file2.data
Normal file
2
test/test-cases/data/pattern-file2.data
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# comment
|
||||||
|
pattern2
|
39
test/test-cases/regression/operator-pmfromfile.json
Normal file
39
test/test-cases/regression/operator-pmfromfile.json
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"enabled": 1,
|
||||||
|
"version_min": 300000,
|
||||||
|
"version_max": 0,
|
||||||
|
"title": "pmFromFile operator test",
|
||||||
|
"client": {
|
||||||
|
"ip": "10.20.30.40",
|
||||||
|
"port": 2313
|
||||||
|
},
|
||||||
|
"server": {
|
||||||
|
"ip": "1.2.3.4",
|
||||||
|
"port": 80
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"headers": {
|
||||||
|
"Host": "foobar.com"
|
||||||
|
},
|
||||||
|
"uri": "\/test.php?param1=pattern2",
|
||||||
|
"method": "GET",
|
||||||
|
"http_version": 1.1,
|
||||||
|
"body": ""
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": "text\/html; charset=utf-8\n\r",
|
||||||
|
"Content-Length": "10\n\r"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"expected": {
|
||||||
|
"debug_log": "Rule returned 1",
|
||||||
|
"http_code": 403
|
||||||
|
},
|
||||||
|
"rules": [
|
||||||
|
"SecRuleEngine On",
|
||||||
|
"SecRule ARGS \"@pmFromFile test-cases/data/pattern-file1.data test-cases/data/pattern-file2.data\" \"phase:1,id:999,deny\""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
@ -86,6 +86,7 @@ TESTS+=test/test-cases/regression/operator-fuzzyhash.json
|
|||||||
TESTS+=test/test-cases/regression/operator-inpectFile.json
|
TESTS+=test/test-cases/regression/operator-inpectFile.json
|
||||||
TESTS+=test/test-cases/regression/operator-ipMatchFromFile.json
|
TESTS+=test/test-cases/regression/operator-ipMatchFromFile.json
|
||||||
TESTS+=test/test-cases/regression/operator-pm.json
|
TESTS+=test/test-cases/regression/operator-pm.json
|
||||||
|
TESTS+=test/test-cases/regression/operator-pmfromfile.json
|
||||||
TESTS+=test/test-cases/regression/operator-rx.json
|
TESTS+=test/test-cases/regression/operator-rx.json
|
||||||
TESTS+=test/test-cases/regression/operator-rxGlobal.json
|
TESTS+=test/test-cases/regression/operator-rxGlobal.json
|
||||||
TESTS+=test/test-cases/regression/operator-UnconditionalMatch.json
|
TESTS+=test/test-cases/regression/operator-UnconditionalMatch.json
|
||||||
|
Loading…
x
Reference in New Issue
Block a user