-
Notifications
You must be signed in to change notification settings - Fork 1
Potential fix for code scanning alert no. 27: Prototype-polluting assignment #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,8 +207,12 @@ | |
| ): void { | ||
| const BLOCKED_KEYS = new Set(["__proto__", "constructor", "prototype"]); | ||
| const keys = path.split("."); | ||
| const lastKey = keys[keys.length - 1]; | ||
|
Check warning on line 210 in src/utils/helpers/DiffUtils.ts
|
||
|
|
||
| if (keys.some((k) => BLOCKED_KEYS.has(k))) return; | ||
| // Reject empty paths or any segment that could lead to prototype pollution | ||
| if (!lastKey || keys.some((k) => BLOCKED_KEYS.has(k))) { | ||
| return; | ||
| } | ||
|
|
||
| let current = obj; | ||
|
|
||
|
|
@@ -220,7 +224,7 @@ | |
| current = current[key] as Record<string, unknown>; | ||
| } | ||
|
|
||
| current[keys.at(-1)!] = value; | ||
| current[lastKey] = value; | ||
Check warningCode scanning / CodeQL Prototype-polluting assignment Medium
This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input Error loading related location Loading Copilot AutofixAI 6 days ago Copilot could not generate an autofix suggestion Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support. |
||
| } | ||
|
|
||
| /** | ||
|
|
||
Check warning
Code scanning / CodeQL
Prototype-polluting function Medium
Copilot Autofix
AI 6 days ago
General approach
To harden against prototype pollution, the deep assignment function must:
Object.prototype).Best concrete fix in this file
Within
setNestedValue:if (!(key in current))with a check that only considers own properties, e.g.Object.prototype.hasOwnProperty.call(current, key). This prevents the code from following or relying on inherited properties that might be polluted.__proto__,constructor, andprototypeand the use ofObject.create(null)for new intermediate objects.Object.prototype.hasOwnPropertyis globally available.Specific change
In
src/utils/helpers/DiffUtils.ts, insetNestedValue, adjust the loop overkeysso that:becomes:
No other changes are needed.