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