Prototype pollution vulnerability in mergeDeep after merging results of two standard schema validations with the same key. Due to the ordering of merging, there must be an any type that is set as a standalone guard, to allow for the __proto__ prop to be merged.
When combined with GHSA-8vch-m3f4-q8jf this allows for a full RCE by an attacker.
Impact
Routes with more than 2 standalone schema validation, eg. zod
Example vulnerable code:
import { Elysia } from "elysia"
import * as z from "zod"
const app = new Elysia()
.guard({
schema: "standalone",
body: z.object({
data: z.any()
})
})
.post("/", ({ body }) => ({ body, win: {}.foo }), {
body: z.object({
data: z.object({
messageId: z.string("pollute-me"),
})
})
})
Patches
Patched by 1.4.17 (elysiajs/elysia#1564)
Reference commit:
Workarounds
Remove __proto__ key from body
Example plugin for removing __proto__ from body
new Elysia()
.onTransform(({ body, headers }) => {
if (headers['content-type'] === 'application/json')
return JSON.parse(JSON.stringify(body), (k, v) => {
if (k === '__proto__') return
return v
})
})
References
Prototype pollution vulnerability in
mergeDeepafter merging results of two standard schema validations with the same key. Due to the ordering of merging, there must be ananytype that is set as astandaloneguard, to allow for the__proto__prop to be merged.When combined with GHSA-8vch-m3f4-q8jf this allows for a full RCE by an attacker.
Impact
Routes with more than 2 standalone schema validation, eg. zod
Example vulnerable code:
Patches
Patched by 1.4.17 (elysiajs/elysia#1564)
Reference commit:
Workarounds
Remove
__proto__key from bodyExample plugin for removing
__proto__from bodyReferences