Changeset 188690 in webkit


Ignore:
Timestamp:
Aug 20, 2015 10:47:08 AM (9 years ago)
Author:
Chris Dumez
Message:

[Cocoa] Treat Epoch as invalid value for "Last-Modified" header
https://bugs.webkit.org/show_bug.cgi?id=148162
rdar://problem/22330837

Reviewed by Antti Koivisto.

Source/WebCore:

Ignore "Last-Modified" header when computing heuristic freshness if it
is Epoch. CFNetwork currently converts a malformed date for Last-Modified
into Epoch so there is no way for us to distinguish Epoch from invalid
input. Without this, we would end up with cached resources that have a
giant lifetime (> 4 years) due to a malformed HTTP header.

Some Websites (e.g. www.popehat.com) also wrongly return Epoch as
Last-Modified value and we would end up caching it overly aggressively.
Now that we consider Epoch as an invalid value for Last-Modified, it will
also work around this content bug.

Test: http/tests/cache/disk-cache/disk-cache-last-modified.html

  • platform/network/ResourceResponseBase.cpp:

(WebCore::ResourceResponseBase::lastModified):

LayoutTests:

Add better layout test coverage for using the "Last-Modified" header to
compute heuristic freshness. In particular, it adds coverage for the
following values: Epoch, malformed date.

  • http/tests/cache/disk-cache/disk-cache-last-modified-expected.txt: Added.
  • http/tests/cache/disk-cache/disk-cache-last-modified.html: Added.

New test.

  • http/tests/cache/disk-cache/resources/cache-test.js:

(makeHeaderValue):
makeHeaderValue() was not resolving 'now(-1000)' into a date. This means that the
tests using it would end up sending an invalid "Last-Modified" header which our
networking code was translating to Epoch. We now ignore Epoch as Last-Modified
value for computing heuristic freshness to not cache due to malformed headers.

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r188686 r188690  
     12015-08-20  Chris Dumez  <cdumez@apple.com>
     2
     3        [Cocoa] Treat Epoch as invalid value for "Last-Modified" header
     4        https://bugs.webkit.org/show_bug.cgi?id=148162
     5        rdar://problem/22330837
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Add better layout test coverage for using the "Last-Modified" header to
     10        compute heuristic freshness. In particular, it adds coverage for the
     11        following values: Epoch, malformed date.
     12
     13        * http/tests/cache/disk-cache/disk-cache-last-modified-expected.txt: Added.
     14        * http/tests/cache/disk-cache/disk-cache-last-modified.html: Added.
     15        New test.
     16
     17        * http/tests/cache/disk-cache/resources/cache-test.js:
     18        (makeHeaderValue):
     19        makeHeaderValue() was not resolving 'now(-1000)' into a date. This means that the
     20        tests using it would end up sending an invalid "Last-Modified" header which our
     21        networking code was translating to Epoch. We now ignore Epoch as Last-Modified
     22        value for computing heuristic freshness to not cache due to malformed headers.
     23
    1242015-08-20  Eric Carlson  <eric.carlson@apple.com>
    225
  • trunk/LayoutTests/http/tests/cache/disk-cache/resources/cache-test.js

    r188468 r188690  
    3434    if (value == 'now(100)')
    3535        return (new Date(new Date().getTime() + serverClientTimeDelta + 100 * 1000)).toUTCString();
     36    if (value == 'now(-1000)')
     37        return (new Date(new Date().getTime() - serverClientTimeDelta - 1000 * 1000)).toUTCString()
    3638    if (value == 'unique()')
    3739        return "" + uniqueIdCounter++;
  • trunk/Source/WebCore/ChangeLog

    r188687 r188690  
     12015-08-20  Chris Dumez  <cdumez@apple.com>
     2
     3        [Cocoa] Treat Epoch as invalid value for "Last-Modified" header
     4        https://bugs.webkit.org/show_bug.cgi?id=148162
     5        rdar://problem/22330837
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Ignore "Last-Modified" header when computing heuristic freshness if it
     10        is Epoch. CFNetwork currently converts a malformed date for Last-Modified
     11        into Epoch so there is no way for us to distinguish Epoch from invalid
     12        input. Without this, we would end up with cached resources that have a
     13        giant lifetime (> 4 years) due to a malformed HTTP header.
     14
     15        Some Websites (e.g. www.popehat.com) also wrongly return Epoch as
     16        Last-Modified value and we would end up caching it overly aggressively.
     17        Now that we consider Epoch as an invalid value for Last-Modified, it will
     18        also work around this content bug.
     19
     20        Test: http/tests/cache/disk-cache/disk-cache-last-modified.html
     21
     22        * platform/network/ResourceResponseBase.cpp:
     23        (WebCore::ResourceResponseBase::lastModified):
     24
    1252015-08-19  Brian Burg  <bburg@apple.com>
    226
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp

    r183901 r188690  
    426426    if (!m_haveParsedLastModifiedHeader) {
    427427        m_lastModified = parseDateValueInHeader(m_httpHeaderFields, HTTPHeaderName::LastModified);
     428#if PLATFORM(COCOA)
     429        // CFNetwork converts malformed dates into Epoch so we need to treat Epoch as
     430        // an invalid value (rdar://problem/22352838).
     431        const std::chrono::system_clock::time_point epoch;
     432        if (m_lastModified && m_lastModified.value() == epoch)
     433            m_lastModified = Nullopt;
     434#endif
    428435        m_haveParsedLastModifiedHeader = true;
    429436    }
Note: See TracChangeset for help on using the changeset viewer.