1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-03-11 06:25:05 +00:00

Improve privacy with hash of the body

This commit is contained in:
Jérémy Rialland 2023-06-15 17:09:36 +02:00 committed by Jérémy Rialland
parent 23bebf94d4
commit c61144abfc

View file

@ -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