mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Adds operation unset to setVar action
This commit is contained in:
committed by
Felipe Zimmerle
parent
e95555132e
commit
b516cc6de1
@@ -46,7 +46,7 @@ bool SetVar::init(std::string *error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resolv operation
|
// Resolv operation
|
||||||
m_operation = setToOne;
|
m_operation = setToOneOperation;
|
||||||
pos = m_parser_payload.find("=");
|
pos = m_parser_payload.find("=");
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
m_operation = setOperation;
|
m_operation = setOperation;
|
||||||
@@ -71,7 +71,7 @@ bool SetVar::init(std::string *error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Variable name
|
// Variable name
|
||||||
if (m_operation == setToOne) {
|
if (m_operation == setToOneOperation) {
|
||||||
m_variableName = std::string(m_parser_payload, pos + 1,
|
m_variableName = std::string(m_parser_payload, pos + 1,
|
||||||
m_parser_payload.length()
|
m_parser_payload.length()
|
||||||
- (pos + 1));
|
- (pos + 1));
|
||||||
@@ -111,8 +111,12 @@ bool SetVar::evaluate(Rule *rule, Transaction *transm_parser_payload) {
|
|||||||
|
|
||||||
if (m_operation == setOperation) {
|
if (m_operation == setOperation) {
|
||||||
targetValue = resolvedPre;
|
targetValue = resolvedPre;
|
||||||
} else if (m_operation == setToOne) {
|
} else if (m_operation == setToOneOperation) {
|
||||||
targetValue = std::string("1");
|
targetValue = std::string("1");
|
||||||
|
} else if (m_operation == unsetOperation) {
|
||||||
|
transm_parser_payload->m_collections.del(m_collectionName + ":" +
|
||||||
|
m_variableNameExpanded);
|
||||||
|
goto end;
|
||||||
} else {
|
} else {
|
||||||
int pre = 0;
|
int pre = 0;
|
||||||
int value = 0;
|
int value = 0;
|
||||||
@@ -151,6 +155,7 @@ bool SetVar::evaluate(Rule *rule, Transaction *transm_parser_payload) {
|
|||||||
transm_parser_payload->m_collections.storeOrUpdateFirst(m_collectionName,
|
transm_parser_payload->m_collections.storeOrUpdateFirst(m_collectionName,
|
||||||
m_variableNameExpanded, targetValue);
|
m_variableNameExpanded, targetValue);
|
||||||
|
|
||||||
|
end:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,9 @@ enum SetVarOperation {
|
|||||||
/* read variable, substract predicate and set */
|
/* read variable, substract predicate and set */
|
||||||
substractAndSetOperation,
|
substractAndSetOperation,
|
||||||
/* set variable to 1 */
|
/* set variable to 1 */
|
||||||
setToOne
|
setToOneOperation,
|
||||||
|
/* unset operation */
|
||||||
|
unsetOperation,
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetVar : public Action {
|
class SetVar : public Action {
|
||||||
|
@@ -374,6 +374,7 @@ using modsecurity::operators::Operator;
|
|||||||
SETVAR_OPERATION_EQUALS
|
SETVAR_OPERATION_EQUALS
|
||||||
SETVAR_OPERATION_EQUALS_PLUS
|
SETVAR_OPERATION_EQUALS_PLUS
|
||||||
SETVAR_OPERATION_EQUALS_MINUS
|
SETVAR_OPERATION_EQUALS_MINUS
|
||||||
|
NOT "NOT"
|
||||||
;
|
;
|
||||||
|
|
||||||
%token <std::string>
|
%token <std::string>
|
||||||
@@ -515,7 +516,6 @@ using modsecurity::operators::Operator;
|
|||||||
DIRECTIVE "DIRECTIVE"
|
DIRECTIVE "DIRECTIVE"
|
||||||
DIRECTIVE_SECRULESCRIPT "DIRECTIVE_SECRULESCRIPT"
|
DIRECTIVE_SECRULESCRIPT "DIRECTIVE_SECRULESCRIPT"
|
||||||
FREE_TEXT "FREE_TEXT"
|
FREE_TEXT "FREE_TEXT"
|
||||||
NOT "NOT"
|
|
||||||
OPERATOR "OPERATOR"
|
OPERATOR "OPERATOR"
|
||||||
OPERATOR_BEGINS_WITH "OPERATOR_BEGINS_WITH"
|
OPERATOR_BEGINS_WITH "OPERATOR_BEGINS_WITH"
|
||||||
OPERATOR_CONTAINS "OPERATOR_CONTAINS"
|
OPERATOR_CONTAINS "OPERATOR_CONTAINS"
|
||||||
@@ -2063,9 +2063,13 @@ act:
|
|||||||
{
|
{
|
||||||
ACTION_CONTAINER($$, new actions::SetUID($1));
|
ACTION_CONTAINER($$, new actions::SetUID($1));
|
||||||
}
|
}
|
||||||
|
| ACTION_SETVAR NOT VARIABLE
|
||||||
|
{
|
||||||
|
ACTION_CONTAINER($$, new actions::SetVar(actions::SetVarOperation::unsetOperation, $3));
|
||||||
|
}
|
||||||
| ACTION_SETVAR VARIABLE
|
| ACTION_SETVAR VARIABLE
|
||||||
{
|
{
|
||||||
ACTION_CONTAINER($$, new actions::SetVar(actions::SetVarOperation::setToOne, $2));
|
ACTION_CONTAINER($$, new actions::SetVar(actions::SetVarOperation::setToOneOperation, $2));
|
||||||
}
|
}
|
||||||
| ACTION_SETVAR VARIABLE SETVAR_OPERATION_EQUALS FREE_TEXT
|
| ACTION_SETVAR VARIABLE SETVAR_OPERATION_EQUALS FREE_TEXT
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user