Arbitrary code execution from cookie config. If dynamic cookies are enabled (ie there exists a schema for cookies), the cookie config is injected into the compiled route without first being sanitised.
Availability of this exploit is generally low, as it requires write access to either the Elysia app's source code (in which case the vulnerability is meaningless) or write access to the cookie config (perhaps where it is assumed to be provisioned by the environment).
However when combined with GHSA-hxj9-33pp-j2cc, this vulnerability allows for a full RCE chain.
Impact
- aot enabled (default)
- cookie schema passed to route
- Cookie config controllable eg. via env
Example of vulnerable code
new Elysia({
cookie: {
secrets: `' + console.log('pwned from secrets') + '`
},
})
.get("/", () => "hello world", {
cookie: t.Cookie({
foo: t.Any(),
}),
})
POC: https://github.com/sportshead/elysia-poc
Patches
Patched by 1.4.17 (elysiajs/elysia#1564)
Reference commit:
Workarounds
Sanitize cookie-related env input
const overrideUnsafeQuote = (value: string) =>
// '`' + value + '`'
'`' + value.replace(/'/g, '\\`').replace(/\${/g, '$\\{') + '`'
References
Arbitrary code execution from cookie config. If dynamic cookies are enabled (ie there exists a schema for cookies), the cookie config is injected into the compiled route without first being sanitised.
Availability of this exploit is generally low, as it requires write access to either the Elysia app's source code (in which case the vulnerability is meaningless) or write access to the cookie config (perhaps where it is assumed to be provisioned by the environment).
However when combined with GHSA-hxj9-33pp-j2cc, this vulnerability allows for a full RCE chain.
Impact
Example of vulnerable code
POC: https://github.com/sportshead/elysia-poc
Patches
Patched by 1.4.17 (elysiajs/elysia#1564)
Reference commit:
Workarounds
Sanitize cookie-related env input
References