Grammarly is the unicorn company that announced its open bug bounty program last September. Since that time, many security researchers posted their submissions and got paid well. Some of Grammarly’s issues are also useful for others. Like the recent XSS, that also bypasses an AWS WAF.
The recent XSS report is a bit different among others. First of all, it was submitted by Frans Rosen, one of the top HackerOne hackers. He is the 6th for the all-time rank.
Secondly, the report was paid for $3000 unlike tons of $50-100 XSSes on a platform.
The report title is: “Config override using non-validated query parameter allows at least reflected XSS by injecting configuration into state” https://hackerone.com/reports/1082847
Moreover, for some reason, an XSS payload that Frans used to validate this Grammarly vulnerability bypasses AWS WAF.
Let’s understand why.
The payload look like a very usual XSS for the first glance:
It consists of a JSON-encoded config parameter that vulnerable application parse. JSON attributes
redirect contains an ordinary XSS sample of alert() function call. And if we will send this request to check how does the mod_security WAF detects it, we will get the following:
At the same time, AWS WAF will pass this payload with no blocking:
But, if we will remove the JSON object and use the same payload in a plain text way, AWS WAF will block it:
An attentive reader may notice that we modified the payload by adding
onerror attribute to make this payload work in HTML attribute injection way. That’s true, but now we can add the JSON prefix back and see what happens:
It passed! We basically found that adding JSON prefixes before payloads makes them invisible for AWS WAF. Let’s understand what happened and why.
We initially decided that the reason for this bypass is behind the JSON parser. As we already discussed recently in a post WAF JSON decoding capability required to protect against API threats like CVE-2020-13942 Apache Unomi RCE
But it was not even close since AWS WAF has no JSON parsing capabilities at all.
After minifying Grammarly payload, we will get that the following request will be blocked by AWS WAF:
But adding just one additional double quote into there bypass the WAF:
The reason is not in JSON-like prefix, but the double-quote itself. We can easily remove the bracer charter and get the same bypass result with the payload
It seems irrational but adding any numbers of double quotes before an XSS payloads bypass AWS WAF. We tested on 1500 rules enabled
Please leave a comment if you have an idea why. Thanks for reading!