]>
Commit | Line | Data |
---|---|---|
0d0e8dd0 | 1 | import * as express from 'express' |
da854ddd C |
2 | import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' |
3 | import { logger } from '../../../helpers/logger' | |
8dc8a34e | 4 | import { getServerActor } from '@server/models/application/application' |
2d53be02 | 5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
0d0e8dd0 | 6 | |
ee28cdf1 C |
7 | async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
8 | logger.debug('Checking activity pub parameters') | |
0d0e8dd0 | 9 | |
ee28cdf1 C |
10 | if (!isRootActivityValid(req.body)) { |
11 | logger.warn('Incorrect activity parameters.', { activity: req.body }) | |
2d53be02 RK |
12 | return res.status(HttpStatusCode.BAD_REQUEST_400) |
13 | .json({ error: 'Incorrect activity.' }) | |
ee28cdf1 | 14 | } |
285fe7c9 | 15 | |
ee28cdf1 | 16 | const serverActor = await getServerActor() |
dae86118 | 17 | const remoteActor = res.locals.signature.actor |
3933a127 | 18 | if (serverActor.id === remoteActor.id || remoteActor.serverId === null) { |
ee28cdf1 | 19 | logger.error('Receiving request in INBOX by ourselves!', req.body) |
2d53be02 RK |
20 | return res.status(HttpStatusCode.CONFLICT_409) |
21 | .end() | |
0d0e8dd0 | 22 | } |
ee28cdf1 C |
23 | |
24 | return next() | |
25 | } | |
0d0e8dd0 C |
26 | |
27 | // --------------------------------------------------------------------------- | |
28 | ||
29 | export { | |
30 | activityPubValidator | |
31 | } |