add checks to resolver and performOneActivity

This commit is contained in:
Francis Dinh 2022-12-25 15:10:33 -05:00
parent d9b7219404
commit d2066d0d86
No known key found for this signature in database
GPG Key ID: 7123E30E441E80DE
2 changed files with 16 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import {
isCollection, isCollection,
isFlag, isFlag,
isMove, isMove,
getApId,
} from '../type.js'; } from '../type.js';
import { apLogger } from '../logger.js'; import { apLogger } from '../logger.js';
import Resolver from '../resolver.js'; import Resolver from '../resolver.js';
@ -37,6 +38,8 @@ import block from './block/index.js';
import flag from './flag/index.js'; import flag from './flag/index.js';
import move from './move/index.js'; import move from './move/index.js';
import type { IObject } from '../type.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) { export async function performActivity(actor: CacheableRemoteUser, activity: IObject) {
if (isCollectionOrOrderedCollection(activity)) { if (isCollectionOrOrderedCollection(activity)) {
@ -59,6 +62,12 @@ export async function performActivity(actor: CacheableRemoteUser, activity: IObj
async function performOneActivity(actor: CacheableRemoteUser, activity: IObject): Promise<void> { async function performOneActivity(actor: CacheableRemoteUser, activity: IObject): Promise<void> {
if (actor.isSuspended) return; if (actor.isSuspended) return;
if (typeof activity.id !== 'undefined') {
const host = extractDbHost(getApId(activity));
if (await shouldBlockInstance(host)) return;
}
if (isCreate(activity)) { if (isCreate(activity)) {
await create(actor, activity); await create(actor, activity);
} else if (isDelete(activity)) { } else if (isDelete(activity)) {

View File

@ -5,7 +5,7 @@ import { getInstanceActor } from '@/services/instance-actor.js';
import { fetchMeta } from '@/misc/fetch-meta.js'; import { fetchMeta } from '@/misc/fetch-meta.js';
import { extractDbHost, isSelfHost } from '@/misc/convert-host.js'; import { extractDbHost, isSelfHost } from '@/misc/convert-host.js';
import { signedGet } from './request.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 { FollowRequests, Notes, NoteReactions, Polls, Users } from '@/models/index.js';
import { parseUri } from './db-resolver.js'; import { parseUri } from './db-resolver.js';
import renderNote from '@/remote/activitypub/renderer/note.js'; import renderNote from '@/remote/activitypub/renderer/note.js';
@ -49,6 +49,12 @@ export default class Resolver {
} }
if (typeof value !== 'string') { 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; return value;
} }