2021-08-27 14:32:44 +02:00
|
|
|
import express from 'express'
|
2020-04-23 09:32:53 +02:00
|
|
|
import { getServerActor } from '@server/models/application/application'
|
2021-07-16 10:42:24 +02:00
|
|
|
import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes'
|
2021-07-16 14:27:30 +02:00
|
|
|
import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
2017-11-10 14:34:45 +01:00
|
|
|
|
2018-04-06 11:54:24 +02:00
|
|
|
async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
|
|
logger.debug('Checking activity pub parameters')
|
2017-11-10 14:34:45 +01:00
|
|
|
|
2018-04-06 11:54:24 +02:00
|
|
|
if (!isRootActivityValid(req.body)) {
|
|
|
|
logger.warn('Incorrect activity parameters.', { activity: req.body })
|
2021-06-01 16:07:58 +02:00
|
|
|
return res.fail({ message: 'Incorrect activity' })
|
2018-04-06 11:54:24 +02:00
|
|
|
}
|
2018-02-23 15:09:12 +01:00
|
|
|
|
2018-04-06 11:54:24 +02:00
|
|
|
const serverActor = await getServerActor()
|
2019-03-19 10:35:15 +01:00
|
|
|
const remoteActor = res.locals.signature.actor
|
2021-02-08 16:06:32 +01:00
|
|
|
if (serverActor.id === remoteActor.id || remoteActor.serverId === null) {
|
2018-04-06 11:54:24 +02:00
|
|
|
logger.error('Receiving request in INBOX by ourselves!', req.body)
|
2021-06-01 16:07:58 +02:00
|
|
|
return res.status(HttpStatusCode.CONFLICT_409).end()
|
2017-11-10 14:34:45 +01:00
|
|
|
}
|
2018-04-06 11:54:24 +02:00
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
2017-11-10 14:34:45 +01:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
activityPubValidator
|
|
|
|
}
|