fix Prototype-polluting assignment ('Code Injection') #20895
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.
ember.js/packages/@ember/engine/index.ts
Line 503 in 6c60105
fix the issue validate the
bucketName
parameter to ensure it cannot be set to a prototype-polluting value like__proto__
,constructor
, orprototype
. This can be achieved by adding a runtime check that explicitly rejects such values. This approach ensures that even if the type system is bypassed, the code remains secure.The fix involves:
bucketName
at the beginning of thebuildInitializerMethod
function.bucketName
is set to a disallowed value.Most JavaScript objects inherit the properties of the built-in
Object.prototype
object. Prototype pollution is a type of vulnerability in which an attacker is able to modify Object.prototype. Since most objects inherit from the compromisedObject.prototype
object, the attacker can use this to tamper with the application logic, and often escalate to remote code execution or cross-site scripting. One way to cause prototype pollution is by modifying an object obtained via a user-controlled property name. Most objects have a special__proto__
property that refers toObject.prototype
. An attacker can abuse this special property to trick the application into performing unintended modifications ofObject.prototype
.POC
the untrusted value
req.params.id
is used as the property namereq.session.todos[id]
. If a malicious user passes in the ID value__proto__
, the variableitems
will then refer toObject.prototype
. Finally, the modification ofitems
then allows the attacker to inject arbitrary properties ontoObject.prototype
.One way to fix this is to use Map objects to associate key/value pairs instead of regular objects, as shown below:
Another way to fix it is to prevent the
__proto__
property from being used as a key, as shown below:References
Object.prototype.proto
Map
CWE-78
CWE-79
CWE-94
CWE-400
CWE-471
CWE-915