Описание
sveltekit-superforms has Prototype Pollution in parseFormData function of formData.js
Summary
sveltekit-superforms v2.27.3 and prior are susceptible to a prototype pollution vulnerability within the parseFormData function of formData.js. An attacker can inject string and array properties into Object.prototype, leading to denial of service, type confusion, and potential remote code execution in downstream applications that rely on polluted objects.
Details
Superforms is a SvelteKit form library for server and client form validation. Under normal operation, form validation is performed by calling the the superValidate function, with the submitted form data and a form schema as arguments:
Within the superValidate function, a call is made to parseRequest in order to parse the user's input. parseRequest then calls into parseFormData, which in turn looks for the presence of __superform_json in the form parameters. If __superform_json is present, the following snippet is executed:
This snippet deserializes JSON input within the __superform_json, and then performs a nested assignment into the deserialized object using values from form parameters beginning with __superform_file_ and __superform_files_. Since both the target property and value of the assignment is controlled by user input, an attacker can use this to pollute the base object prototype. For example, the following request will pollute Object.prototype.toString, which leads to a persistent denial of service in many applications:
PoC
The following PoC demonstrates how this vulnerability can be escalated to remote code execution in the presence of suitable gadgets. The example app represents a typical application signup route, using the popular nodemailer library (5 million weekly downloads from npm).
routes/signup/schema.ts:
routes/signup/+page.server.ts:
The following Python script then pollutes the base object prototype in order to achieve RCE.
In addition to nodemailer, the Language-Based Security group at KTH Royal Institute of Technology also compiles gadgets in many other popular libraries and runtimes, which can be used together with this vulnerability.
Impact
Attackers can inject string and array properties into Object.prototype. This has a high probability of leading to denial of service and type confusion, with potential escalation to other impacts such as remote code execution, depending on the presence of reliable gadgets.
Пакеты
sveltekit-superforms
<= 2.27.3
2.27.4
Связанные уязвимости
sveltekit-superforms makes SvelteKit forms a pleasure to use. sveltekit-superforms v2.27.3 and prior are susceptible to a prototype pollution vulnerability within the parseFormData function of formData.js. An attacker can inject string and array properties into Object.prototype, leading to denial of service, type confusion, and potential remote code execution in downstream applications that rely on polluted objects. This vulnerability is fixed in 2.27.4.