@@ -10117,14 +10117,13 @@ describe('Vulnerabilities', () => {
1011710117 expect ( rejections ) . toEqual ( [ ] ) ;
1011810118 } ) ;
1011910119
10120- it_only_db ( 'mongo' ) ( 'completes a dot notation null on a pointer id' , async ( ) => {
10120+ it_only_db ( 'mongo' ) ( 'rejects a dot notation null on a pointer id without crashing' , async ( ) => {
10121+ // GHSA-655c-2xf3-77x9: a null dot notation key below a pointer is now rejected by
10122+ // schema validation (it previously completed and corrupted the stored pointer).
10123+ // The request still settles cleanly, with no hang and no unhandled rejection.
1012110124 const target = await makeTarget ( ) ;
1012210125 const holder = await makeHolder ( { owner : target } ) ;
10123- let seenOwnerId = 'not-called' ;
10124- Parse . Cloud . afterSave ( 'Holder' , req => {
10125- const owner = req . object . get ( 'owner' ) ;
10126- seenOwnerId = owner ? owner . id : null ;
10127- } ) ;
10126+ Parse . Cloud . afterSave ( 'Holder' , ( ) => { } ) ;
1012810127 const result = await within (
1012910128 request ( {
1013010129 method : 'PUT' ,
@@ -10134,8 +10133,10 @@ describe('Vulnerabilities', () => {
1013410133 } )
1013510134 ) ;
1013610135 expect ( result . hung ) . toBeUndefined ( ) ;
10137- expect ( result . status ) . toBe ( 200 ) ;
10138- expect ( seenOwnerId ) . toBe ( target . id ) ;
10136+ expect ( result . status ) . toBe ( 400 ) ;
10137+ expect ( result . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10138+ await holder . fetch ( { useMasterKey : true } ) ;
10139+ expect ( holder . get ( 'owner' ) . id ) . toBe ( target . id ) ;
1013910140 expect ( rejections ) . toEqual ( [ ] ) ;
1014010141 } ) ;
1014110142
@@ -10269,4 +10270,182 @@ describe('Vulnerabilities', () => {
1026910270 expect ( rejections ) . toEqual ( [ ] ) ;
1027010271 } ) ;
1027110272 } ) ;
10273+
10274+ describe ( '(GHSA-655c-2xf3-77x9) Dot notation key with a null value below a non-object field' , ( ) => {
10275+ const serverURL = 'http://localhost:8378/1' ;
10276+ const masterHeaders = {
10277+ 'X-Parse-Application-Id' : 'test' ,
10278+ 'X-Parse-Master-Key' : 'test' ,
10279+ 'Content-Type' : 'application/json' ,
10280+ } ;
10281+ const clientHeaders = {
10282+ 'X-Parse-Application-Id' : 'test' ,
10283+ 'X-Parse-REST-API-Key' : 'rest' ,
10284+ 'Content-Type' : 'application/json' ,
10285+ } ;
10286+ const maintenanceHeaders = {
10287+ 'X-Parse-Application-Id' : 'test' ,
10288+ 'X-Parse-Maintenance-Key' : 'testing' ,
10289+ 'Content-Type' : 'application/json' ,
10290+ } ;
10291+
10292+ const send = ( method , path , body , headers = masterHeaders ) =>
10293+ request ( { method, url : `${ serverURL } ${ path } ` , headers, body : body && JSON . stringify ( body ) } ) . then (
10294+ r => ( { status : r . status , data : r . data } ) ,
10295+ e => ( { status : e . status , data : e . data } )
10296+ ) ;
10297+ const put = ( id , body , headers ) => send ( 'PUT' , `/classes/Probe655c/${ id } ` , body , headers ) ;
10298+
10299+ async function setupSchema ( ) {
10300+ await send ( 'POST' , '/schemas/Probe655c' , {
10301+ className : 'Probe655c' ,
10302+ fields : {
10303+ owner : { type : 'Pointer' , targetClass : 'Target655c' } ,
10304+ count : { type : 'Number' } ,
10305+ str : { type : 'String' } ,
10306+ obj : { type : 'Object' } ,
10307+ arr : { type : 'Array' } ,
10308+ } ,
10309+ } ) ;
10310+ }
10311+ const makeTarget = ( ) => new Parse . Object ( 'Target655c' ) . save ( { n : 1 } , { useMasterKey : true } ) ;
10312+ async function makeProbe ( fields ) {
10313+ const o = new Parse . Object ( 'Probe655c' ) ;
10314+ await o . save ( fields , { useMasterKey : true } ) ;
10315+ return o ;
10316+ }
10317+
10318+ beforeEach ( setupSchema ) ;
10319+
10320+ it ( 'rejects a null dot notation key below a Pointer field instead of corrupting it' , async ( ) => {
10321+ const target = await makeTarget ( ) ;
10322+ const probe = await makeProbe ( { owner : target } ) ;
10323+ const res = await put ( probe . id , { 'owner.sub' : null } ) ;
10324+ expect ( res . status ) . toBe ( 400 ) ;
10325+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10326+ await probe . fetch ( { useMasterKey : true } ) ;
10327+ expect ( probe . get ( 'owner' ) . id ) . toBe ( target . id ) ;
10328+ } ) ;
10329+
10330+ it ( 'rejects a null dot notation pointer id key' , async ( ) => {
10331+ const target = await makeTarget ( ) ;
10332+ const probe = await makeProbe ( { owner : target } ) ;
10333+ const res = await put ( probe . id , { 'owner.id' : null } ) ;
10334+ expect ( res . status ) . toBe ( 400 ) ;
10335+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10336+ await probe . fetch ( { useMasterKey : true } ) ;
10337+ expect ( probe . get ( 'owner' ) . id ) . toBe ( target . id ) ;
10338+ } ) ;
10339+
10340+ it ( 'rejects a null dot notation key below a Number field' , async ( ) => {
10341+ const probe = await makeProbe ( { count : 5 } ) ;
10342+ const res = await put ( probe . id , { 'count.sub' : null } ) ;
10343+ expect ( res . status ) . toBe ( 400 ) ;
10344+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10345+ await probe . fetch ( { useMasterKey : true } ) ;
10346+ expect ( probe . get ( 'count' ) ) . toBe ( 5 ) ;
10347+ } ) ;
10348+
10349+ it ( 'rejects a null dot notation key below a String field' , async ( ) => {
10350+ const probe = await makeProbe ( { str : 'abc' } ) ;
10351+ const res = await put ( probe . id , { 'str.sub' : null } ) ;
10352+ expect ( res . status ) . toBe ( 400 ) ;
10353+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10354+ await probe . fetch ( { useMasterKey : true } ) ;
10355+ expect ( probe . get ( 'str' ) ) . toBe ( 'abc' ) ;
10356+ } ) ;
10357+
10358+ it ( 'does not make the object unreadable via a null dot notation key below a reserved field' , async ( ) => {
10359+ const probe = await makeProbe ( { str : 'abc' } ) ;
10360+ const res = await put ( probe . id , { 'createdAt.sub' : null } ) ;
10361+ expect ( res . status ) . toBe ( 400 ) ;
10362+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10363+ const read = await send ( 'GET' , `/classes/Probe655c/${ probe . id } ` ) ;
10364+ expect ( read . status ) . toBe ( 200 ) ;
10365+ } ) ;
10366+
10367+ it ( 'rejects a null dot notation key below the ACL' , async ( ) => {
10368+ const probe = await makeProbe ( { str : 'abc' } ) ;
10369+ const res = await put ( probe . id , { 'ACL.sub' : null } ) ;
10370+ expect ( res . status ) . toBe ( 400 ) ;
10371+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10372+ } ) ;
10373+
10374+ it ( 'rejects a null dot notation key below a Pointer field on create' , async ( ) => {
10375+ const target = await makeTarget ( ) ;
10376+ const res = await send ( 'POST' , '/classes/Probe655c' , {
10377+ owner : target . toPointer ( ) ,
10378+ 'owner.sub' : null ,
10379+ } ) ;
10380+ expect ( res . status ) . toBe ( 400 ) ;
10381+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10382+ } ) ;
10383+
10384+ it ( 'rejects the write for a non-master caller on a publicly writable object' , async ( ) => {
10385+ const target = await makeTarget ( ) ;
10386+ const probe = new Parse . Object ( 'Probe655c' ) ;
10387+ probe . set ( 'owner' , target ) ;
10388+ probe . setACL ( new Parse . ACL ( { '*' : { read : true , write : true } } ) ) ;
10389+ await probe . save ( null , { useMasterKey : true } ) ;
10390+ const res = await put ( probe . id , { 'owner.sub' : null } , clientHeaders ) ;
10391+ expect ( res . status ) . toBe ( 400 ) ;
10392+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10393+ await probe . fetch ( { useMasterKey : true } ) ;
10394+ expect ( probe . get ( 'owner' ) . id ) . toBe ( target . id ) ;
10395+ } ) ;
10396+
10397+ it ( 'rejects the write for a maintenance-key caller' , async ( ) => {
10398+ const target = await makeTarget ( ) ;
10399+ const probe = await makeProbe ( { owner : target } ) ;
10400+ const res = await put ( probe . id , { 'owner.sub' : null } , maintenanceHeaders ) ;
10401+ expect ( res . status ) . toBe ( 400 ) ;
10402+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10403+ await probe . fetch ( { useMasterKey : true } ) ;
10404+ expect ( probe . get ( 'owner' ) . id ) . toBe ( target . id ) ;
10405+ } ) ;
10406+
10407+ it ( 'rejects the write for a class with a beforeSave trigger' , async ( ) => {
10408+ const target = await makeTarget ( ) ;
10409+ const probe = await makeProbe ( { owner : target } ) ;
10410+ Parse . Cloud . beforeSave ( 'Probe655c' , ( ) => { } ) ;
10411+ const res = await put ( probe . id , { 'owner.sub' : null } ) ;
10412+ expect ( res . status ) . toBe ( 400 ) ;
10413+ expect ( res . data . code ) . toBe ( Parse . Error . INCORRECT_TYPE ) ;
10414+ await probe . fetch ( { useMasterKey : true } ) ;
10415+ expect ( probe . get ( 'owner' ) . id ) . toBe ( target . id ) ;
10416+ } ) ;
10417+
10418+ it ( 'still accepts a null dot notation key below an Object field' , async ( ) => {
10419+ const probe = await makeProbe ( { obj : { a : 1 } } ) ;
10420+ const res = await put ( probe . id , { 'obj.sub' : null } ) ;
10421+ expect ( res . status ) . toBe ( 200 ) ;
10422+ await probe . fetch ( { useMasterKey : true } ) ;
10423+ expect ( probe . get ( 'obj' ) ) . toEqual ( { a : 1 , sub : null } ) ;
10424+ } ) ;
10425+
10426+ it ( 'still accepts setting a whole object field to null' , async ( ) => {
10427+ const probe = await makeProbe ( { obj : { a : 1 } } ) ;
10428+ const res = await put ( probe . id , { obj : null } ) ;
10429+ expect ( res . status ) . toBe ( 200 ) ;
10430+ await probe . fetch ( { useMasterKey : true } ) ;
10431+ expect ( probe . get ( 'obj' ) ?? null ) . toBeNull ( ) ;
10432+ } ) ;
10433+
10434+ it_only_db ( 'mongo' ) ( 'still accepts a null array element by index' , async ( ) => {
10435+ const probe = await makeProbe ( { arr : [ 'x' ] } ) ;
10436+ const res = await put ( probe . id , { 'arr.0' : null } ) ;
10437+ expect ( res . status ) . toBe ( 200 ) ;
10438+ await probe . fetch ( { useMasterKey : true } ) ;
10439+ expect ( probe . get ( 'arr' ) ) . toEqual ( [ null ] ) ;
10440+ } ) ;
10441+
10442+ it_only_db ( 'mongo' ) ( 'still treats a Delete of a dot notation key below a Pointer as a no-op' , async ( ) => {
10443+ const target = await makeTarget ( ) ;
10444+ const probe = await makeProbe ( { owner : target } ) ;
10445+ const res = await put ( probe . id , { 'owner.sub' : { __op : 'Delete' } } ) ;
10446+ expect ( res . status ) . toBe ( 200 ) ;
10447+ await probe . fetch ( { useMasterKey : true } ) ;
10448+ expect ( probe . get ( 'owner' ) . id ) . toBe ( target . id ) ;
10449+ } ) ;
10450+ } ) ;
1027210451} ) ;
0 commit comments