Skip to content
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

Fix prototype poisoning #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Changelog

# 8.9.1 (25.10.2024)

Fixed prototype poisoning vulnerability in `deepClone`.


## 8.9.0 (31.05.2023)

Ensured Node.js 18 support.

`deepClone` typings have become more strict due to the goal to remove `any`.
Thus, this helper does not expect `any` anymore.
Instead it expects `boolean | number | bigint | string | undefined | null | Date`, or array of them, or an object with values of these types.
The array and theh object may be nested.
Instead, it expects `boolean | number | bigint | string | undefined | null | Date`, or array of them, or an object with values of these types.
The array and the object may be nested.

We believe that this is not a breaking change, because this change makes types more correct and more close to the implementation.
It means that if your code does not satisfy the types of `deepClone`, you're probably not using it right.
Expand Down Expand Up @@ -177,7 +182,7 @@ Removed `deepFlatten` & `getHostnameFromString`.

Added CommonJS version for scripts to make it possible to use them in Node.js env.

To make it work we had to change [isMobile](./lib/is-mobile.js) notation. For now this helpers exports
To make it work we had to change [isMobile](./lib/is-mobile.js) notation. For now these helpers export
a function that returns value, not the value itself.


Expand Down
15 changes: 14 additions & 1 deletion lib/deep-clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@ function deepClone(obj: DeepCloneSupportedType): DeepCloneSupportedType {
const copy: typeof obj = {};

Object.keys(obj).forEach(key => {
copy[key] = deepClone(obj[key]);
const value = deepClone(obj[key]);

// The __proto__ property has a special meaning in JavaScript. So, to prevent prototype poisoning,
// we restrict direct assignment to this property.
if (key === '__proto__') {
Object.defineProperty(copy, key, {
configurable: true,
enumerable: true,
value,
writable: true,
});
} else {
copy[key] = value;
}
});

return copy;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@funboxteam/diamonds",
"version": "8.9.0",
"version": "8.9.1",
"description": "A shiny pile of typed JS helpers for everyday use",
"scripts": {
"build": "npm run clean && npm run build-esm-and-types && npm run build-cjs",
Expand Down
Loading