-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Objective
Add a feature to define constant variables to be replaced in values of parameters when parsing MRTS yaml files. Two types of constants could be defined, global constants and per-file constants. They could then be replaced when parsing.
Proposition
For global constants, a default_constants section would be added as a subsection of global sections:
global:
version: MRTS/0.1
baseid: 100000
default_operator: "@rx"
default_constants:
- constant:
name: ONE
value: 1
- constant:
name: TWO
value: "two"
- constant:
name: THREE
value: 'three'
templates:
- name: "SecRule for TARGETS"
template: |
SecRule $TARGET "$OPERATOR $OPARG" \
"id:$CURRID,\
phase:$PHASE,\
deny,\
t:none,\
log,\
msg:'%{MATCHED_VAR_NAME} was caught in phase:$PHASE',\
ver:'$VERSION'"
default_tests_phase_methods:
- 1: get
- 2: post
- 3: post
- 4: post
- 5: post
For per-file constants, a constants section would be located as a root section:
target: null
rulefile: MRTS_001_INIT.conf
testfile: null
constants:
- constant:
- name: ONE
- value: 1
objects:
- object: ...
The constants would then be accessible inside other sections, using @{ as prefix and }@ as suffix around it's name, to instruct the parser that it is a constant to be substituted. In case @{ }@ symbols are parsed but no corresponding constant is found, no substition takes place to avoid modifying possibly legitimate rule configurations.
testdata:
phase_methods:
2: post
3: post
4: post
targets:
- target: '/*'
test:
input:
headers:
- name: Content-Type
value: @{XML}@
- name: Content-Length
value: @{ONE}@As specified in the MRTS documentation, any global section parsed later than an other global section is overwritten, including for default_constants. If constant names are used multiple times, the latest occurence defines the value. Implementation would be based on a constant dictionnary, like the variables of templates.