[8.x] Improve signed url signature verification #37432
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was done in collaboration with @Krisell
This fixes an issue where a signed url that contains a querystring parameter with no value or empty string value will always be invalid. Additionally, a valid signed url will continue to be valid even after tampering with the url by appending empty querystring values.
This is because the validation code attempts to rebuild the original url for comparison using a combination of the normalized
$request->query()
array andArr::query()
.$request-query()
is not able to differentiate between parameters with no value or empty string values. They all return as null. Furthermore,Arr::query()
will strip away any nulls. The rebuilt url will not be the same as the original url and therefore fails validation.Since the signature was created with the original url, we can simply get the original url by stripping the signature parameter (using regex) from the raw querystring.
The following were some of our considerations on the fix:
signature
will not break our regex$request->server->get('QUERY_STRING')
. According to http://www.faqs.org/rfcs/rfc3875.html (Section 4.1.7), QUERY_STRING variable must always be provided by the server and we can expect it will always exist.The signing code was unaffected and therefore this fix is backwards compatible with any already generated signed urls. We also added tests to: