File tree Expand file tree Collapse file tree 4 files changed +25
-5
lines changed
packages/snaps-rpc-methods/src/permitted Expand file tree Collapse file tree 4 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -29,11 +29,15 @@ describe('get', () => {
2929 expect ( get ( object , 'a.b.c.d' ) ) . toBeNull ( ) ;
3030 } ) ;
3131
32- it ( 'returns `null` if the key is a prototype pollution attempt' , ( ) => {
33- expect ( get ( object , '__proto__.polluted' ) ) . toBeNull ( ) ;
32+ it ( 'throws an error if the key is a prototype pollution attempt' , ( ) => {
33+ expect ( ( ) => get ( object , '__proto__.polluted' ) ) . toThrow (
34+ 'Invalid params: Key contains forbidden characters.' ,
35+ ) ;
3436 } ) ;
3537
3638 it ( 'returns `null` if the key is a constructor pollution attempt' , ( ) => {
37- expect ( get ( object , 'constructor.polluted' ) ) . toBeNull ( ) ;
39+ expect ( ( ) => get ( object , 'constructor.polluted' ) ) . toThrow (
40+ 'Invalid params: Key contains forbidden characters.' ,
41+ ) ;
3842 } ) ;
3943} ) ;
Original file line number Diff line number Diff line change @@ -166,7 +166,9 @@ export function get(
166166
167167 for ( const currentKey of keys ) {
168168 if ( [ '__proto__' , 'constructor' ] . includes ( currentKey ) ) {
169- return null ;
169+ throw rpcErrors . invalidParams (
170+ 'Invalid params: Key contains forbidden characters.' ,
171+ ) ;
170172 }
171173
172174 if ( isPlainObject ( result ) ) {
Original file line number Diff line number Diff line change @@ -88,4 +88,16 @@ describe('set', () => {
8888 } ,
8989 } ) ;
9090 } ) ;
91+
92+ it ( 'throws an error if the key is a prototype pollution attempt' , ( ) => {
93+ expect ( ( ) => set ( { } , '__proto__.polluted' , 'value' ) ) . toThrow (
94+ 'Invalid params: Key contains forbidden characters.' ,
95+ ) ;
96+ } ) ;
97+
98+ it ( 'throws an error if the key is a constructor pollution attempt' , ( ) => {
99+ expect ( ( ) => set ( { } , 'constructor.polluted' , 'value' ) ) . toThrow (
100+ 'Invalid params: Key contains forbidden characters.' ,
101+ ) ;
102+ } ) ;
91103} ) ;
Original file line number Diff line number Diff line change @@ -202,7 +202,9 @@ export function set(
202202 for ( let i = 0 ; i < keys . length ; i ++ ) {
203203 const currentKey = keys [ i ] ;
204204 if ( [ '__proto__' , 'constructor' ] . includes ( currentKey ) ) {
205- return { } ;
205+ throw rpcErrors . invalidParams (
206+ 'Invalid params: Key contains forbidden characters.' ,
207+ ) ;
206208 }
207209
208210 if ( i === keys . length - 1 ) {
You can’t perform that action at this time.
0 commit comments