Skip to content

Commit aea7f62

Browse files
committed
Move forbidden keys to shared array
1 parent bafff42 commit aea7f62

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

packages/snaps-rpc-methods/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = deepmerge(baseConfig, {
1313
branches: 92.98,
1414
functions: 97.46,
1515
lines: 97.94,
16-
statements: 97.52,
16+
statements: 97.53,
1717
},
1818
},
1919
});

packages/snaps-rpc-methods/src/permitted/getState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { hasProperty, isObject, type Json } from '@metamask/utils';
1515

1616
import { manageStateBuilder } from '../restricted/manageState';
1717
import type { MethodHooksObject } from '../utils';
18-
import { StateKeyStruct } from '../utils';
18+
import { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';
1919

2020
const hookNames: MethodHooksObject<GetStateHooks> = {
2121
hasPermission: true,
@@ -164,7 +164,7 @@ export function get(
164164
// eslint-disable-next-line @typescript-eslint/prefer-for-of
165165
for (let i = 0; i < keys.length; i++) {
166166
const currentKey = keys[i];
167-
if (['__proto__', 'constructor'].includes(currentKey)) {
167+
if (FORBIDDEN_KEYS.includes(currentKey)) {
168168
throw rpcErrors.invalidParams(
169169
'Invalid params: Key contains forbidden characters.',
170170
);

packages/snaps-rpc-methods/src/permitted/setState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { isObject, assert, JsonStruct, type Json } from '@metamask/utils';
1616

1717
import { manageStateBuilder } from '../restricted/manageState';
1818
import type { MethodHooksObject } from '../utils';
19-
import { StateKeyStruct } from '../utils';
19+
import { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';
2020

2121
const hookNames: MethodHooksObject<SetStateHooks> = {
2222
hasPermission: true,
@@ -228,7 +228,7 @@ export function set(
228228

229229
for (let i = 0; i < keys.length; i++) {
230230
const currentKey = keys[i];
231-
if (['__proto__', 'constructor'].includes(currentKey)) {
231+
if (FORBIDDEN_KEYS.includes(currentKey)) {
232232
throw rpcErrors.invalidParams(
233233
'Invalid params: Key contains forbidden characters.',
234234
);

packages/snaps-rpc-methods/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { keccak_256 as keccak256 } from '@noble/hashes/sha3';
2121

2222
const HARDENED_VALUE = 0x80000000;
2323

24+
export const FORBIDDEN_KEYS = ['constructor', '__proto__', 'prototype'];
25+
2426
/**
2527
* Maps an interface with method hooks to an object, using the keys of the
2628
* interface, and `true` as value. This ensures that the `methodHooks` object

0 commit comments

Comments
 (0)