@@ -22,6 +22,11 @@ describe('Parse Body Util', () => {
2222 } )
2323 }
2424
25+ const createNestedKey = ( depth : number ) =>
26+ Array ( depth + 1 )
27+ . fill ( 'a' )
28+ . join ( '.' )
29+
2530 it ( 'should parse `multipart/form-data`' , async ( ) => {
2631 const data = new FormData ( )
2732 data . append ( 'message' , 'hello' )
@@ -179,6 +184,49 @@ describe('Parse Body Util', () => {
179184 } )
180185 } )
181186
187+ it ( 'should allow 32 nesting levels by default' , async ( ) => {
188+ const data = new FormData ( )
189+ data . append ( createNestedKey ( 32 ) , 'value' )
190+
191+ const req = createRequest ( FORM_URL , 'POST' , data )
192+ let nested : unknown = await parseBody ( req , { dot : true } )
193+
194+ for ( let i = 0 ; i <= 32 ; i ++ ) {
195+ nested = ( nested as Record < string , unknown > ) . a
196+ }
197+ expect ( nested ) . toBe ( 'value' )
198+ } )
199+
200+ it ( 'should reject dot notation deeper than the default limit' , async ( ) => {
201+ const data = new FormData ( )
202+ data . append ( createNestedKey ( 33 ) , 'value' )
203+
204+ const req = createRequest ( FORM_URL , 'POST' , data )
205+
206+ await expect ( parseBody ( req , { dot : true } ) ) . rejects . toThrow ( 'Nesting limit exceeded' )
207+ } )
208+
209+ it ( 'should reject deeply nested keys without splitting every segment' , async ( ) => {
210+ const req = createRequest ( SEARCH_URL , 'POST' , `${ '.' . repeat ( 65_530 ) } =value` , {
211+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
212+ } )
213+
214+ await expect ( parseBody ( req , { dot : true } ) ) . rejects . toThrow ( 'Nesting limit exceeded' )
215+ } )
216+
217+ it ( 'should reject too many nested objects across multiple fields' , async ( ) => {
218+ const searchParams = new URLSearchParams ( )
219+ for ( let i = 0 ; i <= 10_000 ; i ++ ) {
220+ searchParams . append ( `field${ i } .value` , 'value' )
221+ }
222+
223+ const req = createRequest ( SEARCH_URL , 'POST' , searchParams , {
224+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
225+ } )
226+
227+ await expect ( parseBody ( req , { dot : true } ) ) . rejects . toThrow ( 'Nesting limit exceeded' )
228+ } )
229+
182230 it ( 'should skip keys starting with __proto__. to prevent prototype pollution' , async ( ) => {
183231 const data = new FormData ( )
184232 data . append ( '__proto__.polluted' , 'malicious' )
0 commit comments