From b20298ceb12491b0bb87dd9b98f7c2bd6c9aa535 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 28 Jun 2023 02:01:55 +0200 Subject: [PATCH] Fix AP resolver history on reuse for authorized fetch --- packages/backend/src/remote/activitypub/request.ts | 2 +- packages/backend/src/remote/activitypub/resolver.ts | 12 +++++++++++- packages/backend/src/server/api/endpoints/ap/show.ts | 8 ++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/remote/activitypub/request.ts b/packages/backend/src/remote/activitypub/request.ts index 7360f95449..69c97a445d 100644 --- a/packages/backend/src/remote/activitypub/request.ts +++ b/packages/backend/src/remote/activitypub/request.ts @@ -36,7 +36,7 @@ export default async (user: { id: User["id"] }, url: string, object: any) => { * @param url URL to fetch */ export async function signedGet(url: string, user: { id: User["id"] }) { - apLogger.debug("running signedGet on url: " + url); + apLogger.debug(`Running signedGet on url: ${url}`); const keypair = await getUserKeypair(user.id); const req = createSignedGet({ diff --git a/packages/backend/src/remote/activitypub/resolver.ts b/packages/backend/src/remote/activitypub/resolver.ts index e6bbf9fafc..608ca3e935 100644 --- a/packages/backend/src/remote/activitypub/resolver.ts +++ b/packages/backend/src/remote/activitypub/resolver.ts @@ -39,6 +39,11 @@ export default class Resolver { this.user = user; } + public reset(): Resolver { + this.history = new Set(); + return this; + } + public getHistory(): string[] { return Array.from(this.history); } @@ -61,15 +66,20 @@ export default class Resolver { } if (typeof value !== "string") { + apLogger.debug("Object to resolve is not a string"); if (typeof value.id !== "undefined") { const host = extractDbHost(getApId(value)); if (await shouldBlockInstance(host)) { throw new Error("instance is blocked"); } } + apLogger.debug("Returning existing object:"); + apLogger.debug(JSON.stringify(value, null, 2)); return value; } + apLogger.debug(`Resolving: ${value}`); + if (value.includes("#")) { // URLs with fragment parts cannot be resolved correctly because // the fragment part does not get transmitted over HTTP(S). @@ -107,7 +117,7 @@ export default class Resolver { this.user = await getInstanceActor(); } - apLogger.debug("getting object from remote, authenticated as user:"); + apLogger.debug("Getting object from remote, authenticated as user:"); apLogger.debug(JSON.stringify(this.user, null, 2)); const object = ( diff --git a/packages/backend/src/server/api/endpoints/ap/show.ts b/packages/backend/src/server/api/endpoints/ap/show.ts index 2fdf24075d..3dd168d718 100644 --- a/packages/backend/src/server/api/endpoints/ap/show.ts +++ b/packages/backend/src/server/api/endpoints/ap/show.ts @@ -145,8 +145,12 @@ async function fetchAny( return await mergePack( me, - isActor(object) ? await createPerson(getApId(object), resolver) : null, - isPost(object) ? await createNote(getApId(object), resolver, true) : null, + isActor(object) + ? await createPerson(getApId(object), resolver.reset()) + : null, + isPost(object) + ? await createNote(getApId(object), resolver.reset(), true) + : null, ); }