2017-11-10 08:34:45 -05:00
|
|
|
import * as express from 'express'
|
2017-12-28 05:16:08 -05:00
|
|
|
import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
2018-02-23 09:09:12 -05:00
|
|
|
import { getServerActor } from '../../../helpers/utils'
|
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2017-11-10 08:34:45 -05:00
|
|
|
|
2018-04-06 05:54:24 -04:00
|
|
|
async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
|
|
|
|
logger.debug('Checking activity pub parameters')
|
2017-11-10 08:34:45 -05:00
|
|
|
|
2018-04-06 05:54:24 -04:00
|
|
|
if (!isRootActivityValid(req.body)) {
|
|
|
|
logger.warn('Incorrect activity parameters.', { activity: req.body })
|
|
|
|
return res.status(400).json({ error: 'Incorrect activity.' })
|
|
|
|
}
|
2018-02-23 09:09:12 -05:00
|
|
|
|
2018-04-06 05:54:24 -04:00
|
|
|
const serverActor = await getServerActor()
|
|
|
|
const remoteActor = res.locals.signature.actor as ActorModel
|
|
|
|
if (serverActor.id === remoteActor.id) {
|
|
|
|
logger.error('Receiving request in INBOX by ourselves!', req.body)
|
|
|
|
return res.status(409).end()
|
2017-11-10 08:34:45 -05:00
|
|
|
}
|
2018-04-06 05:54:24 -04:00
|
|
|
|
|
|
|
return next()
|
|
|
|
}
|
2017-11-10 08:34:45 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
activityPubValidator
|
|
|
|
}
|