Valibot: record() issue paths can make flatten() throw for inherited Object property names
valibot 1.4.1 can throw a TypeError inside its flatten() helper when validation issues contain attacker-controlled object keys such as toString, valueOf, or hasOwnProperty.
The issue is reachable through normal record() validation. record() intentionally filters __proto__, prototype, and constructor, but it still accepts other own keys that collide with inherited Object.prototype properties. If the record key schema or value schema rejects such an entry, Valibot creates an issue path containing that key. Passing the resulting issues to Valibot's documented flatten() helper causes flatErrors.nested[dotPath] to resolve to the inherited method instead of an own error array, and the helper calls .push(...) on that function.
This is not a global prototype pollution issue. The impact is availability/error handling: applications that validate user-controlled objects with record() and flatten validation errors for API responses can crash the request path with a TypeError instead of returning structured validation errors.
valibot1.4.1open-circle/valibot9bb6617record() uses _isValidObjectKey() before validating record entries. The helper blocks the three classic prototype pollution keys:
key !== '__proto__' &&
key !== 'prototype' &&
key !== 'constructor'
It does not block other inherited Object.prototype names such as toString, valueOf, and hasOwnProperty. These remain valid own JSON object keys and can appear in issue paths when either the record key schema or value schema rejects the entry.
flatten() then creates nested error storage with an ordinary object:
flatErrors.nested = {};
For a dot path such as toString, this check reads the inherited Object.prototype.toString function:
if (flatErrors.nested![dotPath]) {
flatErrors.nested![dotPath]!.push(issue.message);
}
Because the inherited function is truthy, flatten() calls .push(...) on a function and throws TypeError: flatErrors.nested[dotPath].push is not a function.
A remote attacker can trigger this if an application:
v.record(...);toString;flatten(result.issues) helper to prepare validation errors.This is a common pattern in API/form validation: safeParse() collects issues and flatten() converts them into response-friendly error objects. Instead of a validation response, the request can hit an unexpected exception path.
The same root cause can also affect manually constructed issues or other schemas that place inherited Object property names into dot paths. I am reporting the record() path because it uses only public Valibot APIs and attacker-controlled JSON keys.
Run in a disposable directory:
npm install valibot@1.4.1
node poc_record_flatten_inherited_key_dos.mjs
Minimal example:
import * as v from 'valibot';
const schema = v.record(v.string(), v.number());
const input = JSON.parse('{"toString":"not-a-number"}');
const result = v.safeParse(schema, input);
console.log(result.success); // false
console.log(result.issues[0].path.map((item) => item.key)); // ["toString"]
v.flatten(result.issues); // TypeError
Observed output from valibot@1.4.1:
{
"name": "record value schema rejects attacker-controlled value",
"key": "toString",
"success": false,
"issueCount": 1,
"firstPath": ["toString"],
"firstMessage": "Invalid type: Expected number but received \"not-a-number\"",
"flattened": {
"ok": false,
"exception": "TypeError",
"message": "flatErrors.nested[dotPath].push is not a function"
}
}
The local PoC also reproduces the same exception for valueOf, hasOwnProperty, isPrototypeOf, propertyIsEnumerable, and toLocaleString. A control case with an ordinary key produces normal flattened errors.
valibot release is 1.4.1 and maps to open-circle/valibot.gh api repos/open-circle/valibot/private-vulnerability-reporting returned {"enabled":true}.npm audit for a clean project containing only valibot@1.4.1 returned no vulnerabilities.1.2.0.valibot 1.4.1 returned no vulnerabilities.flatten toString, flatten hasOwnProperty, record toString, __proto__, constructor, and prototype pollution did not find a matching disclosure of this record() issue-path / flatten() exception.open-circle/valibot#67 added prototype pollution mitigation for record() by blacklisting __proto__, prototype, and constructor; it does not cover flatten() collisions with other inherited property names. open-circle/valibot#1429 is an open plain-object / record() type semantics PR and does not disclose this flatten() exception behavior.Use null-prototype containers for flat error maps and/or perform own-property checks before appending:
flatErrors.nested as Object.create(null).Object.prototype.hasOwnProperty.call(flatErrors.nested, dotPath) rather than truthiness.getDotPath() / flatten(), including inherited Object property names.flatten() with paths toString, valueOf, hasOwnProperty, __proto__, prototype, and constructor.왜 이 VPI인가 (설명가능 · 실험적)
VPI 산정 기준
| 영향도(기본값(정보 없음)) | 55.00 |
| 악용 신호(추가 악용신호 없음) | ×1.00 |
| VPI | 55.00 |
VPI 공식 vpi-v1 기준