Security: Prototype pollution via untrusted YAML user-config keys#1494
Conversation
parseUserConfig() copies YAML group names directly into a plain object (`ret[groupKey] = groupValue`). A malicious userscript can use special keys such as `__proto__`, `constructor`, or `prototype` to mutate object prototypes or interfere with later merges/lookups. Because this parser handles untrusted script metadata, this can become a cross-script integrity issue. Affected files: yaml.ts Signed-off-by: Quang Do <github@qdzsh.dev>
|
Then why not change it to Map? Actually the ScriptCat coding was really poorly designed. But yeah, the proposed change is good to have. |
| } | ||
| // 验证是否符合分组规范:group -> config -> properties | ||
| for (const [groupKey, groupValue] of Object.entries(obj)) { | ||
| if (["__proto__", "constructor", "prototype"].includes(groupKey)) { |
There was a problem hiding this comment.
| if (["__proto__", "constructor", "prototype"].includes(groupKey)) { | |
| if (Reflect.has(Object.prototype, groupKey)) { |
This should be better. This covers valueOf and toString, etc.
prototype is the inherited property for Function not Object, so it is okay. Since it is not a class function, adding the key prototype does not have any negative impact (pollution).
| // 验证是否符合分组规范:group -> config -> properties | ||
| for (const [groupKey, groupValue] of Object.entries(obj)) { | ||
| if (["__proto__", "constructor", "prototype"].includes(groupKey)) { | ||
| throw new Error(`UserConfig group "${groupKey}" is not a valid object.`); |
There was a problem hiding this comment.
| throw new Error(`UserConfig group "${groupKey}" is not a valid object.`); | |
| throw new Error(`UserConfig key "${groupKey}" is not valid.`); |
The Error message here was wrong.
- Reject any key inherited from Object.prototype (covers valueOf, toString, etc.) instead of a hardcoded __proto__/constructor/prototype list. - Correct the error message to reference the invalid key, not 'object'.
|
Good points, thanks for the careful review.
On |
cyfung1031
left a comment
There was a problem hiding this comment.
@CodFrm please final check and merge.
|
Thanks! |
Summary
Security: Prototype pollution via untrusted YAML user-config keys
Problem
Severity:
Medium| File:src/pkg/utils/yaml.ts:L12parseUserConfig() copies YAML group names directly into a plain object (
ret[groupKey] = groupValue). A malicious userscript can use special keys such as__proto__,constructor, orprototypeto mutate object prototypes or interfere with later merges/lookups. Because this parser handles untrusted script metadata, this can become a cross-script integrity issue.Solution
Create the result object with
Object.create(null)and reject dangerous keys (__proto__,constructor,prototype) before assignment. Prefer a schema-validated structure instead of copying arbitrary keys into a plain object.Changes
src/pkg/utils/yaml.ts(modified)Testing