Potential fix for code scanning alert no. 1: Prototype-polluting function#8
Closed
NullSablex wants to merge 1 commit intomasterfrom
Closed
Potential fix for code scanning alert no. 1: Prototype-polluting function#8NullSablex wants to merge 1 commit intomasterfrom
NullSablex wants to merge 1 commit intomasterfrom
Conversation
…tion Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/NullSablex/PawnPro/security/code-scanning/1
In general, prototype pollution in deep-assignment functions is mitigated by (a) blocking dangerous key names such as
__proto__,constructor, andprototype, and (b) only traversing / extending objects that are verified to be safe (typically, “plain objects”), refusing to follow a chain into anything else. This ensures an attacker cannot redirect the traversal intoObject.prototypeor another sensitive object and then write properties on it.For this specific
setKeyimplementation insrc/core/config.ts, we already have step (a): aforbiddenlist checked against every component ofdotPath. The best additional safeguard, without changing existing functionality, is to ensure thatcursoris always a plain object during the traversal and before the final write. We can do this by:if (!isPlainObject(cursor[key])) { cursor[key] = {}; }with logic that:cursor[key]exists but is not a plain object, we overwrite it with a new empty plain object rather than traversing into it.cursorto the newly created or existing plain object.cursor[parts[parts.length - 1]] = value;), verifying thatcursoritself is a plain object. If not, we either replace it safely or throw an error. To preserve current behavior (which is to always make the path writable), the least disruptive approach is to ensure during the loop thatcursoris always a plain object; that makes an extra check before the final write unnecessary.parts.some(...)check already covers it globally, so no extra logic is actually needed there.We should reuse the existing
isPlainObjecthelper from this file and not introduce new dependencies. The edits will all be within thesetKeymethod: around lines 146–154. No new imports are required; no external packages are necessary.Suggested fixes powered by Copilot Autofix. Review carefully before merging.