fix: Handle HTTP redirects for migrated instances in sharing sync#4658
fix: Handle HTTP redirects for migrated instances in sharing sync#4658
Conversation
71e3f81 to
d8e9035
Compare
taratatach
left a comment
There was a problem hiding this comment.
Looks like tryUpdateMemberInstance(err, m, opts) is called only if the error status is 410 Gone while we update opts.Domain if the error status is 401 Unauthorized.
Should we change the condition on line (newly) 666?
| finalHost := res.Request.URL.Host | ||
| if finalHost != "" && finalHost != opts.Domain { | ||
| // Redirect detected - update member instance to the new domain | ||
| newURL := &url.URL{Scheme: res.Request.URL.Scheme, Host: finalHost} |
There was a problem hiding this comment.
Can't we simply reuse res.Request.URL here?
There was a problem hiding this comment.
Go way to support a specific symbol in URLs, and to avoid string concat like scheme + "://" + host
Sorry, didn't get your question. Why do we need to change this condition? |
d8e9035 to
93a0c66
Compare
Summary
Problem
When an instance is migrated from one domain to another (e.g., alice.mycozy.cloud → alice.twake.app) using 302 redirects instead of the official move functionality, sharing sync fails with Unauthorized: {"error":"No token in request"}. When Go's http.Client follows a 302 redirect to a different host, it strips the Authorization header for security reasons (to prevent credential leakage to untrusted domains).
So:
Solution
Detect redirects by comparing the response's final URL (res.Request.URL) with the original request domain. When a cross-host redirect is detected: