-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
Description
As initially conjectured in #2129 (comment), Express's default etag behavior is very broken.
As stated by section 2.1 of RFC 7232:
A "strong validator" is representation metadata that changes value
whenever a change occurs to the representation data that would be
observable in the payload body of a 200 (OK) response to GET.[...]
A collision-resistant hash function applied to
the representation data is also sufficient if the data is available
prior to the response header fields being sent and the digest does
not need to be recalculated every time a validation request is
received.[...]
In contrast, a "weak validator" is representation metadata that might
not change for every change to the representation data. This
weakness might be due to limitations in how the value is calculated,
such as clock resolution, an inability to ensure uniqueness for all
possible representations of the resource, or a desire of the resource
owner to group representations by some self-determined set of
equivalency rather than unique sequences of data. An origin server
SHOULD change a weak entity-tag whenever it considers prior
representations to be unacceptable as a substitute for the current
representation. In other words, a weak entity-tag ought to change
whenever the origin server wants caches to invalidate old responses.For example, the representation of a weather report that changes in
content every second, based on dynamic measurements, might be grouped
into sets of equivalent representations (from the origin server's
perspective) with the same weak validator in order to allow cached
representations to be valid for a reasonable period of time (perhaps
adjusted dynamically based on server load or weather quality).
Likewise, a representation's modification time, if defined with only
one-second resolution, might be a weak validator if it is possible
for the representation to be modified twice during a single second
and retrieved between those modifications.Likewise, a validator is weak if it is shared by two or more
representations of a given resource at the same time, unless those
representations have identical representation data. For example, if
the origin server sends the same validator for a representation with
a gzip content coding applied as it does for a representation with no
content coding, then that validator is weak.
TL;DR: A "weak etag" is an etag that is based on metadata. The "weak" in "weak etag" has nothing to do with collision-resistance weakness: all etags are interpreted to be semantically collision-resistant. Yet the behavior of Express when etag is set to weak (the default) is to use a hash-like function not resistant to collisions, prefixed with 'W/' (the signifier that denotes that the response would be semantically equivalent, if not byte equivalent, to other responses with that etag).
On top of being semantically wrong, this could be exploited by an attacker to set a value that would permute a page's etag to remain the same, denying requests for it from receiving the new version of the page whenever its content would be changed.