<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>257327</bug_id>
          
          <creation_ts>2023-05-25 06:25:57 -0700</creation_ts>
          <short_desc>Old url hash fragment is used when loading page from cache</short_desc>
          <delta_ts>2023-05-30 13:49:05 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Page Loading</component>
          <version>Safari 16</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>255924</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=255924</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>saralkaushik</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>achristensen</cc>
    
    <cc>beidson</cc>
    
    <cc>brandonstewart</cc>
    
    <cc>cdumez</cc>
    
    <cc>koivisto</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1957893</commentid>
    <comment_count>0</comment_count>
    <who name="">saralkaushik</who>
    <bug_when>2023-05-25 06:25:57 -0700</bug_when>
    <thetext>Steps to reproduce...

1. Go to a URL that performs a 301 redirect, with a hash in the URL. E.g. https://www.monzo.com/#foo=bar
2. Observe that the user is redirected to https://monzo.com/#foo=bar
3. Go to a URL at a completely different domain name
4. Go to the same URL in step 1, but with a different hash https://www.monzo.com/#bar=foo

Expected Results

The user should be redirected to https://monzo.com/#bar=foo

Actual Results

The user is redirected to the URL from step 2, e.g. https://monzo.com/#foo=bar</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958218</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2023-05-26 09:37:53 -0700</bug_when>
    <thetext>Is this the same as bug 255924?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958870</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2023-05-30 13:41:35 -0700</bug_when>
    <thetext>I have a decent idea of where the issue may reside.

The key we use the network cache ignores the URL hash (which is intentional as pages with different fragments normally have the same bytes):
```
Key Cache::makeCacheKey(const WebCore::ResourceRequest&amp; request)
{
    // FIXME: This implements minimal Range header disk cache support. We don&apos;t parse
    // ranges so only the same exact range request will be served from the cache.
    String range = request.httpHeaderField(WebCore::HTTPHeaderName::Range);
    return { request.cachePartition(), resourceType(), range, request.url().stringWithoutFragmentIdentifier(), m_storage-&gt;salt() };
}
```

However, we also cache redirects in the cache and I think caching redirects with fragments may lead to confusion:
```
std::unique_ptr&lt;Entry&gt; Cache::makeRedirectEntry(const WebCore::ResourceRequest&amp; request, const WebCore::ResourceResponse&amp; response, const WebCore::ResourceRequest&amp; redirectRequest)
{
    auto cachedRedirectRequest = redirectRequest;
    cachedRedirectRequest.clearHTTPAuthorization();
    return makeUnique&lt;Entry&gt;(makeCacheKey(request), response, WTFMove(cachedRedirectRequest), WebCore::collectVaryingRequestHeaders(networkProcess().storageSession(m_sessionID), request, response));
}
```
because the response coming from the cache contains a fragment (and it may not match the one of the request)

So we when we navigate to https://www.monzo.com/#foo=bar, we cache an entry with the key &quot;https://www.monzo.com/#foo=bar&quot; which is a redirect to https://monzo.com/#foo=bar. Then later on, we try the load https://www.monzo.com/#bar=foo, we look up the same cached redirect, since we ignore the fragment in the request and end up redirecting the the cached destination URL (https://www.monzo.com/#foo=bar).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958872</commentid>
    <comment_count>3</comment_count>
    <who name="Brandon">brandonstewart</who>
    <bug_when>2023-05-30 13:44:26 -0700</bug_when>
    <thetext>This appears to be a duplicate of the issue I am working on.

https://bugs.webkit.org/show_bug.cgi?id=255924</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958873</commentid>
    <comment_count>4</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2023-05-30 13:49:05 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 255924 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>