File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -852,4 +852,61 @@ describe('batch', () => {
852852 expect ( result . data ) . toEqual ( jasmine . any ( Array ) ) ;
853853 } ) ;
854854 } ) ;
855+
856+ describe ( 'nested batch requests' , ( ) => {
857+ it ( 'rejects sub-request that targets the batch endpoint' , async ( ) => {
858+ await expectAsync (
859+ request ( {
860+ method : 'POST' ,
861+ url : 'http://localhost:8378/1/batch' ,
862+ headers,
863+ body : JSON . stringify ( {
864+ requests : [
865+ {
866+ method : 'POST' ,
867+ path : '/1/batch' ,
868+ body : {
869+ requests : [ { method : 'GET' , path : '/1/classes/TestClass' } ] ,
870+ } ,
871+ } ,
872+ ] ,
873+ } ) ,
874+ } )
875+ ) . toBeRejectedWith (
876+ jasmine . objectContaining ( {
877+ status : 400 ,
878+ data : jasmine . objectContaining ( {
879+ error : 'nested batch requests are not allowed' ,
880+ } ) ,
881+ } )
882+ ) ;
883+ } ) ;
884+
885+ it ( 'rejects when any sub-request among valid ones targets the batch endpoint' , async ( ) => {
886+ await expectAsync (
887+ request ( {
888+ method : 'POST' ,
889+ url : 'http://localhost:8378/1/batch' ,
890+ headers,
891+ body : JSON . stringify ( {
892+ requests : [
893+ { method : 'GET' , path : '/1/classes/TestClass' } ,
894+ {
895+ method : 'POST' ,
896+ path : '/1/batch' ,
897+ body : { requests : [ { method : 'GET' , path : '/1/classes/TestClass' } ] } ,
898+ } ,
899+ ] ,
900+ } ) ,
901+ } )
902+ ) . toBeRejectedWith (
903+ jasmine . objectContaining ( {
904+ status : 400 ,
905+ data : jasmine . objectContaining ( {
906+ error : 'nested batch requests are not allowed' ,
907+ } ) ,
908+ } )
909+ ) ;
910+ } ) ;
911+ } ) ;
855912} ) ;
Original file line number Diff line number Diff line change @@ -101,6 +101,9 @@ async function handleBatch(router, req) {
101101 const rateLimits = req . config . rateLimits || [ ] ;
102102 for ( const restRequest of req . body . requests ) {
103103 const routablePath = makeRoutablePath ( restRequest . path ) ;
104+ if ( ( restRequest . method || 'GET' ) . toUpperCase ( ) === 'POST' && routablePath === batchPath ) {
105+ throw new Parse . Error ( Parse . Error . INVALID_JSON , 'nested batch requests are not allowed' ) ;
106+ }
104107 for ( const limit of rateLimits ) {
105108 const pathExp = limit . path . regexp || limit . path ;
106109 if ( ! pathExp . test ( routablePath ) ) {
You can’t perform that action at this time.
0 commit comments