aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/secure.ts11
1 files changed, 7 insertions, 4 deletions
diff --git a/server/middlewares/secure.ts b/server/middlewares/secure.ts
index f58bea734..f7424c9c3 100644
--- a/server/middlewares/secure.ts
+++ b/server/middlewares/secure.ts
@@ -6,9 +6,12 @@ import {
6 logger, 6 logger,
7 checkSignature as peertubeCryptoCheckSignature 7 checkSignature as peertubeCryptoCheckSignature
8} from '../helpers' 8} from '../helpers'
9import { PodSignature } from '../../shared'
9 10
10function checkSignature (req: express.Request, res: express.Response, next: express.NextFunction) { 11function checkSignature (req: express.Request, res: express.Response, next: express.NextFunction) {
11 const host = req.body.signature.host 12 const signatureObject: PodSignature = req.body.signature
13 const host = signatureObject.host
14
12 db.Pod.loadByHost(host) 15 db.Pod.loadByHost(host)
13 .then(pod => { 16 .then(pod => {
14 if (pod === null) { 17 if (pod === null) {
@@ -27,7 +30,7 @@ function checkSignature (req: express.Request, res: express.Response, next: expr
27 signatureShouldBe = host 30 signatureShouldBe = host
28 } 31 }
29 32
30 const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, req.body.signature.signature) 33 const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, signatureObject.signature)
31 34
32 if (signatureOk === true) { 35 if (signatureOk === true) {
33 res.locals.secure = { 36 res.locals.secure = {
@@ -37,11 +40,11 @@ function checkSignature (req: express.Request, res: express.Response, next: expr
37 return next() 40 return next()
38 } 41 }
39 42
40 logger.error('Signature is not okay in body for %s.', req.body.signature.host) 43 logger.error('Signature is not okay in body for %s.', signatureObject.host)
41 return res.sendStatus(403) 44 return res.sendStatus(403)
42 }) 45 })
43 .catch(err => { 46 .catch(err => {
44 logger.error('Cannot get signed host in body.', { error: err.stack, signature: req.body.signature.signature }) 47 logger.error('Cannot get signed host in body.', { error: err.stack, signature: signatureObject.signature })
45 return res.sendStatus(500) 48 return res.sendStatus(500)
46 }) 49 })
47} 50}