Skip to content

Commit 8455a5b

Browse files
author
zac
committed
Make 'Data' parameter optional in WAF regex.
Only a few Data types allow it.
1 parent e4fae9b commit 8455a5b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

waf_regex/logic.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class WafRegexLogic:
1414
def __init__(self, resource_properties):
1515
self.regex_patterns = resource_properties['RegexPatterns']
1616
self.match_type = resource_properties['Type']
17-
self.match_data = resource_properties['Data']
17+
self.match_data = resource_properties.get('Data', '')
1818
self.transform = resource_properties['Transform']
1919
self.match_name = resource_properties['Name']
2020
self.pattern_name = f"{resource_properties['Name']}-pattern"
@@ -99,22 +99,26 @@ def new_match_set(self):
9999
return response_create_match_set['RegexMatchSet']['RegexMatchSetId']
100100

101101
def insert_match_set(self, match_set_id, pattern_set_id):
102+
update = {
103+
'Action': 'INSERT',
104+
'RegexMatchTuple': {
105+
'FieldToMatch': {
106+
'Type': self.match_type
107+
},
108+
'TextTransformation': self.transform,
109+
'RegexPatternSetId': pattern_set_id
110+
}
111+
}
112+
113+
# This applies when `match_type` is 'HEADER' or 'SINGLE_QUERY_ARG'
114+
if (self.match_data != '') {
115+
update['RegexMatchTuple']['FieldToMatch']['Data'] = self.match_data
116+
}
117+
102118
changeToken = self.client.get_change_token()
103119
update_regex_matchset = self.client.update_regex_match_set(
104120
RegexMatchSetId=match_set_id,
105-
Updates=[
106-
{
107-
'Action': 'INSERT',
108-
'RegexMatchTuple': {
109-
'FieldToMatch': {
110-
'Type': self.match_type,
111-
'Data': self.match_data
112-
},
113-
'TextTransformation': self.transform,
114-
'RegexPatternSetId': pattern_set_id
115-
}
116-
},
117-
],
121+
Updates=[update],
118122
ChangeToken=changeToken['ChangeToken']
119123
)
120124

0 commit comments

Comments
 (0)