Bug 255924

Summary: URI Fragments Cached After 301 Redirect
Product: WebKit Reporter: zachshaw1
Component: Page LoadingAssignee: Brandon <brandonstewart>
Status: RESOLVED FIXED    
Severity: Major CC: achristensen, beidson, brandonstewart, bugs-noreply, cdumez, koivisto, mcatanzaro, saralkaushik, simon.khalil, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari 16   
Hardware: All   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=257327

Description zachshaw1 2023-04-25 08:12:04 PDT
Version: Safari 16.4 (macOS & iOS)

When Safari is redirected by a 301 with URI fragments, for example site.com/page#key=123 -> www.site.com/page#key=123, any subsequent page hits after the 301, Safari will use the initial cached URI fragments.

This isn't happening on any other browser, nor is this happening on Safari 16.3 the new URI fragments are correctly picked up.

Disable Caches enabled & private browsing both work fine as well.
Comment 1 simon 2023-04-25 08:18:39 PDT
I'm having this issue too. 

Strangely after a 301 the URL fragment is picking up cached values instead of the new fragment values. 

Very odd behaviour
Comment 2 Radar WebKit Bug Importer 2023-04-25 18:38:40 PDT
<rdar://problem/108535944>
Comment 3 Brandon 2023-05-25 11:48:29 PDT
Was doing some testing and was able to reproduce back on Safari 16.2 and a recent version of Safari.

Testing

Redirect Server

from http.server import HTTPServer, BaseHTTPRequestHandler

class Redirect(BaseHTTPRequestHandler):
   def do_GET(self):
       print("hello")
       self.send_response(301)
       self.send_header('Location', 'http://localhost:8000')
       self.send_header('Referrer-Policy', 'same-origin')
       self.end_headers()

HTTPServer(('', 10000), Redirect).serve_forever()

##################

Server to redirect to

python3 -m http.server --bind 127.0.0.1 --directory . 8000

index.html
<!DOCTYPE html>
<html>
<p>Hello World</p>
</html>


URL

Go to localhost:10000/#key=foo
Then go to localhost:10000/#key=bar

I noticed it works correctly on the second time you visit the redirect.

URL Enter -> URL Result
localhost:10000/#key=foo -> localhost:8000/#key=foo 
localhost:10000/#key=bar -> localhost:8000/#key=foo
localhost:10000/#key=bar -> localhost:8000/#key=bar
Comment 4 Chris Dumez 2023-05-30 13:49:05 PDT
*** Bug 257327 has been marked as a duplicate of this bug. ***
Comment 5 Chris Dumez 2023-05-30 13:50:26 PDT
Seem information from dupe at https://bugs.webkit.org/show_bug.cgi?id=257327#c2 to help fix this.

Odds are we simply want to stop caching redirects when the request URL contains a fragment.
Comment 6 Chris Dumez 2023-05-30 13:53:15 PDT
(In reply to Chris Dumez from comment #5)
> Seem information from dupe at
> https://bugs.webkit.org/show_bug.cgi?id=257327#c2 to help fix this.
> 
> Odds are we simply want to stop caching redirects when the request URL
> contains a fragment.

It is not OK to navigate to https://www.monzo.com/#foo=bar, it is not OK to cache en entry like this:
```
https://www.monzo.com (because we drop fragment from cache keys) -> https://monzo.com/#foo=bar
```

Because this cached redirect would get reused for every load of https://www.monzo.com, no matter the fragment identifier.
Comment 7 Brandon 2023-05-30 16:26:28 PDT
Pull request: https://github.com/WebKit/WebKit/pull/14514
Comment 8 EWS 2023-07-10 10:04:26 PDT
Committed 265906@main (205444531ae8): <https://commits.webkit.org/265906@main>

Reviewed commits have been landed. Closing PR #14514 and removing active labels.