@@ -29,7 +29,7 @@ test('prototype contamination', async (t) => {
2929 } catch {
3030 ;
3131 }
32- strictEqual ( a , 'string' , "the toString method should not be compromised " ) ;
32+ strictEqual ( a , undefined , "the toString method should not be used directly " ) ;
3333
3434 } ) ;
3535
@@ -51,7 +51,47 @@ test('prototype contamination', async (t) => {
5151
5252 const text = await resClient . text ( ) ;
5353
54- t . ok ( text ) ;
54+ ok ( text ) ;
55+ } ) ;
56+
57+ test ( 'should not use unsafe methods on user provided objects' , async ( t ) => {
58+ server . on ( 'request' , async ( req , res ) => {
59+ const form = formidable ( ) ;
60+
61+ const [ fields , files ] = await form . parse ( req ) ;
62+
63+ res . writeHead ( 200 ) ;
64+ res . end ( "ok" ) ;
65+
66+ let a ;
67+ try {
68+ a = typeof String ( fields ) ;
69+ } catch {
70+ ;
71+ }
72+ strictEqual ( a , undefined , "the toString method should not be used directly" ) ;
73+
74+ } ) ;
75+
76+ await new Promise ( resolve => server . listen ( port , resolve ) ) ;
77+
78+ const body = `{"a":"x","b":"x","z":5}` ;
79+
80+ const resClient = await fetch ( String ( new URL ( `http:localhost:${ port } /` ) ) , {
81+ method : 'POST' ,
82+ headers : {
83+ 'Content-Length' : body . length ,
84+ Host : `localhost:${ port } ` ,
85+ 'Content-Type' : 'text/json;' ,
86+ } ,
87+ body
88+ } ) ;
89+
90+ strictEqual ( resClient . status , 200 ) ;
91+
92+ const text = await resClient . text ( ) ;
93+
94+ ok ( text ) ;
5595} ) ;
5696
5797
0 commit comments