Conversation
| for (const validationError of invalidRecordError.validationErrors) { | ||
| if (invalidRecordError.modelApiIdentifier) { | ||
| result[invalidRecordError.modelApiIdentifier] ??= {}; | ||
| result[invalidRecordError.modelApiIdentifier][validationError.apiIdentifier] = { message: validationError.message }; |
Check warning
Code scanning / CodeQL
Prototype-polluting assignment Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 months ago
To fix this, we should prevent dangerous values ('__proto__', 'constructor', 'prototype') from ever being used as keys on plain objects. The best way, without changing existing functionality, is to add a check when assigning to result[invalidRecordError.modelApiIdentifier] (line 733) and, optionally, result[validationError.apiIdentifier] (line 735), to ensure that neither key is one of the dangerous reserved names. If encountered, we should skip that assignment and possibly log or collect as a separate error. This fix should be implemented directly in the loop in the formatErrorMessages function. No extra dependencies are required; the fix is a conditional check.
| @@ -729,10 +729,19 @@ | ||
| const invalidRecordError = error as InvalidRecordError; | ||
| for (const validationError of invalidRecordError.validationErrors) { | ||
| if (invalidRecordError.modelApiIdentifier) { | ||
| result[invalidRecordError.modelApiIdentifier] ??= {}; | ||
| result[invalidRecordError.modelApiIdentifier][validationError.apiIdentifier] = { message: validationError.message }; | ||
| const key = invalidRecordError.modelApiIdentifier; | ||
| if (key !== "__proto__" && key !== "constructor" && key !== "prototype") { | ||
| result[key] ??= {}; | ||
| const fieldKey = validationError.apiIdentifier; | ||
| if (fieldKey !== "__proto__" && fieldKey !== "constructor" && fieldKey !== "prototype") { | ||
| result[key][fieldKey] = { message: validationError.message }; | ||
| } | ||
| } | ||
| } else { | ||
| result[validationError.apiIdentifier] = { message: validationError.message }; | ||
| const key = validationError.apiIdentifier; | ||
| if (key !== "__proto__" && key !== "constructor" && key !== "prototype") { | ||
| result[key] = { message: validationError.message }; | ||
| } | ||
| } | ||
| } | ||
| } else { |
398b20f to
73ecbd2
Compare
73ecbd2 to
e716377
Compare
... a description that explains what, why, and how ...
PR Checklist