@@ -228,7 +228,7 @@ describe('Cloud Code', () => {
228228 expect ( response . headers [ 'x-custom-header' ] ) . toEqual ( 'third' ) ;
229229 } ) ;
230230
231- it ( 'res.status() throws error for non-number status code' , async ( ) => {
231+ it ( 'res.status() throws error for non-integer status code' , async ( ) => {
232232 Parse . Cloud . define ( 'invalidStatusType' , ( req , res ) => {
233233 res . status ( '200' ) ;
234234 return { message : 'ok' } ;
@@ -251,6 +251,29 @@ describe('Cloud Code', () => {
251251 }
252252 } ) ;
253253
254+ it ( 'res.status() throws error for NaN status code' , async ( ) => {
255+ Parse . Cloud . define ( 'nanStatus' , ( req , res ) => {
256+ res . status ( NaN ) ;
257+ return { message : 'ok' } ;
258+ } ) ;
259+
260+ try {
261+ await request ( {
262+ method : 'POST' ,
263+ url : 'http://localhost:8378/1/functions/nanStatus' ,
264+ headers : {
265+ 'X-Parse-Application-Id' : 'test' ,
266+ 'X-Parse-REST-API-Key' : 'rest' ,
267+ 'Content-Type' : 'application/json' ,
268+ } ,
269+ body : { } ,
270+ } ) ;
271+ fail ( 'Expected request to fail' ) ;
272+ } catch ( response ) {
273+ expect ( response . status ) . toEqual ( 400 ) ;
274+ }
275+ } ) ;
276+
254277 it ( 'res.set() throws error for non-string header name' , async ( ) => {
255278 Parse . Cloud . define ( 'invalidHeaderName' , ( req , res ) => {
256279 res . set ( 123 , 'value' ) ;
@@ -320,6 +343,75 @@ describe('Cloud Code', () => {
320343 }
321344 } ) ;
322345
346+ it ( 'res.set() throws error for empty header name' , async ( ) => {
347+ Parse . Cloud . define ( 'emptyHeaderName' , ( req , res ) => {
348+ res . set ( ' ' , 'value' ) ;
349+ return { message : 'ok' } ;
350+ } ) ;
351+
352+ try {
353+ await request ( {
354+ method : 'POST' ,
355+ url : 'http://localhost:8378/1/functions/emptyHeaderName' ,
356+ headers : {
357+ 'X-Parse-Application-Id' : 'test' ,
358+ 'X-Parse-REST-API-Key' : 'rest' ,
359+ 'Content-Type' : 'application/json' ,
360+ } ,
361+ body : { } ,
362+ } ) ;
363+ fail ( 'Expected request to fail' ) ;
364+ } catch ( response ) {
365+ expect ( response . status ) . toEqual ( 400 ) ;
366+ }
367+ } ) ;
368+
369+ it ( 'res.set() throws error for prototype pollution header names' , async ( ) => {
370+ Parse . Cloud . define ( 'protoHeaderName' , ( req , res ) => {
371+ res . set ( '__proto__' , 'value' ) ;
372+ return { message : 'ok' } ;
373+ } ) ;
374+
375+ try {
376+ await request ( {
377+ method : 'POST' ,
378+ url : 'http://localhost:8378/1/functions/protoHeaderName' ,
379+ headers : {
380+ 'X-Parse-Application-Id' : 'test' ,
381+ 'X-Parse-REST-API-Key' : 'rest' ,
382+ 'Content-Type' : 'application/json' ,
383+ } ,
384+ body : { } ,
385+ } ) ;
386+ fail ( 'Expected request to fail' ) ;
387+ } catch ( response ) {
388+ expect ( response . status ) . toEqual ( 400 ) ;
389+ }
390+ } ) ;
391+
392+ it ( 'res.set() throws error for CRLF in header value' , async ( ) => {
393+ Parse . Cloud . define ( 'crlfHeaderValue' , ( req , res ) => {
394+ res . set ( 'X-Custom-Header' , 'value\r\nX-Injected: bad' ) ;
395+ return { message : 'ok' } ;
396+ } ) ;
397+
398+ try {
399+ await request ( {
400+ method : 'POST' ,
401+ url : 'http://localhost:8378/1/functions/crlfHeaderValue' ,
402+ headers : {
403+ 'X-Parse-Application-Id' : 'test' ,
404+ 'X-Parse-REST-API-Key' : 'rest' ,
405+ 'Content-Type' : 'application/json' ,
406+ } ,
407+ body : { } ,
408+ } ) ;
409+ fail ( 'Expected request to fail' ) ;
410+ } catch ( response ) {
411+ expect ( response . status ) . toEqual ( 400 ) ;
412+ }
413+ } ) ;
414+
323415 it ( 'can get config' , ( ) => {
324416 const config = Parse . Server ;
325417 let currentConfig = Config . get ( 'test' ) ;
0 commit comments