activity.ts 963 B

12345678910111213141516171819202122232425262728
  1. import * as express from 'express'
  2. import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
  3. import { logger } from '../../../helpers/logger'
  4. import { getServerActor } from '../../../helpers/utils'
  5. async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
  6. logger.debug('Checking activity pub parameters')
  7. if (!isRootActivityValid(req.body)) {
  8. logger.warn('Incorrect activity parameters.', { activity: req.body })
  9. return res.status(400).json({ error: 'Incorrect activity.' })
  10. }
  11. const serverActor = await getServerActor()
  12. const remoteActor = res.locals.signature.actor
  13. if (serverActor.id === remoteActor.id) {
  14. logger.error('Receiving request in INBOX by ourselves!', req.body)
  15. return res.status(409).end()
  16. }
  17. return next()
  18. }
  19. // ---------------------------------------------------------------------------
  20. export {
  21. activityPubValidator
  22. }