summaryrefslogtreecommitdiff
path: root/internal/federation/dereferencing/account.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2025-01-30 09:40:21 +0000
committerLibravatar GitHub <noreply@github.com>2025-01-30 10:40:21 +0100
commit1ab960bf151d7b6440ee8611041447894abbc458 (patch)
treec70468864c2eab544d596b2309d1b01f1ce93971 /internal/federation/dereferencing/account.go
parent[feature] Use maintenance router to serve 503 while server is starting/migrat... (diff)
downloadgotosocial-1ab960bf151d7b6440ee8611041447894abbc458.tar.xz
[bugfix] harden checks for remotes masquerading as local, and return correct local account redirects early (#3706)
Diffstat (limited to 'internal/federation/dereferencing/account.go')
-rw-r--r--internal/federation/dereferencing/account.go25
1 files changed, 17 insertions, 8 deletions
diff --git a/internal/federation/dereferencing/account.go b/internal/federation/dereferencing/account.go
index a47284c34..a9a816b4c 100644
--- a/internal/federation/dereferencing/account.go
+++ b/internal/federation/dereferencing/account.go
@@ -639,7 +639,16 @@ func (d *Dereferencer) enrichAccount(
return nil, nil, gtserror.Newf("db error getting account after redirects: %w", err)
}
- if alreadyAcc != nil {
+ switch {
+ case alreadyAcc == nil:
+ // nothing to do
+
+ case alreadyAcc.IsLocal():
+ // Request eventually redirected to a
+ // local account. Return it as-is here.
+ return alreadyAcc, nil, nil
+
+ default:
// We had this account stored
// under discovered final URI.
//
@@ -718,12 +727,6 @@ func (d *Dereferencer) enrichAccount(
latestAcc.Username = cmp.Or(latestAcc.Username, accUsername)
}
- if latestAcc.Domain == "" {
- // Ensure we have a domain set by this point,
- // otherwise it gets stored as a local user!
- return nil, nil, gtserror.Newf("empty domain for %s", uri)
- }
-
// Ensure the final parsed account URI matches
// the input URI we fetched (or received) it as.
if matches, err := util.URIMatches(
@@ -740,10 +743,16 @@ func (d *Dereferencer) enrichAccount(
} else if !matches {
return nil, nil, gtserror.Newf(
"account uri %s does not match %s",
- latestAcc.URI, uri.String(),
+ latestAcc.URI, uri,
)
}
+ // Ensure this isn't a local account,
+ // or a remote masquerading as such!
+ if latestAcc.IsLocal() {
+ return nil, nil, gtserror.Newf("cannot dereference local account %s", uri)
+ }
+
// Get current time.
now := time.Now()