@@ -12768,4 +12768,78 @@ describe('Vulnerabilities', () => {
1276812768 } ) ;
1276912769 } ) ;
1277012770 } ) ;
12771+
12772+ describe ( '(GHSA-9492-427f-466x) Email address format validation backtracks on a crafted email address' , ( ) => {
12773+ const headers = {
12774+ 'X-Parse-Application-Id' : 'test' ,
12775+ 'X-Parse-REST-API-Key' : 'rest' ,
12776+ 'Content-Type' : 'application/json' ,
12777+ } ;
12778+ const lineTerminators = {
12779+ LF : '\n' ,
12780+ CR : '\r' ,
12781+ LS : String . fromCharCode ( 0x2028 ) ,
12782+ PS : String . fromCharCode ( 0x2029 ) ,
12783+ } ;
12784+ const craftedEmail = lineTerminator => '@' . repeat ( 100000 ) + lineTerminator ;
12785+ const signUp = body =>
12786+ request ( {
12787+ method : 'POST' ,
12788+ url : `${ Parse . serverURL } /users` ,
12789+ headers,
12790+ body : JSON . stringify ( body ) ,
12791+ } ) . catch ( e => e ) ;
12792+
12793+ for ( const [ name , lineTerminator ] of Object . entries ( lineTerminators ) ) {
12794+ it ( `rejects a crafted email address ending with ${ name } on sign-up in time` , async ( ) => {
12795+ const start = Date . now ( ) ;
12796+ const response = await signUp ( {
12797+ username : 'user' ,
12798+ password : 'password' ,
12799+ email : craftedEmail ( lineTerminator ) ,
12800+ } ) ;
12801+ expect ( Date . now ( ) - start ) . toBeLessThan ( 2000 ) ;
12802+ expect ( response . data . code ) . toBe ( Parse . Error . INVALID_EMAIL_ADDRESS ) ;
12803+ } ) ;
12804+ }
12805+
12806+ it ( 'rejects a crafted email address on user update in time' , async ( ) => {
12807+ const user = await Parse . User . signUp ( 'user' , 'password' ) ;
12808+ const start = Date . now ( ) ;
12809+ const response = await request ( {
12810+ method : 'PUT' ,
12811+ url : `${ Parse . serverURL } /users/${ user . id } ` ,
12812+ headers : { ...headers , 'X-Parse-Session-Token' : user . getSessionToken ( ) } ,
12813+ body : JSON . stringify ( { email : craftedEmail ( lineTerminators . LF ) } ) ,
12814+ } ) . catch ( e => e ) ;
12815+ expect ( Date . now ( ) - start ) . toBeLessThan ( 2000 ) ;
12816+ expect ( response . data . code ) . toBe ( Parse . Error . INVALID_EMAIL_ADDRESS ) ;
12817+ } ) ;
12818+
12819+ it ( 'accepts an email address with a character before and after an at sign' , async ( ) => {
12820+ const emails = [ 'user@example.com' , 'a@b' , 'a @ b' , 'a@b@c' , 'a@@b' , '@a@b' ] ;
12821+ for ( const [ i , email ] of emails . entries ( ) ) {
12822+ const response = await signUp ( { username : `user${ i } ` , password : 'password' , email } ) ;
12823+ expect ( response . status ) . withContext ( email ) . toBe ( 201 ) ;
12824+ }
12825+ } ) ;
12826+
12827+ it ( 'rejects an email address without a character before or after an at sign' , async ( ) => {
12828+ for ( const email of [ 'example.com' , '@example.com' , 'user@' , '@' , '@@' ] ) {
12829+ const response = await signUp ( { username : 'user' , password : 'password' , email } ) ;
12830+ expect ( response . data . code ) . withContext ( email ) . toBe ( Parse . Error . INVALID_EMAIL_ADDRESS ) ;
12831+ }
12832+ } ) ;
12833+
12834+ it ( 'rejects an email address with a line terminator' , async ( ) => {
12835+ for ( const lt of Object . values ( lineTerminators ) ) {
12836+ for ( const email of [ `${ lt } a@b` , `a${ lt } @b` , `a@${ lt } b` , `a@b${ lt } ` ] ) {
12837+ const response = await signUp ( { username : 'user' , password : 'password' , email } ) ;
12838+ expect ( response . data . code )
12839+ . withContext ( encodeURIComponent ( email ) )
12840+ . toBe ( Parse . Error . INVALID_EMAIL_ADDRESS ) ;
12841+ }
12842+ }
12843+ } ) ;
12844+ } ) ;
1277112845} ) ;
0 commit comments