diff --git a/packages/backend/src/remote/activitypub/kernel/index.ts b/packages/backend/src/remote/activitypub/kernel/index.ts index b8af3dc487..e24af2b387 100644 --- a/packages/backend/src/remote/activitypub/kernel/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/index.ts @@ -18,6 +18,7 @@ import { isCollection, isFlag, isMove, + getApId, } from '../type.js'; import { apLogger } from '../logger.js'; import Resolver from '../resolver.js'; @@ -37,6 +38,8 @@ import block from './block/index.js'; import flag from './flag/index.js'; import move from './move/index.js'; import type { IObject } from '../type.js'; +import { extractDbHost } from '@/misc/convert-host.js'; +import { shouldBlockInstance } from '@/misc/should-block-instance.js'; export async function performActivity(actor: CacheableRemoteUser, activity: IObject) { if (isCollectionOrOrderedCollection(activity)) { @@ -59,6 +62,12 @@ export async function performActivity(actor: CacheableRemoteUser, activity: IObj async function performOneActivity(actor: CacheableRemoteUser, activity: IObject): Promise { if (actor.isSuspended) return; + if (typeof activity.id !== 'undefined') { + const host = extractDbHost(getApId(activity)); + if (await shouldBlockInstance(host)) return; + } + + if (isCreate(activity)) { await create(actor, activity); } else if (isDelete(activity)) { diff --git a/packages/backend/src/remote/activitypub/resolver.ts b/packages/backend/src/remote/activitypub/resolver.ts index 8958c892a7..e4fdedac94 100644 --- a/packages/backend/src/remote/activitypub/resolver.ts +++ b/packages/backend/src/remote/activitypub/resolver.ts @@ -5,7 +5,7 @@ import { getInstanceActor } from '@/services/instance-actor.js'; import { fetchMeta } from '@/misc/fetch-meta.js'; import { extractDbHost, isSelfHost } from '@/misc/convert-host.js'; import { signedGet } from './request.js'; -import { IObject, isCollectionOrOrderedCollection, ICollection, IOrderedCollection } from './type.js'; +import { IObject, isCollectionOrOrderedCollection, ICollection, IOrderedCollection, getApId } from './type.js'; import { FollowRequests, Notes, NoteReactions, Polls, Users } from '@/models/index.js'; import { parseUri } from './db-resolver.js'; import renderNote from '@/remote/activitypub/renderer/note.js'; @@ -49,6 +49,12 @@ export default class Resolver { } if (typeof value !== 'string') { + if (typeof value.id !== 'undefined') { + const host = extractDbHost(getApId(value)); + if (await shouldBlockInstance(host)) { + throw new Error('instance is blocked'); + } + } return value; }