-
Notifications
You must be signed in to change notification settings - Fork 0
/
waf-rule-owasp-ssi.tf
68 lines (65 loc) · 1.91 KB
/
waf-rule-owasp-ssi.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# OWASP SSI
# Server Side Includes
variable "rule_owasp_ssi_action" {
type = string
description = "COUNT or BLOCK, any other value will disable this rule entirely."
default = "DISABLED"
}
variable "rule_owasp_ssi_priority" {
type = number
description = "The priority in which to execute this rule."
default = 90
}
variable "rule_ssi_file_extensions" {
type = list(string)
description = "A blacklist of file extensions within the URI of a request."
default = [".bak", ".backup", ".cfg", ".conf", ".config", ".ini", ".log"]
}
variable "rule_ssi_paths" {
type = list(string)
description = "A blacklist of relative paths within the URI of a request."
default = ["/includes"]
}
locals {
# Determine if the SSI rule is enabled
is_owasp_ssi_enabled = var.enabled && contains(var.enable_actions, var.rule_owasp_ssi_action) ? 1 : 0
}
resource "aws_waf_rule" "owasp_ssi" {
count = local.is_owasp_ssi_enabled
name = "${var.waf_prefix}-detect-ssi"
metric_name = replace("${var.waf_prefix}detectssi", "/[^0-9A-Za-z]/", "")
predicates {
data_id = aws_waf_byte_match_set.match_ssi[0].id
negated = false
type = "ByteMatch"
}
tags = local.tags
}
resource "aws_waf_byte_match_set" "match_ssi" {
count = local.is_owasp_ssi_enabled
name = "${var.waf_prefix}-match-ssi"
dynamic "byte_match_tuples" {
iterator = x
for_each = var.rule_ssi_file_extensions
content {
text_transformation = "LOWERCASE"
target_string = lower(x.value)
positional_constraint = "ENDS_WITH"
field_to_match {
type = "URI"
}
}
}
dynamic "byte_match_tuples" {
iterator = x
for_each = var.rule_ssi_paths
content {
text_transformation = "URL_DECODE"
target_string = x.value
positional_constraint = "STARTS_WITH"
field_to_match {
type = "URI"
}
}
}
}