Skip to content

Commit

Permalink
Fix: forkbomb DOS mitigation
Browse files Browse the repository at this point in the history
  • Loading branch information
atsu1125 committed Dec 7, 2022
1 parent be04a95 commit 416c239
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/backend/src/remote/activitypub/models/mention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import * as promiseLimit from 'promise-limit';
import Resolver from '../resolver';
import { User } from '@/models/entities/user';

export async function extractApMentions(tags: IObject | IObject[] | null | undefined) {
export async function extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver) {
const hrefs = unique(extractApMentionObjects(tags).map(x => x.href as string));

const resolver = new Resolver();

const limit = promiseLimit<User | null>(2);
const mentionedUsers = (await Promise.all(
hrefs.map(x => limit(() => resolvePerson(x, resolver).catch(() => null)))
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/remote/activitypub/models/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
throw new Error('actor has been suspended');
}

const noteAudience = await parseAudience(actor, note.to, note.cc);
const noteAudience = await parseAudience(actor, note.to, note.cc, resolver);
let visibility = noteAudience.visibility;
const visibleUsers = noteAudience.visibleUsers;

Expand All @@ -111,7 +111,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s

let isTalk = note._misskey_talk && visibility === 'specified';

const apMentions = await extractApMentions(note.tag);
const apMentions = await extractApMentions(note.tag, resolver);
const apHashtags = await extractApHashtags(note.tag);

// 添付ファイル
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/remote/activitypub/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class Resolver {

constructor(recursionLimit = 100) {
this.history = new Set();
this.recursionLimit = recursionLimit;
}

public getHistory(): string[] {
Expand Down

0 comments on commit 416c239

Please sign in to comment.