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() ignores If-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 whose Last-Modified is the epoch as having no modification date: If-Unmodified-Since always gives 412, and If-Modified-Since never gives 304.
  • ConditionalGetMiddleware passes an epoch Last-Modified on as missing, and skips conditional handling altogether when the response has no ETag.
  • @condition / @last_modified don't add the Last-Modified header when last_modified_func returns 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 canblmz, 44 minutes ago

Has patch: set

comment:2 by canblmz, 32 minutes ago

Has patch: unset
Note: See TracTickets for help on using tickets.
Back to Top