-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Generate url-safe hashes for signed urls #59022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ec97e3a
to
93eb218
Compare
|
There is 2 errors in fabbot, which need to be treated differently:
|
Fixing the deps=low tests is probably a matter of bumping the min requirement |
@@ -17,6 +17,7 @@ | |||
], | |||
"require": { | |||
"php": ">=8.2", | |||
"ext-sodium": "*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making HttpFoundation require ext-sodium is a no-go (especially if only the UriSigner needs it as it is not the main feature of the component)
@@ -124,7 +125,7 @@ public function checkRequest(Request $request): bool | |||
|
|||
private function computeHash(string $uri): string | |||
{ | |||
return base64_encode(hash_hmac('sha256', $uri, $this->secret, true)); | |||
return sodium_bin2base64(hash_hmac('sha256', $uri, $this->secret, true), SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing a dependency on ext-sodium just to provide URL-safe base64 encoding is clearly not necessary. It is very easy to do it in userland (using the same strtr
you use for the comparison)
5782c78
to
4b6515e
Compare
4b6515e
to
8258bc4
Compare
8258bc4
to
a533750
Compare
Thank you @valtzu. |
This PR was merged into the 6.4 branch. Discussion ---------- [HttpKernel] relax assertions on generated hashes | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT fixes the high deps tests after #59022 Commits ------- 85a5d13 relax assertions on generated hashes
Generate url-safe signed urls since some clients can't handle parameter encoding correctly and are sending
(space), making the signature invalid.
%2B
as+
which PHP reads asBackwards-compatibility is included, and planned to be removed in 8.0 – which will mean all signed urls generated with <7.3 are rendered invalid.