Skip to content

Commit 4d634ea

Browse files
committed
Update isSafeDynamicKey and JSDoc for readability, add prototype to blocklist
1 parent 64f0b6d commit 4d634ea

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/controller-utils/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = merge(baseConfig, {
1919
global: {
2020
branches: 77.65,
2121
functions: 81.25,
22-
lines: 86.87,
22+
lines: 86.53,
2323
statements: 86.74,
2424
},
2525
},

packages/controller-utils/src/util.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@ import { MAX_SAFE_CHAIN_ID } from './constants';
1616

1717
const TIMEOUT_ERROR = new Error('timeout');
1818

19-
const PROTOTYPE_POLLUTION_BLOCKLIST = ['__proto__', 'constructor'] as const;
19+
const PROTOTYPE_POLLUTION_BLOCKLIST = [
20+
'__proto__',
21+
'constructor',
22+
'prototype',
23+
] as const;
2024

2125
/**
22-
* Checks whether a dynamic string used as an object property key
23-
* could be used in a prototype pollution attack.
26+
* Checks whether a dynamic property key could be used in
27+
* a [prototype pollution attack](https://portswigger.net/web-security/prototype-pollution).
2428
*
25-
* @param key - The dynamic key to check for safety.
26-
* @returns Whether the given dyanmic key is safe to use.
29+
* @param key - The dynamic key to validate.
30+
* @returns Whether the given dynamic key is safe to use.
2731
*/
2832
export function isSafeDynamicKey(key: string): boolean {
29-
return PROTOTYPE_POLLUTION_BLOCKLIST.every((badInput) => key !== badInput);
33+
return !PROTOTYPE_POLLUTION_BLOCKLIST.some(
34+
(blockedKey) => key === blockedKey,
35+
);
3036
}
3137

3238
/**

0 commit comments

Comments
 (0)