Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ To be released.
collections instead of being treated as unknown routes.
[[#849], [#851] by ChanHaeng Lee]

- Fixed split-origin WebFinger responses for `acct:` aliases on the web
Comment thread
dahlia marked this conversation as resolved.
origin host. When a local actor is queried through the server-origin
`acct:` alias, Fedify now returns the canonical handle-host `acct:` URI as
the JRD `subject` and keeps the queried `acct:` URI in `aliases`.
[[#920], [#921]]

[#849]: https://github.com/fedify-dev/fedify/issues/849
[#851]: https://github.com/fedify-dev/fedify/pull/851
[#920]: https://github.com/fedify-dev/fedify/issues/920
[#921]: https://github.com/fedify-dev/fedify/pull/921

### @fedify/cli

Expand Down
35 changes: 30 additions & 5 deletions packages/fedify/src/federation/webfinger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,47 @@ test("handleWebFinger()", async (t) => {
});

await t.step("handleHost", async () => {
const u = new URL(url);
u.searchParams.set("resource", "acct:someone@example.com");
let u = new URL("https://ap.example.com/.well-known/webfinger");
u.searchParams.set("resource", "acct:someone@ap.example.com");
let context = createContext(u);
let request = context.request;
let response = await handleWebFinger(request, {
context,
host: "handle.example.com",
host: "example.com",
actorDispatcher,
onNotFound,
});
assertEquals(response.status, 200);
assertEquals(await response.json(), {
...expected,
aliases: [...expected.aliases, "acct:someone@handle.example.com"],
subject: "acct:someone@example.com",
aliases: [
"https://ap.example.com/users/someone",
"acct:someone@ap.example.com",
],
links: [
{
href: "https://ap.example.com/users/someone",
rel: "self",
type: "application/activity+json",
},
{
href: "https://ap.example.com/@someone",
rel: "http://webfinger.net/rel/profile-page",
},
{
href: "https://ap.example.com/@someone",
rel: "alternate",
type: "text/html",
},
{
href: "https://ap.example.com/icon.jpg",
rel: "http://webfinger.net/rel/avatar",
type: "image/jpeg",
},
],
});

u = new URL(url);
u.searchParams.set("resource", "acct:someone@handle.example.com");
context = createContext(u);
request = context.request;
Expand Down
6 changes: 4 additions & 2 deletions packages/fedify/src/federation/webfinger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ async function handleWebFingerInternal<TContextData>(
}

const aliases: string[] = [];
let subject = resourceUrl.href;
if (resourceUrl.protocol != "acct:" && actor.preferredUsername != null) {
aliases.push(`acct:${actor.preferredUsername}@${host ?? context.url.host}`);
if (host != null && host !== context.url.host) {
Expand All @@ -255,10 +256,11 @@ async function handleWebFingerInternal<TContextData>(
!resourceUrl.href.endsWith(`@${host}`)
) {
const username = resourceUrl.href.replace(/^acct:/, "").replace(/@.*$/, "");
aliases.push(`acct:${username}@${host}`);
subject = `acct:${actor.preferredUsername ?? username}@${host}`;
aliases.push(resourceUrl.href);
Comment thread
dahlia marked this conversation as resolved.
Outdated
}
const jrd: ResourceDescriptor = {
subject: resourceUrl.href,
subject,
aliases,
links,
};
Expand Down
Loading