Turning on Application Gateway WAF causes API Management Developer Portal to no longer load

As a follow up to my previous post:

Publishing an API Management’s Developer Portal through an App Gateway only displays the side navigation bar

I wanted to demonstrate the full end-to-end deployment of an API Management deployed into an internal virtual network that is published by an Application Gateway. Microsoft actually provides a series of PowerShell cmdlets for the deployment as described here:

Integrate API Management in an internal virtual network with Application Gateway
https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-integrate-internal-vnet-appgateway
The intent was to then convert the deployment to Terraform code and add it to my repo.
What I noticed was the after successfully deploying the resources, my developer portal exhibited a similar behavior as my previous post where the page would not load:
The only difference is that the error message was more generic with:
Oops, something went wrong.
We are unable to complete your operation this time.
Please try again later.
Given the deployment was straight from the Microsoft documentation, I was confused as to why the developer portal wasn’t working even though the API gateway did. As a quick test, I had a look at the WAF settings and decided to change it from Prevention to Detection:
Surprisingly, the developer portal started to work:
Knowing this is likely a WAF issue, I went ahead and configured Diagnostic Settings for the Application Gateway to review the logs and immediately saw the following entries:
Rule ID: 942100
RequestUri: /subscriptions/000/resourceGroups/000/providers/Microsoft.ApiManagement/service/apim-contoso-dev/contentTypes/page/contentItems
Message: SQL Injection Attack Detected via libinjection
Rule ID: 942110
RequestUri: /subscriptions/000/resourceGroups/000/providers/Microsoft.ApiManagement/service/apim-contoso-dev/contentTypes/page/contentItems
Message: SQL Injection Attack: Common Injection Testing Detected
Rule ID: 042200
RequestUri: /signin-sso
Message: Detects MySQL comment-/space-obfuscated injections and backtick termination
I’ve worked with WAF issues in the past and understood that the traffic between the Application Gateway and the APIM was triggering rules such as SQL Injections and eventually scoring an Anomaly score past 5, which results in the traffic being blocked. More detail on how scoring works can be found in the following documentation:
Attempting to perform a trace from within the a browser will also show that the management endpoint is blocked:
After going through documentation again, I realized that it was mentioned that the Application Gateway WAF can break down APIM’s portal functionality:
To my surprise, there are a total of 16 rules that can cause access issues to the developer portal. Taking the instructions in the warning literally, it sounds like Microsoft recommends to disable all of these rules.
  1. 942200
  2. 920300
  3. 920330
  4. 931130
  5. 942100
  6. 942110
  7. 942180
  8. 942200
  9. 942260
  10. 942340
  11. 942370
  12. 942200
  13. 942260
  14. 942370
  15. 942430
  16. 942440
Once I’ve gone ahead and disabled all of the 16 rules, the page began to load:
I gave the alternatives a lot of thought before proceeding to disable the rules and could not think of a better way workaround so I’m open to suggestions in the comments section if there is a better way.

Leave a Reply

Your email address will not be published. Required fields are marked *