]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/middlewares/validators/activitypub/activity.ts
15e8bb07968557053b1645e992468e73b4290c6d
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / activitypub / activity.ts
1 import * as express from 'express'
2 import { body } from 'express-validator/check'
3 import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
4 import { logger } from '../../../helpers/logger'
5 import { getServerActor } from '../../../helpers/utils'
6 import { ActorModel } from '../../../models/activitypub/actor'
7 import { areValidationErrors } from '../utils'
8
9 const activityPubValidator = [
10 body('').custom((value, { req }) => isRootActivityValid(req.body)),
11
12 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
13 logger.debug('Checking activity pub parameters')
14
15 if (areValidationErrors(req, res)) return
16
17 const serverActor = await getServerActor()
18 const remoteActor = res.locals.signature.actor as ActorModel
19 if (serverActor.id === remoteActor.id) {
20 logger.error('Receiving request in INBOX by ourselves!', req.body)
21 return res.sendStatus(409)
22 }
23
24 return next()
25 }
26 ]
27
28 // ---------------------------------------------------------------------------
29
30 export {
31 activityPubValidator
32 }