server: block Create activites from blocked hosts #298
2 changed files with 11 additions and 2 deletions
|
@ -1,12 +1,15 @@
|
||||||
import { CacheableRemoteUser } from '@/models/entities/user.js';
|
import { CacheableRemoteUser } from '@/models/entities/user.js';
|
||||||
import { toArray, concat, unique } from '@/prelude/array.js';
|
import { toArray, concat, unique } from '@/prelude/array.js';
|
||||||
import { Resolver } from '@/remote/activitypub/resolver.js';
|
import { Resolver } from '@/remote/activitypub/resolver.js';
|
||||||
|
import { shouldBlockInstance } from '@/misc/should-block-instance.js';
|
||||||
|
import { extractDbHost } from '@/misc/convert-host.js';
|
||||||
import { ICreate, getApId, isPost, getApType } from '../../type.js';
|
import { ICreate, getApId, isPost, getApType } from '../../type.js';
|
||||||
import { apLogger } from '../../logger.js';
|
import { apLogger } from '../../logger.js';
|
||||||
import createNote from './note.js';
|
import createNote from './note.js';
|
||||||
|
|
||||||
export default async (actor: CacheableRemoteUser, activity: ICreate, resolver: Resolver): Promise<void> => {
|
export default async (actor: CacheableRemoteUser, activity: ICreate, resolver: Resolver): Promise<void> => {
|
||||||
const uri = getApId(activity);
|
const uri = getApId(activity);
|
||||||
|
if (await shouldBlockInstance(extractDbHost(uri))) return;
|
||||||
|
|||||||
|
|
||||||
apLogger.info(`Create: ${uri}`);
|
apLogger.info(`Create: ${uri}`);
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,19 @@ import { extractDbHost } from '@/misc/convert-host.js';
|
||||||
import { StatusError } from '@/misc/fetch.js';
|
import { StatusError } from '@/misc/fetch.js';
|
||||||
import { Resolver } from '@/remote/activitypub/resolver.js';
|
import { Resolver } from '@/remote/activitypub/resolver.js';
|
||||||
import { createNote, fetchNote } from '@/remote/activitypub/models/note.js';
|
import { createNote, fetchNote } from '@/remote/activitypub/models/note.js';
|
||||||
import { getApId, IObject, ICreate } from '@/remote/activitypub/type.js';
|
import { getApId, IObject } from '@/remote/activitypub/type.js';
|
||||||
|
import { shouldBlockInstance } from '@/misc/should-block-instance.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 投稿作成アクティビティを捌きます
|
* Handles post creation activity
|
||||||
*/
|
*/
|
||||||
export default async function(resolver: Resolver, actor: CacheableRemoteUser, note: IObject, silent = false): Promise<string> {
|
export default async function(resolver: Resolver, actor: CacheableRemoteUser, note: IObject, silent = false): Promise<string> {
|
||||||
const uri = getApId(note);
|
const uri = getApId(note);
|
||||||
|
const host = extractDbHost(uri);
|
||||||
|
|
||||||
|
if (await shouldBlockInstance(host)) {
|
||||||
|
return 'skip: blocked host';
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof note === 'object') {
|
if (typeof note === 'object') {
|
||||||
if (actor.uri !== note.attributedTo) {
|
if (actor.uri !== note.attributedTo) {
|
||||||
|
|
Loading…
Reference in a new issue
Shouldn't this already be covered by resolving the activity object further down? The object being created must be from the same host, otherwise it would have been caught by this check
if (extractDbHost(actor.uri) !== extractDbHost(note.id)) {
return 'skip: host in actor.uri !== note.id';
}
. I guess it was already embedded as an object so the usual checks aren't performed due to this short circuit
if (typeof value !== 'string') {
return value;
}
. Maybe a better idea to add the matching id/url and instance blocks in that case too.
Maybe also check this at a higher level, i.e. in
performOneActivity
.