Skip to content

Commit ef6c2b6

Browse files
authored
DS-2844 Missing rule config for WAF SQLi rule (#1041)
# Task Branch Pull Request **<https://nhsd-jira.digital.nhs.uk/browse/DS-2844>** ## Description of Changes This PR creates a custom WAF rule to identify the SQL injection attacks in change event request. Please include a summary of the change ## Type of change - Security enhancements(Prevention of SQL injections) ## Development Checklist - [x] I have performed a self-review of my own code - [x] Tests have added that prove my fix is effective or that my feature works (Integration tests) - [x] I have updated Dependabot to include my changes (if applicable) ## Code Reviewer Checklist - [x] I can confirm the changes have been tested or approved by a tester
1 parent 7144815 commit ef6c2b6

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

build/automation/var/project.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ TF_VAR_waf_ip_allow_list_rule_name := $(PROJECT_ID)-$(SHARED_ENVIRONMENT)-waf-ip
141141
TF_VAR_waf_rate_based_rule_name := $(PROJECT_ID)-$(SHARED_ENVIRONMENT)-waf-rate-based-rule
142142
TF_VAR_waf_aws_known_bad_inputs_rule_name := $(PROJECT_ID)-$(SHARED_ENVIRONMENT)-waf-aws-known-bad-inputs-rule
143143
TF_VAR_waf_aws_sqli_rule_name := $(PROJECT_ID)-$(SHARED_ENVIRONMENT)-waf-aws-sqli-rule
144+
TF_VAR_waf_custom_sqli_rule_name := $(PROJECT_ID)-$(SHARED_ENVIRONMENT)-waf-custom-sqli-rule
144145

145146
# -------------------------------
146147
# BLUE/GREEN ENVIRONMENT VARIABLES

infrastructure/stacks/shared-resources/cloudwatch-waf-alarms.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ resource "aws_cloudwatch_metric_alarm" "waf_aws_managed_sql_injection_blocked_re
118118
threshold = "1"
119119
}
120120

121+
resource "aws_cloudwatch_metric_alarm" "waf_custom_sql_injection_count_requests" {
122+
count = var.waf_enabled ? 1 : 0
123+
alarm_actions = [aws_sns_topic.shared_resources_sns_topic_app_alerts_for_slack_default_region.arn]
124+
alarm_description = "WAF Custom SQL Injection Count Requests"
125+
alarm_name = "${var.project_id} | ${var.shared_environment} | WAF Custom SQL Injection Count Requests"
126+
comparison_operator = "GreaterThanThreshold"
127+
datapoints_to_alarm = "1"
128+
dimensions = {
129+
Rule = var.waf_custom_sqli_rule_name
130+
WebACL = var.waf_acl_name,
131+
Region = var.aws_region
132+
}
133+
evaluation_periods = "1"
134+
metric_name = "CountedRequests"
135+
namespace = "AWS/WAFV2"
136+
period = "60"
137+
statistic = "Sum"
138+
threshold = "1"
139+
}
140+
121141
resource "aws_cloudwatch_metric_alarm" "waf_aws_managed_ip_reputation_list_blocked_requests" {
122142
count = var.waf_enabled ? 1 : 0
123143
alarm_actions = [aws_sns_topic.shared_resources_sns_topic_app_alerts_for_slack_default_region.arn]

infrastructure/stacks/shared-resources/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,8 @@ variable "waf_aws_sqli_rule_name" {
216216
type = string
217217
description = "WAF AWS SQLi rule name"
218218
}
219+
220+
variable "waf_custom_sqli_rule_name" {
221+
type = string
222+
description = "WAF custom SQLi rule name"
223+
}

infrastructure/stacks/shared-resources/waf.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,33 @@ resource "aws_wafv2_web_acl" "di_endpoint_waf" {
164164
}
165165
}
166166

167+
rule {
168+
name = var.waf_custom_sqli_rule_name
169+
priority = 8
170+
171+
action {
172+
count {}
173+
}
174+
175+
statement {
176+
sqli_match_statement {
177+
field_to_match {
178+
body {}
179+
}
180+
sensitivity_level = "HIGH"
181+
text_transformation {
182+
priority = 0
183+
type = "NONE"
184+
}
185+
}
186+
}
187+
visibility_config {
188+
sampled_requests_enabled = true
189+
metric_name = var.waf_custom_sqli_rule_name
190+
cloudwatch_metrics_enabled = true
191+
}
192+
}
193+
167194
rule {
168195
name = var.waf_ip_reputation_list_rule_name
169196
priority = 7

0 commit comments

Comments
 (0)