Opened 7 months ago
Closed 5 months ago
#22258 closed defect (bug) (fixed)
nocache_headers fail to prevent aggressive caching in Chrome
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | General | Version: | 3.5 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | sirzooro, slene |
Description
In Chrome 22, a response with a valid Last-Modified header will be cached despite Cache-Control and Expires headers. So even though the user is logged in, the resource is cached and the browser sends If-Modified-Since with subsequent requests. This can result in a strange, partially-logged out experience with batcache under certain conditions.
In wp_get_nocache_headers(), the Last-Modified header is set to the current time. Setting its value to the empty string resolves the issue.
I will post two patches: one which only empties the Last-Modified header in the array, another which also removes the header when the header_remove() function is defined (PHP >= 5.3).
Attachments (4)
Change History (20)
comment:2
SergeyBiryukov — 7 months ago
Related: #21745
- Keywords commit added
- Milestone changed from Awaiting Review to 3.5
Looks good. Goes nicely with #21745.
Because there are filters in both wp_get_nocache_headers() and WP::send_headers(), here is an alternative patch.
Replying to nacin:
Because there are filters in both wp_get_nocache_headers() and WP::send_headers(), here is an alternative patch.
I endorse this patch.
Only side effect of 22258.3.diff is it could remove a valid Last-Modified header that is not set by WP or via the wp_headers filter. I don't think this is an issue, but in the interest of CYA, two possibilities: the extra send_headers() logic andy has, or 22258.4.diff.
RFC2616 doesn't say much about this, but some reading: http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-13#page-10. If the Date and Last-Modified headers are within 60 seconds (and they would be here, barring a server misconfiguration), it is considered a weak validator, because of potential timing inconsistencies; they are also considered weak for being only accurate to the second.
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In [22283]:
- Resolution fixed deleted
- Status changed from closed to reopened
Do we want to silence header_remove() like we do header() to avoid "Cannot modify header information - headers already sent by..." messages? These are popping up all over the unit tests.
comment:10
andy — 7 months ago
Good catch, but the @-bandage wastes more dev time than a clean fix would. I would rather see core functions with header() calls do something smart like check headers_sent() and trigger_error().
comment:11
nacin — 7 months ago
Would probably be easiest if we just checked headers_sent() at the start of nocache_headers(), and in WP::send_headers(). There's no reason to error-suppress header() a half-dozen times when we can bypass it all together.
comment:12
nacin — 7 months ago
Though, @ isn't as bad, because if someone is using xdebug.scream or a custom error handler (including the Debug Bar), it doesn't get masked in the way headers_sent() would. At least it is consistent with our use of @header(), and we can possibly make changes later.
comment:13
in reply to:
↑ 9
sirzooro — 7 months ago
- Cc sirzooro added
comment:14
nacin — 7 months ago
- Resolution set to fixed
- Status changed from reopened to closed
In [22303]:
comment:15
slene — 5 months ago
- Cc slene added
- Keywords needs-patch added; has-patch removed
- Resolution fixed deleted
- Status changed from closed to reopened
In php5.2 the Last-Modified header always blank !!!
A response with a blank Last-Modified header will be set to "Thu, 01 Jan 1970 00:00:00 GMT" in some server. The browser will be always send a If-Modified-Since header "Thu, 01 Jan 1970 00:00:00 GMT". and the server response a 304 status code. Make the browser can not refresh cache.
sorry my bad english...
comment:16
SergeyBiryukov — 5 months ago
- Keywords has-patch added; needs-patch removed
- Resolution set to fixed
- Status changed from reopened to closed
This ticket was closed on a completed milestone. If you believe there's a problem, please open a new one. That sounds like server misconfiguration though.

Empty Last-Modified