Valid Object keys and Ensure that serializable classes are unserialized with 'C' #305
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.
Motivation
This library was used in a
Web Exploitationchallenge for the ECSC 2025 qualifiers of Team Greece and Team Cyprus. Two bugs were found:Otype and manual setting of key-value pairs, allowing pollution of the__proto__attribute.toStringthat could be triggered by requesting the unserialization of an object with a class instance as a key, which would invoketoStringautomatically.Why these matter
unserializedmethod they implemented. A user should not be allowed to set the__proto__attribute during unserialization, as it can lead to unexpected behavior or security issues.What this changes
numberorstring, and not equal to__proto__.O:notserializable-class.Thoughts
serialize.ts,Mapobjects are currently converted into plain key-value objects. This causes data loss becauseMapsupports dynamic, non-string keys, but the serialization process coerces them into static string keys.Mapserialization is indeed required, it would be better to implement a custom serialization and unserialization method that preserves key types. For example, by reconstructing theMapusing.set()during unserialization.