Skip to content

Commit ff302a1

Browse files
committed
Keep canonical WebFinger aliases
When a split-origin acct lookup uses a non-canonical username, include the preferred username on the web-origin host in aliases. This keeps the fallback acct response consistent with actor URI lookups while preserving the queried alias. #921 (comment) Assisted-by: Codex:gpt-5.5
1 parent 278aa05 commit ff302a1

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

packages/fedify/src/federation/webfinger.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ test("handleWebFinger()", async (t) => {
269269
? "someone"
270270
: username === "bar"
271271
? "someone2"
272+
: username === "qux"
273+
? "someone2"
272274
: null;
273275
};
274276

@@ -442,6 +444,47 @@ test("handleWebFinger()", async (t) => {
442444
],
443445
});
444446

447+
u.searchParams.set("resource", "acct:qux@ap.example.com");
448+
context = createContext(u);
449+
request = context.request;
450+
response = await handleWebFinger(request, {
451+
context,
452+
host: "example.com",
453+
actorDispatcher,
454+
actorHandleMapper,
455+
onNotFound,
456+
});
457+
assertEquals(response.status, 200);
458+
assertEquals(await response.json(), {
459+
subject: "acct:bar@example.com",
460+
aliases: [
461+
"https://ap.example.com/users/someone2",
462+
"acct:qux@ap.example.com",
463+
"acct:bar@ap.example.com",
464+
],
465+
links: [
466+
{
467+
href: "https://ap.example.com/users/someone2",
468+
rel: "self",
469+
type: "application/activity+json",
470+
},
471+
{
472+
href: "https://ap.example.com/@someone2",
473+
rel: "http://webfinger.net/rel/profile-page",
474+
},
475+
{
476+
href: "https://ap.example.com/@someone2",
477+
rel: "alternate",
478+
type: "text/html",
479+
},
480+
{
481+
href: "https://ap.example.com/icon.jpg",
482+
rel: "http://webfinger.net/rel/avatar",
483+
type: "image/jpeg",
484+
},
485+
],
486+
});
487+
445488
u = new URL(url);
446489
u.searchParams.set("resource", "acct:someone@handle.example.com");
447490
context = createContext(u);

packages/fedify/src/federation/webfinger.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ async function handleWebFingerInternal<TContextData>(
259259
) {
260260
subject = `acct:${actor.preferredUsername ?? acctUsername}@${host}`;
261261
aliases.push(resourceUrl.href);
262+
if (
263+
actor.preferredUsername != null && actor.preferredUsername !== "" &&
264+
actor.preferredUsername !== acctUsername
265+
) {
266+
aliases.push(`acct:${actor.preferredUsername}@${context.url.host}`);
267+
}
262268
}
263269
const jrd: ResourceDescriptor = {
264270
subject,

0 commit comments

Comments
 (0)