Skip to content

Commit d00ea51

Browse files
author
Felipe Zimmerle
committed
Adds initial support to drop action
1 parent ba4273b commit d00ea51

File tree

10 files changed

+3339
-3171
lines changed

10 files changed

+3339
-3171
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
v3.0.4 - YYYY-MMM-DD (to be released)
22
-------------------------------------
33

4+
- Adds initially support to the drop action.
5+
[@zimmerle]
46
- Complete merging of particular rule properties
57
[Issue #1978 - @defanator]
68
- Replaces AC_CHECK_FILE with 'test -f'

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ ACTIONS = \
121121
actions/ctl/request_body_access.cc\
122122
actions/disruptive/allow.cc \
123123
actions/disruptive/deny.cc \
124+
actions/disruptive/drop.cc \
124125
actions/disruptive/redirect.cc \
125126
actions/disruptive/pass.cc \
126127
actions/exec.cc \

src/actions/disruptive/drop.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 security@modsecurity.org.
13+
*
14+
*/
15+
16+
#include "src/actions/disruptive/drop.h"
17+
18+
#include <string.h>
19+
#include <iostream>
20+
#include <string>
21+
#include <cstring>
22+
#include <memory>
23+
24+
#include "modsecurity/transaction.h"
25+
26+
namespace modsecurity {
27+
namespace actions {
28+
namespace disruptive {
29+
30+
31+
bool Drop::evaluate(Rule *rule, Transaction *transaction,
32+
std::shared_ptr<RuleMessage> rm) {
33+
ms_dbg_a(transaction, 8, "Running action drop " \
34+
"[executing deny instead of drop.]");
35+
36+
if (transaction->m_it.status == 200) {
37+
transaction->m_it.status = 403;
38+
}
39+
40+
transaction->m_it.disruptive = true;
41+
intervention::freeLog(&transaction->m_it);
42+
rm->m_isDisruptive = true;
43+
transaction->m_it.log = strdup(
44+
rm->log(RuleMessage::LogMessageInfo::ClientLogMessageInfo).c_str());
45+
46+
return true;
47+
}
48+
49+
50+
} // namespace disruptive
51+
} // namespace actions
52+
} // namespace modsecurity

src/parser/location.hh

Lines changed: 137 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// A Bison parser, made by GNU Bison 3.1.
1+
// A Bison parser, made by GNU Bison 3.2.
22

33
// Locations for Bison parsers in C++
44

@@ -38,11 +38,144 @@
3838
#ifndef YY_YY_LOCATION_HH_INCLUDED
3939
# define YY_YY_LOCATION_HH_INCLUDED
4040

41-
# include "position.hh"
41+
# include <algorithm> // std::max
42+
# include <iostream>
43+
# include <string>
44+
45+
# ifndef YY_NULLPTR
46+
# if defined __cplusplus
47+
# if 201103L <= __cplusplus
48+
# define YY_NULLPTR nullptr
49+
# else
50+
# define YY_NULLPTR 0
51+
# endif
52+
# else
53+
# define YY_NULLPTR ((void*)0)
54+
# endif
55+
# endif
4256

4357

4458
namespace yy {
45-
#line 46 "location.hh" // location.cc:290
59+
#line 60 "location.hh" // location.cc:339
60+
/// Abstract a position.
61+
class position
62+
{
63+
public:
64+
/// Construct a position.
65+
explicit position (std::string* f = YY_NULLPTR,
66+
unsigned l = 1u,
67+
unsigned c = 1u)
68+
: filename (f)
69+
, line (l)
70+
, column (c)
71+
{}
72+
73+
74+
/// Initialization.
75+
void initialize (std::string* fn = YY_NULLPTR,
76+
unsigned l = 1u,
77+
unsigned c = 1u)
78+
{
79+
filename = fn;
80+
line = l;
81+
column = c;
82+
}
83+
84+
/** \name Line and Column related manipulators
85+
** \{ */
86+
/// (line related) Advance to the COUNT next lines.
87+
void lines (int count = 1)
88+
{
89+
if (count)
90+
{
91+
column = 1u;
92+
line = add_ (line, count, 1);
93+
}
94+
}
95+
96+
/// (column related) Advance to the COUNT next columns.
97+
void columns (int count = 1)
98+
{
99+
column = add_ (column, count, 1);
100+
}
101+
/** \} */
102+
103+
/// File name to which this position refers.
104+
std::string* filename;
105+
/// Current line number.
106+
unsigned line;
107+
/// Current column number.
108+
unsigned column;
109+
110+
private:
111+
/// Compute max (min, lhs+rhs).
112+
static unsigned add_ (unsigned lhs, int rhs, int min)
113+
{
114+
return static_cast<unsigned> (std::max (min,
115+
static_cast<int> (lhs) + rhs));
116+
}
117+
};
118+
119+
/// Add \a width columns, in place.
120+
inline position&
121+
operator+= (position& res, int width)
122+
{
123+
res.columns (width);
124+
return res;
125+
}
126+
127+
/// Add \a width columns.
128+
inline position
129+
operator+ (position res, int width)
130+
{
131+
return res += width;
132+
}
133+
134+
/// Subtract \a width columns, in place.
135+
inline position&
136+
operator-= (position& res, int width)
137+
{
138+
return res += -width;
139+
}
140+
141+
/// Subtract \a width columns.
142+
inline position
143+
operator- (position res, int width)
144+
{
145+
return res -= width;
146+
}
147+
148+
/// Compare two position objects.
149+
inline bool
150+
operator== (const position& pos1, const position& pos2)
151+
{
152+
return (pos1.line == pos2.line
153+
&& pos1.column == pos2.column
154+
&& (pos1.filename == pos2.filename
155+
|| (pos1.filename && pos2.filename
156+
&& *pos1.filename == *pos2.filename)));
157+
}
158+
159+
/// Compare two position objects.
160+
inline bool
161+
operator!= (const position& pos1, const position& pos2)
162+
{
163+
return !(pos1 == pos2);
164+
}
165+
166+
/** \brief Intercept output stream redirection.
167+
** \param ostr the destination output stream
168+
** \param pos a reference to the position to redirect
169+
*/
170+
template <typename YYChar>
171+
std::basic_ostream<YYChar>&
172+
operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
173+
{
174+
if (pos.filename)
175+
ostr << *pos.filename << ':';
176+
return ostr << pos.line << '.' << pos.column;
177+
}
178+
46179
/// Abstract a location.
47180
class location
48181
{
@@ -185,5 +318,5 @@ namespace yy {
185318

186319

187320
} // yy
188-
#line 189 "location.hh" // location.cc:290
321+
#line 322 "location.hh" // location.cc:339
189322
#endif // !YY_YY_LOCATION_HH_INCLUDED

0 commit comments

Comments
 (0)