From 2d53be0267acc49cda46707b885096193a1f4e9c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 7 Dec 2020 14:32:36 +0100 Subject: replace numbers with typed http status codes (#3409) --- server/middlewares/activitypub.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'server/middlewares/activitypub.ts') diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index d00594059..ce94a2129 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts @@ -7,6 +7,7 @@ import { getOrCreateActorAndServerAndModel } from '../lib/activitypub/actor' import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger' import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' import { getAPId } from '@server/helpers/activitypub' +import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' async function checkSignature (req: Request, res: Response, next: NextFunction) { try { @@ -28,11 +29,11 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) const activity: ActivityDelete = req.body if (isActorDeleteActivityValid(activity) && activity.object === activity.actor) { logger.debug('Handling signature error on actor delete activity', { err }) - return res.sendStatus(204) + return res.sendStatus(HttpStatusCode.NO_CONTENT_204) } logger.warn('Error in ActivityPub signature checker.', { err }) - return res.sendStatus(403) + return res.sendStatus(HttpStatusCode.FORBIDDEN_403) } } @@ -70,13 +71,13 @@ async function checkHttpSignature (req: Request, res: Response) { } catch (err) { logger.warn('Invalid signature because of exception in signature parser', { reqBody: req.body, err }) - res.status(403).json({ error: err.message }) + res.status(HttpStatusCode.FORBIDDEN_403).json({ error: err.message }) return false } const keyId = parsed.keyId if (!keyId) { - res.sendStatus(403) + res.sendStatus(HttpStatusCode.FORBIDDEN_403) return false } @@ -93,7 +94,7 @@ async function checkHttpSignature (req: Request, res: Response) { if (verified !== true) { logger.warn('Signature from %s is invalid', actorUrl, { parsed }) - res.sendStatus(403) + res.sendStatus(HttpStatusCode.FORBIDDEN_403) return false } @@ -106,7 +107,7 @@ async function checkJsonLDSignature (req: Request, res: Response) { const signatureObject: ActivityPubSignature = req.body.signature if (!signatureObject || !signatureObject.creator) { - res.sendStatus(403) + res.sendStatus(HttpStatusCode.FORBIDDEN_403) return false } @@ -120,7 +121,7 @@ async function checkJsonLDSignature (req: Request, res: Response) { if (verified !== true) { logger.warn('Signature not verified.', req.body) - res.sendStatus(403) + res.sendStatus(HttpStatusCode.FORBIDDEN_403) return false } -- cgit v1.2.3