Repository navigation
Description
Hi,
POST method request will delete existing cache with the same URL, i.e. anyone can flush the cache of any URL by simply sending a POST method request, that is not an expected behaviour, I believe.
This is the behaviour with the configuration where proxy.config.http.cache.post_method is 0 (the default value).
$ curl -v --output /dev/null http://cacheable.example.com/ |& grep age:
age: 0 <-- initial request, thus fresh response
$ curl -v --output /dev/null http://cacheable.example.com/ |& grep age:
age: 1 <-- cached response
$ curl -X POST -v --output /dev/null http://cacheable.example.com/ |& grep age:
age: 0 <-- fresh response, because POST is not cachable
$ curl -v --output /dev/null http://cacheable.example.com/ |& grep age:
age: 0 <-- fresh response, because the existing cache was deleted by POST request above
This is because is_method_cacheable is false for POST method request
| HttpTransactHeaders::is_method_cacheable(const HttpConfigParams *http_config_param, const int method) |
but
does_method_require_cache_copy_deletion is truetrafficserver/proxy/http/HttpTransact.cc
Line 666 in 3bb1ae9
| does_method_require_cache_copy_deletion(const HttpConfigParams *http_config_param, const int method) |
that is called in issue_revalidate where the existing cache will be deleted.
trafficserver/proxy/http/HttpTransact.cc
Line 2419 in 3bb1ae9
| if (does_method_require_cache_copy_deletion(s->http_config_param, s->method)) { |
(does_method_require_cache_copy_deletion is also used in HandleCacheOpenReadMiss, where it just does CACHE_DO_NO_ACTION.)
trafficserver/proxy/http/HttpTransact.cc
Line 3262 in 3bb1ae9
| if (does_method_require_cache_copy_deletion(s->http_config_param, s->method) && s->api_req_cacheable == false) { |
For now I am not sure what is the right way to fix this issue. does_method_require_cache_copy_deletion should exclude cases where is_method_cacheable is true ? Or issue_revalidate should delete cache only when both is_method_cacheable and does_method_require_cache_copy_deletion are true ?
Thanks in advance !
Kazuhiko
Activity
bryancall commentedon May 14, 2021
@fdiary We should delete the cache entry after receiving a 2xx response from the origin.
fdiary commentedon May 14, 2021
@bryancall (by default) ATS does not cache POST request response. Why do you think we "should" delete the existing cache generated by GET request response with such non-cacheable request ?
bneradt commentedon May 19, 2021
I've written an AuTest that reproduces this on a local branch. I'm now considering how ATS's behavior should change.
I agree with @bryancall 's comment: that is, we should delete the cached entry if a 2xx is received from the server to a POST. The problem with keeping the cached content valid is that the POST potentially invalidates the resource because POST is an unsafe method.
Consider this sequence:
How should ATS respond to this GET request? It should not serve out of the cache the response received from the server in step 2 since that response has been invalidated.
However, we don't want to invalidate such entries to previous GET requests if the POST failed (i.e., if the server responds with a non-2xx response). That would be too aggressive, and that is what we currently do.
The RFC seems to describe this proposed behavior here:
https://datatracker.ietf.org/doc/html/rfc7234#section-4.4
vpelletier commentedon May 24, 2021
While further investigating this issue with @fdiary, I noticed this part also in rfc7234 section-4.4 (emphasis mine):
I was under the initial impression that POST responses should only invalidate the cache when they contain
Locationand/orContent-Locationand then only the resources they identify would be invalidated (and not the Request URI).We now believe the original reason for the present bug report was misguided: invalidating the Request URI of a POST request is RFC-compliant, and it is up to us to direct POSTs to URIs which we do not want to invalidate.
The efficiency of us changing our POST URIs kind of depends on error statuses not invalidating the resources, otherwise a malicious (...for a rather tame meaning of "malicious", I believe) client can evict arbitrary entries from the cache by sending POST requests on URIs not intended to receiving them even if they correctly reject the POST. Thanks a lot for spotting this.