Skip to content

[HttpCache] purge both http and https from http cache #21582

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 1 commit into from

Conversation

dbu
Copy link
Contributor

@dbu dbu commented Feb 10, 2017

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

The HTTP cache store of HttpCache respects the scheme for cache entries, which is the expected behaviour. however, Store::purge($url) also respects the scheme when invalidating the cache. This seems wrong to me.

This PR is rather rough for now, and i did not even look at the tests. Do the maintainers agree with my assumption? Should it be a bugfix against 2.8? Any input on the code?

}

return false;
if (isset($this->locks[$key2])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the actual deleting could be moved to a private function to avoid code repetition.

Copy link
Member

Choose a reason for hiding this comment

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

Having a private method makes sense I think.

$uri2 = 0 === strpos($uri, 'https://')
? preg_replace('https', 'http', $uri, 1)
: preg_replace('http', 'https', $uri, 1);
$key2 = $this->getCacheKey(Request::create($url2));
Copy link
Contributor

Choose a reason for hiding this comment

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

uri2

@@ -324,20 +324,37 @@ private function getMetadata($key)
public function purge($url)
{
$key = $this->getCacheKey(Request::create($url));
$uri2 = 0 === strpos($uri, 'https://')
Copy link
Contributor

Choose a reason for hiding this comment

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

url

@dbu
Copy link
Contributor Author

dbu commented Feb 12, 2017

ups, yep url not uri. but i wait for feedback on the general idea before fixing any details here

@fabpot
Copy link
Member

fabpot commented Feb 12, 2017

fabbot reports errors that should be fixed.

@dbu dbu force-pushed the patch-1 branch 2 times, most recently from e2cad29 to 00420e2 Compare February 13, 2017 08:47
*/
public function purge($url)
{
$key = $this->getCacheKey(Request::create($url));
$http = preg_replace('#^https#', 'http', $url);
Copy link
Contributor Author

@dbu dbu Feb 13, 2017

Choose a reason for hiding this comment

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

if $url is already http://, nothing changes.

this was previously

        $url2 = 0 === strpos($url, 'https://')
            ? preg_replace('#^https#', 'http', $url, 1)
            : preg_replace('#^http#', 'https', $url, 1);

        return $this->doPurge($url) || $this->doPurge($url2);

but i find the new code more readable. we add one preg_replace instead of a strpos. given that we do multiple filesystem operations, the speed difference should not matter.

@dbu
Copy link
Contributor Author

dbu commented Feb 13, 2017

updated. should this go into master or is it a bugfix?

@fabpot
Copy link
Member

fabpot commented Feb 16, 2017

I think this is a bug fix.

@@ -317,14 +317,30 @@ private function getMetadata($key)
/**
* Purges data for the given URL.
*
* This method purges both the http and the https version of the cache entry.
Copy link
Member

Choose a reason for hiding this comment

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

HTTP in caps?

* @param string $url A URL
*
* @return bool true if the URL exists and has been purged, false otherwise
* @return bool true if the URL exists with either http or https scheme and has been purged, false otherwise
Copy link
Member

Choose a reason for hiding this comment

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

Same here?

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Feb 18, 2017
@dbu
Copy link
Contributor Author

dbu commented Feb 18, 2017

fixed the spelling. should i close this and open a new pull request against the 2.7 branch? or can the mergers handle that?

@fabpot
Copy link
Member

fabpot commented Feb 18, 2017

Thank you @dbu.

fabpot added a commit that referenced this pull request Feb 18, 2017
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #21582).

Discussion
----------

[HttpCache] purge both http and https from http cache

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

The HTTP cache store of HttpCache respects the scheme for cache entries, which is the expected behaviour. however, Store::purge($url) also respects the scheme when invalidating the cache. This seems wrong to me.

This PR is rather rough for now, and i did not even look at the tests. Do the maintainers agree with my assumption? Should it be a bugfix against 2.8? Any input on the code?

Commits
-------

15da53c purge both http and https from http cache store
@fabpot fabpot closed this Feb 18, 2017
This was referenced Mar 6, 2017

return $this->doPurge($http) || $this->doPurge($https);
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the title of this PR, I would have expected this to be an && instead of an ||

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my thinking was that when either http or https was purged we report that something was purged. the chances that both http and https were in cache are small.

i think the most sane use case for this is when doing cache invalidation, e.g. with FOSHttpCache: you need to send a request to the specific host by ip, rather than the domain name, to target each server instance. but if you do that over https, you get certificate mismatches and thus want to use http.

apart from such special cases, your webserver should probably redirect requests from http to https rather than allow both.

@fabpot fabpot mentioned this pull request Mar 9, 2017
fabpot added a commit that referenced this pull request Mar 21, 2017
This PR was squashed before being merged into the 2.7 branch (closes #22079).

Discussion
----------

[HttpKernel] Fixed bug with purging of HTTPS URLs

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

I found two bugs in `HttpCache\Store::purge()` with HTTPS URLs:

1. `->purge('https://example.com/')` only purges the `http` version not the `https` one.
2. If a cache entry exists for both `http` and `https`, only the `http` version gets purged, the `https` version stays in the cache.

I think this issues were introduced with #21582.

This pull request fixes both issues and adds tests for them.

Commits
-------

f509150 [HttpKernel] Fixed bug with purging of HTTPS URLs
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