Skip to content

[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

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

valtzu
Copy link
Contributor

@valtzu valtzu commented Nov 27, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #52822
License MIT

Generate url-safe signed urls since some clients can't handle parameter encoding correctly and are sending %2B as + which PHP reads as (space), making the signature invalid.

Backwards-compatibility is included, and planned to be removed in 8.0 – which will mean all signed urls generated with <7.3 are rendered invalid.

@carsonbot carsonbot added this to the 7.3 milestone Nov 27, 2024
@valtzu valtzu force-pushed the generate-url-safe-signatures branch 2 times, most recently from ec97e3a to 93eb218 Compare November 27, 2024 20:55
@valtzu
Copy link
Contributor Author

valtzu commented Nov 27, 2024

  1. fabbot failures are not a result of these changes – I can of course fix them here but not sure if I should
  2. Not sure how to fix those tests in other packages as it's only tests that depend on UriSigner from 7.3 🤔

@stof
Copy link
Member

stof commented Nov 28, 2024

There is 2 errors in fabbot, which need to be treated differently:

  • the coding standard failure is related to your change and must be fixed
  • the exception message formatting should be ignored (this check has some false positives as we have special cases)

@stof
Copy link
Member

stof commented Nov 28, 2024

Fixing the deps=low tests is probably a matter of bumping the min requirement

@@ -17,6 +17,7 @@
],
"require": {
"php": ">=8.2",
"ext-sodium": "*",
Copy link
Member

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);
Copy link
Member

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)

@valtzu valtzu force-pushed the generate-url-safe-signatures branch 3 times, most recently from 5782c78 to 4b6515e Compare December 1, 2024 16:38
@valtzu valtzu force-pushed the generate-url-safe-signatures branch from 4b6515e to 8258bc4 Compare December 14, 2024 10:35
@valtzu valtzu force-pushed the generate-url-safe-signatures branch from 8258bc4 to a533750 Compare December 14, 2024 10:46
@fabpot
Copy link
Member

fabpot commented Dec 18, 2024

Thank you @valtzu.

@fabpot fabpot merged commit dd061aa into symfony:7.3 Dec 18, 2024
10 of 11 checks passed
xabbuh added a commit that referenced this pull request Dec 19, 2024
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
@fabpot fabpot mentioned this pull request May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HttpFoundation] Use base64url in the UriSigner service
4 participants