You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The yaml schema has a mechanism to handle global and local constants.
459
+
460
+
~~~yaml
461
+
global:
462
+
default_constants:
463
+
one: 1
464
+
TWO: 2
465
+
two_in_list:
466
+
- 2
467
+
FOO_IN_DICT:
468
+
foo: attack
469
+
...
470
+
471
+
constants:
472
+
HEADERS_IN_DICTIONARY:
473
+
headers:
474
+
- name: test
475
+
value: test
476
+
- name: one
477
+
value: ~{one}~
478
+
- name: 2
479
+
value: ~{TWO}~
480
+
template_in_list:
481
+
- SecRule for TARGETS
482
+
- Template with constants
483
+
one: one
484
+
~~~
485
+
486
+
Global constants are defined under the `global.default_constants` field. They are accessible across files and are reset whenever a new `global` field is defined.
487
+
488
+
Local constants are defined under a `constants` field at the root of a file. They are only accessible in the file they are defined in.
489
+
490
+
#### Syntax
491
+
Constants are defined as key-value pairs where:
492
+
493
+
~~~yaml
494
+
NAME: VALUE
495
+
~~~
496
+
497
+
The name is used for referencing the constant and the value is used for the substitution. Referencing a constant can be done inside the value of any other key in the API. References use the `~{...}~` separators like so:
498
+
499
+
~~~yaml
500
+
~{NAME}~
501
+
~~~
502
+
503
+
Variable names can be lower or upper case and are case sensitive.
504
+
505
+
#### Properties
506
+
507
+
Constants can be yaml scalars, lists, or dictionaries:
508
+
509
+
~~~yaml
510
+
scalar: 1
511
+
list:
512
+
- 1
513
+
dictionary:
514
+
1: 1
515
+
~~~
516
+
517
+
Constants can reference other constants in their values:
518
+
519
+
~~~yaml
520
+
headers:
521
+
- name: one
522
+
value: ~{one}~
523
+
- name: two
524
+
value: ~{TWO}~
525
+
~~~
526
+
527
+
Local constants with the same name as global constants have precedence in their local scope:
528
+
~~~yaml
529
+
global:
530
+
default_constants:
531
+
ONE: 1
532
+
...
533
+
constants:
534
+
ONE: one
535
+
...
536
+
key: ~{ONE}~ # substituted by 'one'
537
+
~~~
538
+
Values can contain multiple references, such as in templates:
539
+
540
+
~~~yaml
541
+
- name: "Template with constants"
542
+
template: |
543
+
SecRule ~{target}~ "${OPERATOR}$ ${OPARG}$" \
544
+
"id:${CURRID}$,\
545
+
phase:${PHASE}$,\
546
+
deny,\
547
+
t:~{None}~,\
548
+
log,\
549
+
msg:'%{MATCHED_VAR_NAME} was caught in phase:${PHASE}$',\
550
+
ver:'~{VERSION}~'"
551
+
~~~
552
+
553
+
### Output / additional checks
458
554
459
555
By default, the generator will produce checks for tests with `go-ftw`'s `expect_ids` field using the current rule id as parameter. If the associated rule matches and it's id put in the log, the test will pass.
0 commit comments