From c61144abfcc21fe1e271c765643c4e70bfa124e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Thu, 15 Jun 2023 17:09:36 +0200 Subject: [PATCH] Improve privacy with hash of the body --- api/source/redis-cache.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/source/redis-cache.ts b/api/source/redis-cache.ts index adb30b113..6f0600480 100644 --- a/api/source/redis-cache.ts +++ b/api/source/redis-cache.ts @@ -1,3 +1,5 @@ +import { createHash } from 'crypto' + import Router from '@koa/router' import IORedis from 'ioredis' import IORedisMock from 'ioredis-mock' @@ -27,7 +29,10 @@ export const redisCacheMiddleware = () => { return } - const cacheKey = JSON.stringify(ctx.request.body) + const cacheKey = createHash('sha1') + .update(JSON.stringify(ctx.request.body)) + .digest('base64') + const cachedResponse = await redis.get(cacheKey) if (cachedResponse) { ctx.body = JSON.parse(cachedResponse) as unknown