We have a Web API which uses the REST semantics and is protected using the Azure's Application Gateway using a Web Application Firewall. The Web App consuming this API can send in any type of data in a JSON format but what is happening is that some strings are triggering the Web Application Firewall's rules for SQL Injection. Here is the error log I am seeing -
Message - Detects MySQL comment-/space-obfuscated injections and backtick termination
instanceId_s - appgw_3
SourceSystem - Azure
clientIp_s - 103.149.149.193
ruleSetType_s - OWASP
ruleSetVersion_s - CRS 3.1
ruleId_s - 942200
ruleGroup_s - REQUEST-942-APPLICATION-ATTACK-SQLI
action_s - Matched
details_message_s -
Pattern match (?i:(?:(?:(?:(?:trunc|cre|upd)at|renam)e|(?:inser|selec)t|de(?:lete|sc)|alter|load)\\s*?\\(\\s*?space\\s*?\\(|,.*?[)\\da-f\"'`][\"'`](?:[\"'`].*?[\"'`]|(?:\\r?\\n)?\\z|[^\"'`]+)|\\Wselect.+\\W*?from)) at ARGS.
details_data_s - Matched Data: , THE\" found within ARGS:filters.value: \"COMPANY, THE\"
details_file_s - REQUEST-942-APPLICATION-ATTACK-SQLI.conf
details_line_s - 683
policyId_s - 54#default
policyScope_s - Global
The POST JSON body looks something like the following -
{
"clientSide": false,
"first": 0,
"rows": 20,
"sorting": [
{
"field": "rank",
"order": 1
}
],
"filters": [
{
"field": "name",
"value": [
"\"COMPANY, THE\""
],
"matchMode": "in"
},
{
"field": "global",
"value": [],
"matchMode": "contains"
},
{
"field": "globalFilterFields",
"value": [
"distName"
]
}
]
}
My question is how can we fix this issue and what is the generally recommended approach?
- I can Base64 encode the entire payload every time before sending it to the API and have it decode it but then I wonder if that kind of defeats the purpose of having a WAF in front of the API since it will not be able to detect even malicious attempts because they will be base64 encoded.
- I can try adding an exclusion to the Application Gateway's Firewall but I have not been able to find out a way to add an exclusion for the POST body. Also, since the Web App allows users to enter arbitrary data in the sense that things like double quotes etc, are allowed, I don't want to add hundreds of rules (App Gateway WAF allows 100 custom rules I believe) like this.
Are there any other ways to solve this issue?