X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Factivitypub.ts;h=ce94a2129f84f56c275d3cfaf3e1c965b816a295;hb=606bcaf29eca4c37f0a6db718f7b83529ed88496;hp=d00594059a40748126616d1c7d9e7bd67fb5e3ef;hpb=797d05bdd99b63104522051d0f61f1e0f003e780;p=github%2FChocobozzz%2FPeerTube.git 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 }