Skip to content

Commit c855291

Browse files
committed
Adds support to the cmd_line transformation
Details on #965
1 parent d0e0002 commit c855291

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

src/actions/transformations/cmd_line.cc

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,58 @@ namespace modsecurity {
3030
namespace actions {
3131
namespace transformations {
3232

33-
CmdLine::CmdLine(std::string action)
34-
: Transformation(action) {
35-
this->action_kind = 1;
36-
}
3733

3834
std::string CmdLine::evaluate(std::string value,
3935
Transaction *transaction) {
40-
/**
41-
* @todo Implement the transformation CmdLine
42-
*/
43-
if (transaction) {
44-
#ifndef NO_LOGS
45-
transaction->debug(4, "Transformation CmdLine is not implemented yet.");
46-
#endif
36+
std::string ret;
37+
int space = 0;
38+
39+
for (auto& a : value) {
40+
switch (a) {
41+
/* remove some characters */
42+
case '"':
43+
case '\'':
44+
case '\\':
45+
case '^':
46+
//ret.append("i was here");
47+
break;
48+
49+
/* replace some characters to space (only one) */
50+
case ' ':
51+
case ',':
52+
case ';':
53+
case '\t':
54+
case '\r':
55+
case '\n':
56+
if (space == 0) {
57+
ret.append(" ");
58+
space++;
59+
}
60+
break;
61+
62+
/* remove space before / or ( */
63+
case '/':
64+
case '(':
65+
if (space) {
66+
ret.pop_back();
67+
}
68+
space = 0;
69+
ret.append(&a, 1);
70+
break;
71+
72+
/* copy normal characters */
73+
default :
74+
char b = std::tolower(a);
75+
ret.append(&b);
76+
space = 0;
77+
break;
78+
}
4779
}
48-
return value;
80+
81+
return ret;
4982
}
5083

84+
5185
} // namespace transformations
5286
} // namespace actions
5387
} // namespace modsecurity

src/actions/transformations/cmd_line.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ namespace transformations {
3030

3131
class CmdLine : public Transformation {
3232
public:
33-
explicit CmdLine(std::string action);
33+
explicit CmdLine(std::string action)
34+
: Transformation(action) { }
35+
3436
std::string evaluate(std::string exp,
3537
Transaction *transaction) override;
3638
};

0 commit comments

Comments
 (0)