Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] Fix UriSigner::check when _hash is not at the end of the uri #12574

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

Closed
wants to merge 10 commits into from

Conversation

nyroDev
Copy link
Contributor

@nyroDev nyroDev commented Nov 25, 2014

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

I have a weird server installation behind Varnish that rewrite the signed URL to add the _hash at the end of the url queries.
Exemple :
URL called: http://exemple.com/page?foo=bar&_hash=123
URL received by PHP: http://exemple.com/page?_hash=123&foo=bar

When the _hash is not at the end of the URL, the UriSigner fail to verify it even if the _hash is correct.

The fix rewrites the check function to use parse_url and parse_str to analyse the URI and check the signature.

$params = array();
}

if (!isset($params['_hash']) || !$params['_hash']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (empty($params['_hash'])) { will do the same in a more readable way

$path = isset($url['path']) ? $url['path'] : '';
$query = isset($url['query']) && $url['query'] ? '?' . $url['query'] : '';
$fragment = isset($url['fragment']) ? '#' . $url['fragment'] : '';
$testUrl = $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use http_build_url to generate the URL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its only available as an extension

@nyroDev
Copy link
Contributor Author

nyroDev commented Nov 25, 2014

@GromNaN I'm running PHP 5.3.3 on the server I'm testing it and the function http_build_url is not defined for this version.
That's why I used the code from a comment on this function on PHP documentation to recreate it.

@Tobion
Copy link
Contributor

Tobion commented Nov 26, 2014

@nyroDev This change will not help when varnish rewrites the query params. The hash is currently also done over the query string (without the hash param). So the order is important and if the order changes, the hash is not valid anymore. So this would also require to change the hashing logic to be independent of the query param order.

@timglabisch
Copy link

i looked at the rfc and didn't found any information about how to normalize the param order. amazon aws for example use this strategy for url signing:

Sort the encoded parameter names by character code (that is, in strict ASCII order). For example, a parameter name that begins with the uppercase letter F (ASCII code 70) precedes a parameter name that begins with a lowercase letter b (ASCII code 98).

@fabpot
Copy link
Member

fabpot commented Jan 3, 2015

Thank you @nyroDev.

fabpot added a commit that referenced this pull request Jan 3, 2015
… end of the uri (nyroDev)

This PR was submitted for the 2.5 branch but it was merged into the 2.3 branch instead (closes #12574).

Discussion
----------

[HttpKernel] Fix UriSigner::check when _hash is not at the end of the uri

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

I have a weird server installation behind Varnish that rewrite the signed URL to add the _hash at the end of the url queries.
Exemple :
URL called: http://exemple.com/page?foo=bar&_hash=123
URL received by PHP: http://exemple.com/page?_hash=123&foo=bar

When the _hash is not at the end of the URL, the UriSigner fail to verify it even if the _hash is correct.

The fix rewrites the check function to use parse_url and parse_str to analyse the URI and check the signature.

Commits
-------

29b217c [HttpKernel] Fix UriSigner::check when _hash is not at the end of the uri
@fabpot fabpot closed this Jan 3, 2015
@@ -33,5 +33,7 @@ public function testCheck()

$this->assertTrue($signer->check($signer->sign('http://example.com/foo')));
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar')));

$this->assertTrue($signer->sign('http://example.com/foo?foo=bar&bar=foo') === $signer->sign('http://example.com/foo?bar=foo&foo=bar'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using assertSame would be better

fabpot added a commit that referenced this pull request Mar 17, 2015
…_build_query (Jakub Simon)

This PR was squashed before being merged into the 2.6 branch (closes #13944).

Discussion
----------

[HttpKernel] UriSigner::buildUrl - default params for http_build_query

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

UriSigner fail to verify hash when custom ini setting arg_separator.output is used.
It was introduced in #12574

Commits
-------

3d6933f [HttpKernel] UriSigner::buildUrl - default params for http_build_query
stof added a commit that referenced this pull request Oct 17, 2017
…ric)

This PR was merged into the 2.7 branch.

Discussion
----------

[HttpKernel] Remove obsolete PHPDoc from UriSigner

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

`_hash` query param does not have to be at the end of the URL ever since #12574 so this PHPDoc is confusing. I've actually lost couple of hours of work rewriting my URLs to place it at the end before I realized that `UriSigner` doesn't really care.

Commits
-------

45ac192 Remove obsolete PHPDoc from UriSigner
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.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.