You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following pattern for creating endpoints is common, and may lead to a CSRF attack, provided it is a GET/POST handler, and only requires strings, or arrays of strings in the body.
The following is an example of what a vulnerable handler might look like:
exportdefaultdefineEventHandler(asynce=>{// Authenticated endpointawaitVerifyAuthenticationHere(e)// Assumption here that content-type is validated.constbody=awaitreadBody(e)// Optional validation here ...// Some sensitive action that relies upon bodyif(body.action==="update"){awaitUpdateUser(body.new_username)}})
Describe the bug
The readBody utility will accept multiple different content type's, including application/jsonapplication/x-www-form-urlencoded and text/plain.
There is an assumption that the readBody handler will only emit an object for the application/json content type, however, this also occurs for application/x-www-form-urlencoded.
This has implications for security as cross-site requests can be sent when using the application/x-www-form-urlencoded, but they cannot be sent when using application/json.
If readBody is called without appropriate CSRF protections, or without verifying the content-type header, the application may be at risk of a CSRF attack.
Additional context
The following handler is an example of how an attacker could exploit one of these issues:
Environment
N/A
Reproduction
The following pattern for creating endpoints is common, and may lead to a CSRF attack, provided it is a
GET
/POST
handler, and only requires strings, or arrays of strings in the body.The following is an example of what a vulnerable handler might look like:
Describe the bug
The
readBody
utility will accept multiple different content type's, includingapplication/json
application/x-www-form-urlencoded
andtext/plain
.There is an assumption that the
readBody
handler will only emit an object for theapplication/json
content type, however, this also occurs forapplication/x-www-form-urlencoded
.This has implications for security as cross-site requests can be sent when using the
application/x-www-form-urlencoded
, but they cannot be sent when usingapplication/json
.If
readBody
is called without appropriate CSRF protections, or without verifying thecontent-type
header, the application may be at risk of a CSRF attack.Additional context
The following handler is an example of how an attacker could exploit one of these issues:
Logs
No response
The text was updated successfully, but these errors were encountered: