mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-29 19:24:29 +03:00
Testing new approach to tag macro expansion
This commit is contained in:
28
apache2/re.c
28
apache2/re.c
@@ -597,6 +597,7 @@ msre_actionset *msre_actionset_create(msre_engine *engine, const char *text,
|
||||
actionset->id = NOT_SET_P;
|
||||
actionset->rev = NOT_SET_P;
|
||||
actionset->msg = NOT_SET_P;
|
||||
actionset->tag = NOT_SET_P;
|
||||
actionset->logdata = NOT_SET_P;
|
||||
actionset->phase = NOT_SET;
|
||||
actionset->severity = -1;
|
||||
@@ -679,6 +680,7 @@ msre_actionset *msre_actionset_merge(msre_engine *engine, msre_actionset *parent
|
||||
if (child->id != NOT_SET_P) merged->id = child->id;
|
||||
if (child->rev != NOT_SET_P) merged->rev = child->rev;
|
||||
if (child->msg != NOT_SET_P) merged->msg = child->msg;
|
||||
if (child->tag != NOT_SET_P) merged->tag = child->tag;
|
||||
if (child->logdata != NOT_SET_P) merged->logdata = child->logdata;
|
||||
if (child->severity != NOT_SET) merged->severity = child->severity;
|
||||
if (child->phase != NOT_SET) merged->phase = child->phase;
|
||||
@@ -735,6 +737,7 @@ void msre_actionset_set_defaults(msre_actionset *actionset) {
|
||||
if (actionset->id == NOT_SET_P) actionset->id = NULL;
|
||||
if (actionset->rev == NOT_SET_P) actionset->rev = NULL;
|
||||
if (actionset->msg == NOT_SET_P) actionset->msg = NULL;
|
||||
if (actionset->tag == NOT_SET_P) actionset->tag = NULL;
|
||||
if (actionset->logdata == NOT_SET_P) actionset->logdata = NULL;
|
||||
if (actionset->phase == NOT_SET) actionset->phase = 2;
|
||||
if (actionset->severity == -1) {} /* leave at -1 */
|
||||
@@ -1436,28 +1439,16 @@ static int msre_ruleset_phase_rule_remove_with_exception(msre_ruleset *ruleset,
|
||||
|
||||
break;
|
||||
case RULE_EXCEPTION_REMOVE_TAG :
|
||||
if ((rule->actionset != NULL)&&(apr_is_empty_table(rule->actionset->actions) == 0)) {
|
||||
if ((rule->actionset != NULL)&&(rule->actionset->tag != NULL)) {
|
||||
char *my_error_msg = NULL;
|
||||
const apr_array_header_t *tarr = NULL;
|
||||
const apr_table_entry_t *telts = NULL;
|
||||
int act;
|
||||
|
||||
tarr = apr_table_elts(rule->actionset->actions);
|
||||
telts = (const apr_table_entry_t*)tarr->elts;
|
||||
|
||||
for (act = 0; act < tarr->nelts; act++) {
|
||||
msre_action *action = (msre_action *)telts[act].val;
|
||||
if((action != NULL) && (action->metadata != NULL) && (strcmp("tag", action->metadata->name) == 0)) {
|
||||
|
||||
int rc = msc_regexec(re->param_data,
|
||||
action->param, strlen(action->param),
|
||||
rule->actionset->tag, strlen(rule->actionset->tag),
|
||||
&my_error_msg);
|
||||
if (rc >= 0) {
|
||||
remove_rule = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1594,8 +1585,15 @@ char *msre_format_metadata(modsec_rec *msr, msre_actionset *actionset) {
|
||||
for (k = 0; k < tarr->nelts; k++) {
|
||||
msre_action *action = (msre_action *)telts[k].val;
|
||||
if (strcmp(telts[k].key, "tag") == 0) {
|
||||
/* Expand variables in the tag argument. */
|
||||
msc_string *var = (msc_string *)apr_pcalloc(msr->mp, sizeof(msc_string));
|
||||
|
||||
var->value = (char *)action->param;
|
||||
var->value_len = strlen(action->param);
|
||||
expand_macros(msr, var, NULL, msr->mp);
|
||||
|
||||
tags = apr_psprintf(msr->mp, "%s [tag \"%s\"]", tags,
|
||||
log_escape(msr->mp, action->param));
|
||||
log_escape(msr->mp, var->value));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -297,6 +297,7 @@ struct msre_actionset {
|
||||
const char *rev;
|
||||
const char *msg;
|
||||
const char *logdata;
|
||||
const char *tag;
|
||||
int severity;
|
||||
int phase;
|
||||
msre_rule *rule;
|
||||
|
@@ -584,32 +584,15 @@ static apr_status_t msre_action_tag_execute(modsec_rec *msr, apr_pool_t *mptmp,
|
||||
msre_rule *rule, msre_action *action)
|
||||
{
|
||||
msc_string *var = NULL;
|
||||
/*
|
||||
msre_action *action_tag = NULL;
|
||||
const apr_array_header_t *tarr = NULL;
|
||||
const apr_table_entry_t *telts = NULL;
|
||||
int act;
|
||||
*/
|
||||
|
||||
var = apr_pcalloc(mptmp, sizeof(msc_string));
|
||||
if (var == NULL) return -1;
|
||||
var->value = (char *)action->param;
|
||||
var->value_len = strlen(var->value);
|
||||
expand_macros(msr, var, rule, mptmp);
|
||||
/*
|
||||
tarr = apr_table_elts(rule->actionset->actions);
|
||||
telts = (const apr_table_entry_t*)tarr->elts;
|
||||
|
||||
for (act = 0; act < tarr->nelts; act++) {
|
||||
action_tag = (msre_action *)telts[act].val;
|
||||
if((action_tag != NULL) && (action_tag->metadata != NULL) && (strcmp("tag", action_tag->metadata->name) == 0)) {
|
||||
action_tag->param = apr_pstrmemdup(rule->ruleset->engine->mp, var->value, var->value_len);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
action->param = apr_pstrmemdup(rule->ruleset->engine->mp, var->value, var->value_len);
|
||||
if(rule->actionset != NULL)
|
||||
rule->actionset->tag = var->value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user