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