From 4f49137101a665f6a76bd8159a175a2aa680af96 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 30 Nov 2017 13:37:11 +0100 Subject: Fix req accepts --- server/initializers/constants.ts | 3 +++ server/middlewares/activitypub.ts | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'server') diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 4f63cbb02..e3d779456 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -316,6 +316,8 @@ const CACHE = { } } +const ACCEPT_HEADERS = ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.concat('html', 'application/json') + // --------------------------------------------------------------------------- const OPENGRAPH_AND_OEMBED_COMMENT = '' @@ -336,6 +338,7 @@ if (isTestInstance() === true) { export { API_VERSION, + ACCEPT_HEADERS, BCRYPT_SALT_SIZE, CACHE, CONFIG, diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 485645720..c2ad18195 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts @@ -3,7 +3,7 @@ import { NextFunction, Request, RequestHandler, Response } from 'express' import { ActivityPubSignature } from '../../shared' import { isSignatureVerified, logger } from '../helpers' import { database as db } from '../initializers' -import { ACTIVITY_PUB } from '../initializers/constants' +import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers/constants' import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account' async function checkSignature (req: Request, res: Response, next: NextFunction) { @@ -37,7 +37,8 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { return (req: Request, res: Response, next: NextFunction) => { - if (!req.accepts(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS)) { + const accepted = req.accepts(ACCEPT_HEADERS) + if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) { return next() } -- cgit v1.2.3