Closed sksaju closed 4 years ago
@aaemnnosttv @adamsilverstein Any idea what's happening here? The only issue like this I was aware of was fixed in #339 - maybe we missed something there?
@felixarntz this looks similar to a problem we've seen in #243 which may be related to web server configuration.
One possibility is that some [WAF, security plugin, etc] may be interfering with the value of the request
parameter value in a way which breaks the URL-encoded JSON. This would cause the decoding to fail on the API side, resulting in a null
value which may trigger the same error as if the parameter wasn't passed at all since it is technically "not set".
That's the best theory I have at the moment but it's difficult to troubleshoot without a more definitive way to reproduce the problem.
After doing some digging on https://github.com/google/site-kit-wp/issues/767
I noticed if you do the following steps you can reproduce this issue on the following host: https://interserv.cmsdevrel.com/wp-admin
Steps
Notice Dashboard looks like this:
400 error:
After investigating in the environment where this is happening I found that query parameters (in this environment) have a maximum value length of 512 characters. Any parameter with a value longer than that becomes undefined in the eyes of the REST request and not present in $request->get_params()
. I haven't found what conditions are responsible for this but it doesn't appear to be a limit at the server level, at least in the environment we have.
This is solvable by changing the way batch requests are made; the easiest solution is to simply change these to be made with a POST request instead of GET. This moves the request data into the body of the request which is then submitted as a regular JSON body rather than putting everything into a single parameter in the query string. This is actually how the Google API client performs batch requests as well. The request method of the batch request itself does not need to be GET
because all of the individual requests contain their own method. The REST API also abstracts the source of request parameters so it is a very small change to make.
IB ✅
Tested
Installed the following zip as a pre-test google-site-kit.zip
Notice:
Deactivated and deleted.
Installed the following zip with this fix. google-site-kit.zip
Notice:
Passed QA ✅
Bug Description
After successfully setup the plugin i got this error [400 (Bad Request)].
Screenshots
Additional Context
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
Changelog entry
POST
instead, as the query length was problematic on certain environments.