import { Activity, ActivityType } from '../../../../shared/models/activitypub'
-import { getActorUrl } from '../../../helpers/activitypub'
+import { checkUrlsSameHost, getActorUrl } from '../../../helpers/activitypub'
import { logger } from '../../../helpers/logger'
import { ActorModel } from '../../../models/activitypub/actor'
import { processAcceptActivity } from './process-accept'
Like: processLikeActivity
}
-async function processActivities (activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel) {
+async function processActivities (
+ activities: Activity[],
+ options: {
+ signatureActor?: ActorModel
+ inboxActor?: ActorModel
+ outboxUrl?: string
+ } = {}) {
const actorsCache: { [ url: string ]: ActorModel } = {}
for (const activity of activities) {
- if (!signatureActor && [ 'Create', 'Announce', 'Like' ].indexOf(activity.type) === -1) {
+ if (!options.signatureActor && [ 'Create', 'Announce', 'Like' ].indexOf(activity.type) === -1) {
logger.error('Cannot process activity %s (type: %s) without the actor signature.', activity.id, activity.type)
continue
}
const actorUrl = getActorUrl(activity.actor)
// When we fetch remote data, we don't have signature
- if (signatureActor && actorUrl !== signatureActor.url) {
- logger.warn('Signature mismatch between %s and %s.', actorUrl, signatureActor.url)
+ if (options.signatureActor && actorUrl !== options.signatureActor.url) {
+ logger.warn('Signature mismatch between %s and %s, skipping.', actorUrl, options.signatureActor.url)
continue
}
- const byActor = signatureActor || actorsCache[actorUrl] || await getOrCreateActorAndServerAndModel(actorUrl)
+ if (options.outboxUrl && checkUrlsSameHost(options.outboxUrl, actorUrl) !== true) {
+ logger.warn('Host mismatch between outbox URL %s and actor URL %s, skipping.', options.outboxUrl, actorUrl)
+ continue
+ }
+
+ const byActor = options.signatureActor || actorsCache[actorUrl] || await getOrCreateActorAndServerAndModel(actorUrl)
actorsCache[actorUrl] = byActor
const activityProcessor = processActivity[activity.type]
}
try {
- await activityProcessor(activity, byActor, inboxActor)
+ await activityProcessor(activity, byActor, options.inboxActor)
} catch (err) {
logger.warn('Cannot process activity %s.', activity.type, { err })
}