@@ -166,6 +166,19 @@ describe('Astro Actions', () => {
166166 assert . equal ( data . code , 'NOT_FOUND' ) ;
167167 } ) ;
168168
169+ it ( 'Returns 404 for prototype methods used as action names' , async ( ) => {
170+ for ( const name of [ 'constructor' , '__proto__' , 'toString' , 'valueOf' ] ) {
171+ const res = await fixture . fetch ( `/_actions/${ name } ` , {
172+ method : 'POST' ,
173+ body : JSON . stringify ( { } ) ,
174+ headers : {
175+ 'Content-Type' : 'application/json' ,
176+ } ,
177+ } ) ;
178+ assert . equal ( res . status , 404 , `Expected 404 for /_actions/${ name } ` ) ;
179+ }
180+ } ) ;
181+
169182 it ( 'Should fail when calling an action without using Astro.callAction' , async ( ) => {
170183 const res = await fixture . fetch ( '/invalid/' ) ;
171184 assert . equal ( res . status , 500 ) ;
@@ -606,6 +619,20 @@ describe('Astro Actions', () => {
606619 const data = await res . json ( ) ;
607620 assert . equal ( data . code , 'NOT_FOUND' ) ;
608621 } ) ;
622+
623+ it ( 'Returns 404 for prototype methods used as action names' , async ( ) => {
624+ for ( const name of [ 'constructor' , '__proto__' , 'toString' , 'valueOf' ] ) {
625+ const req = new Request ( `http://example.com/_actions/${ name } ` , {
626+ method : 'POST' ,
627+ headers : {
628+ 'Content-Type' : 'application/json' ,
629+ } ,
630+ body : JSON . stringify ( { } ) ,
631+ } ) ;
632+ const res = await app . render ( req ) ;
633+ assert . equal ( res . status , 404 , `Expected 404 for /_actions/${ name } ` ) ;
634+ }
635+ } ) ;
609636 } ) ;
610637} ) ;
611638
0 commit comments