Opened 47 minutes ago
Last modified 32 minutes ago
#37487 assigned Bug
Conditional request handling treats the Unix epoch as a missing date
| Reported by: | canblmz | Owned by: | canblmz |
|---|---|---|---|
| Component: | HTTP handling | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
parse_http_date_safe() returns 0 for Thu, 01 Jan 1970 00:00:00 GMT, and the conditional request code checks these timestamps for truthiness, so the epoch is handled as if the date were missing:
get_conditional_response()ignoresIf-Unmodified-Since: Thu, 01 Jan 1970 00:00:00 GMT, so a request that should get 412 (for any resource modified after 1970) goes through._if_unmodified_since_passes()and_if_modified_since_passes()treat a resource whoseLast-Modifiedis the epoch as having no modification date:If-Unmodified-Sincealways gives 412, andIf-Modified-Sincenever gives 304.ConditionalGetMiddlewarepasses an epochLast-Modifiedon as missing, and skips conditional handling altogether when the response has noETag.@condition/@last_modifieddon't add theLast-Modifiedheader whenlast_modified_funcreturns the epoch.
An epoch Last-Modified can come up for files whose mtime was normalized to 0, e.g. by a reproducible build.
Comparing with is None / is not None instead fixes all four. I have a patch with tests ready.
This touches the same helper as #37252 (PR 21737), where not last_modified would also treat the epoch as missing. The two fixes are compatible, and I'm happy to rebase on whichever lands first.
Change History (2)
comment:1 by , 44 minutes ago
| Has patch: | set |
|---|
comment:2 by , 32 minutes ago
| Has patch: | unset |
|---|