Skip to content

Commit 9cb3f23

Browse files
author
Felipe Zimmerle
committed
Adds support to setrsc action
1 parent 616a95b commit 9cb3f23

File tree

10 files changed

+4672
-4383
lines changed

10 files changed

+4672
-4383
lines changed

Diff for: Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ TESTS+=test/test-cases/regression/issue-960.json
126126
TESTS+=test/test-cases/regression/request-body-parser-xml-validade-dtd.json
127127
TESTS+=test/test-cases/regression/variable-TIME_MIN.json
128128
TESTS+=test/test-cases/regression/action-setuid.json
129+
TESTS+=test/test-cases/regression/action-setrsc.json
129130
TESTS+=test/test-cases/regression/issue-1152.json
130131
TESTS+=test/test-cases/regression/config-calling_phases_by_name.json
131132
TESTS+=test/test-cases/regression/variable-USERID.json

Diff for: src/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ ACTIONS = \
128128
actions/rev.cc \
129129
actions/rule_id.cc \
130130
actions/severity.cc \
131+
actions/set_rsc.cc \
131132
actions/set_sid.cc \
132133
actions/set_uid.cc \
133134
actions/set_var.cc \

Diff for: src/actions/set_rsc.cc

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 [email protected].
13+
*
14+
*/
15+
16+
#include "src/actions/set_rsc.h"
17+
18+
#include <iostream>
19+
#include <string>
20+
21+
#include "modsecurity/transaction.h"
22+
#include "modsecurity/rule.h"
23+
#include "src/macro_expansion.h"
24+
25+
26+
namespace modsecurity {
27+
namespace actions {
28+
29+
30+
bool SetRSC::init(std::string *error) {
31+
m_collection_key = std::string(m_parser_payload, 0,
32+
m_parser_payload.length());
33+
34+
if (m_collection_key.empty()) {
35+
error->assign("Missing collection key");
36+
return false;
37+
}
38+
39+
return true;
40+
}
41+
42+
43+
bool SetRSC::evaluate(Rule *rule, Transaction *t) {
44+
std::string colNameExpanded = MacroExpansion::expand(m_collection_key, t);
45+
46+
#ifndef NO_LOGS
47+
t->debug(8, "RESOURCE initiated with value: \'"
48+
+ colNameExpanded + "\'.");
49+
#endif
50+
51+
t->m_collections.m_resource_collection_key = colNameExpanded;
52+
t->m_variableResource.set(colNameExpanded, t->m_variableOffset);
53+
54+
return true;
55+
}
56+
57+
} // namespace actions
58+
} // namespace modsecurity

Diff for: src/actions/set_rsc.h

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 [email protected].
13+
*
14+
*/
15+
16+
#include <string>
17+
18+
#include "modsecurity/actions/action.h"
19+
20+
#ifndef SRC_ACTIONS_SET_RSC_H_
21+
#define SRC_ACTIONS_SET_RSC_H_
22+
23+
class Transaction;
24+
25+
namespace modsecurity {
26+
class Transaction;
27+
namespace actions {
28+
29+
30+
class SetRSC : public Action {
31+
public:
32+
explicit SetRSC(std::string _action)
33+
: Action(_action) { }
34+
35+
bool evaluate(Rule *rule, Transaction *transaction) override;
36+
bool init(std::string *error) override;
37+
38+
private:
39+
std::string m_collection_key;
40+
};
41+
42+
43+
} // namespace actions
44+
} // namespace modsecurity
45+
46+
#endif // SRC_ACTIONS_SET_RSC_H_

0 commit comments

Comments
 (0)