aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-03-19 09:34:29 +0100
committerChocobozzz <me@florianbigard.com>2019-03-19 09:34:29 +0100
commite65c0c5b1fab9c3d93f51721b2458cf5cf471f20 (patch)
treefbdb8fef45aedf8fcdfbf676f8e5418244901503 /server/middlewares
parent0f6acda11681de90d38dd18669863c6e270851ee (diff)
downloadPeerTube-e65c0c5b1fab9c3d93f51721b2458cf5cf471f20.tar.gz
PeerTube-e65c0c5b1fab9c3d93f51721b2458cf5cf471f20.tar.zst
PeerTube-e65c0c5b1fab9c3d93f51721b2458cf5cf471f20.zip
Better AP route checker
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/activitypub.ts26
1 files changed, 9 insertions, 17 deletions
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts
index 01e5dd24e..5fa10cbfd 100644
--- a/server/middlewares/activitypub.ts
+++ b/server/middlewares/activitypub.ts
@@ -1,5 +1,4 @@
1import { eachSeries } from 'async' 1import { NextFunction, Request, Response } from 'express'
2import { NextFunction, Request, RequestHandler, Response } from 'express'
3import { ActivityPubSignature } from '../../shared' 2import { ActivityPubSignature } from '../../shared'
4import { logger } from '../helpers/logger' 3import { logger } from '../helpers/logger'
5import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto' 4import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../helpers/peertube-crypto'
@@ -30,23 +29,16 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
30 } 29 }
31} 30}
32 31
33function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { 32function executeIfActivityPub (req: Request, res: Response, next: NextFunction) {
34 return (req: Request, res: Response, next: NextFunction) => { 33 const accepted = req.accepts(ACCEPT_HEADERS)
35 const accepted = req.accepts(ACCEPT_HEADERS) 34 if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) {
36 if (accepted === false || ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS.indexOf(accepted) === -1) { 35 // Bypass this route
37 return next() 36 return next('route')
38 } 37 }
39 38
40 logger.debug('ActivityPub request for %s.', req.url) 39 logger.debug('ActivityPub request for %s.', req.url)
41 40
42 if (Array.isArray(fun) === true) { 41 return next()
43 return eachSeries(fun as RequestHandler[], (f, cb) => {
44 f(req, res, cb)
45 }, next)
46 }
47
48 return (fun as RequestHandler)(req, res, next)
49 }
50} 42}
51 43
52// --------------------------------------------------------------------------- 44// ---------------------------------------------------------------------------