From 496454cf1fb9f7d3488d48b2d44e12f3921fe625 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sun, 22 Oct 2023 19:07:22 +0200 Subject: [PATCH] [backend] Fix initial federation initiated by GoToSocial in secure mode This bypasses GoToSocial issue #1186 (ref: https://github.com/superseriousbusiness/gotosocial/issues/1186) --- .../src/remote/activitypub/db-resolver.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/remote/activitypub/db-resolver.ts b/packages/backend/src/remote/activitypub/db-resolver.ts index d8aa3b706..02b0c2cd5 100644 --- a/packages/backend/src/remote/activitypub/db-resolver.ts +++ b/packages/backend/src/remote/activitypub/db-resolver.ts @@ -19,6 +19,9 @@ import type { IObject } from "./type.js"; import { getApId } from "./type.js"; import { resolvePerson, updatePerson } from "./models/person.js"; import {redisClient, subscriber} from "@/db/redis.js"; +import { remoteLogger } from "@/remote/logger.js"; + +const logger = remoteLogger.createSubLogger("db-resolver"); const publicKeyCache = new Cache("publicKey", 60 * 30); const publicKeyByUserIdCache = new Cache( @@ -188,7 +191,21 @@ export default class DbResolver { user: CacheableRemoteUser; key: UserPublickey | null; } | null> { - const user = (await resolvePerson(uri)) as CacheableRemoteUser; + let user: CacheableRemoteUser; + + try { + user = (await resolvePerson(uri)) as CacheableRemoteUser; + } + catch (e: any) { + // Bypass GoToSocial issue #1186 (ref: https://github.com/superseriousbusiness/gotosocial/issues/1186) + if (e.message === 'invalid Actor: wrong inbox' && uri.match(/https?:\/\/[a-zA-Z0-9-.]+\/users\/[a-zA-Z0-9_]+\/main-key$/)) { + logger.warn(`Failed to resolve ${uri}, re-attempting without trailing /main-key`); + user = (await resolvePerson(uri.substring(0, uri.length - 9))) as CacheableRemoteUser; + } + else { + throw e; + } + } if (user == null) return null;