Improve privacy with hash of the body

pull/2723/head
Jérémy Rialland 2023-06-15 17:09:36 +02:00 committed by Jérémy Rialland
parent 23bebf94d4
commit c61144abfc
1 changed files with 6 additions and 1 deletions

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