@@ -12923,14 +12923,6 @@ describe('Vulnerabilities', () => {
1292312923 ? { updatedAt : jasmine . any ( String ) }
1292412924 : { updatedAt : jasmine . any ( String ) , field } ;
1292512925 for ( const [ stored , values ] of Object . entries ( storedValues ) ) {
12926- // A Remove needs a stored parent field on MongoDB
12927- if (
12928- name === 'Remove' &&
12929- stored === 'a missing field' &&
12930- process . env . PARSE_SERVER_TEST_DB !== 'postgres'
12931- ) {
12932- continue ;
12933- }
1293412926 const response = await update ( values , body ) ;
1293512927 expect ( response . data ) . withContext ( stored ) . toEqual ( expected ) ;
1293612928 }
@@ -13045,4 +13037,170 @@ describe('Vulnerabilities', () => {
1304513037 }
1304613038 } ) ;
1304713039 } ) ;
13040+ describe ( '(GHSA-4m87-fqwv-2m8v) Dot notation operation on a missing field reveals whether the field is stored to a caller without read access' , ( ) => {
13041+ const headers = {
13042+ 'X-Parse-Application-Id' : 'test' ,
13043+ 'X-Parse-REST-API-Key' : 'rest' ,
13044+ 'Content-Type' : 'application/json' ,
13045+ } ;
13046+ const masterHeaders = { ...headers , 'X-Parse-Master-Key' : 'test' } ;
13047+
13048+ beforeEach ( async ( ) => {
13049+ const schema = new Parse . Schema ( 'WriteOnly' ) ;
13050+ schema . addObject ( 'field' ) ;
13051+ schema . addArray ( 'list' ) ;
13052+ schema . setCLP ( {
13053+ find : { } ,
13054+ get : { } ,
13055+ count : { } ,
13056+ create : { '*' : true } ,
13057+ update : { '*' : true } ,
13058+ delete : { } ,
13059+ addField : { } ,
13060+ } ) ;
13061+ await schema . save ( ) ;
13062+ } ) ;
13063+
13064+ const update = async ( stored , body , extraHeaders = { } ) => {
13065+ const obj = await new Parse . Object ( 'WriteOnly' ) . save ( stored , { useMasterKey : true } ) ;
13066+ const response = await request ( {
13067+ method : 'PUT' ,
13068+ url : `${ Parse . serverURL } /classes/WriteOnly/${ obj . id } ` ,
13069+ headers : { ...headers , ...extraHeaders } ,
13070+ body : JSON . stringify ( body ) ,
13071+ } ) ;
13072+ return { ...response , id : obj . id } ;
13073+ } ;
13074+
13075+ const create = ( body , extraHeaders = { } ) =>
13076+ request ( {
13077+ method : 'POST' ,
13078+ url : `${ Parse . serverURL } /classes/WriteOnly` ,
13079+ headers : { ...headers , ...extraHeaders } ,
13080+ body : JSON . stringify ( body ) ,
13081+ } ) ;
13082+
13083+ describe ( 'update' , ( ) => {
13084+ const storedValues = {
13085+ 'a stored path' : { field : { items : [ 'y' ] , deep : { items : [ 'y' ] } } } ,
13086+ 'a parent without the path' : { field : { other : 'stored-other' } } ,
13087+ 'a missing parent field' : { } ,
13088+ } ;
13089+ const cases = [
13090+ [ 'Remove' , { 'field.items' : { __op : 'Remove' , objects : [ 'y' ] } } , { items : [ ] } ] ,
13091+ [
13092+ 'nested Remove' ,
13093+ { 'field.deep.items' : { __op : 'Remove' , objects : [ 'y' ] } } ,
13094+ { deep : { items : [ ] } } ,
13095+ ] ,
13096+ [
13097+ 'Remove with an operation on another path' ,
13098+ {
13099+ 'field.items' : { __op : 'Remove' , objects : [ 'y' ] } ,
13100+ 'field.count' : { __op : 'Increment' , amount : 0 } ,
13101+ } ,
13102+ { items : [ ] , count : 0 } ,
13103+ ] ,
13104+ ] ;
13105+ for ( const trigger of [ 'no trigger' , 'beforeSave' , 'afterSave' ] ) {
13106+ for ( const [ name , body , field ] of cases ) {
13107+ it ( `returns the request values of ${ name } with ${ trigger } ` , async ( ) => {
13108+ if ( trigger !== 'no trigger' ) {
13109+ Parse . Cloud [ trigger ] ( 'WriteOnly' , ( ) => { } ) ;
13110+ }
13111+ for ( const [ stored , values ] of Object . entries ( storedValues ) ) {
13112+ const response = await update ( values , body ) ;
13113+ expect ( response . status ) . withContext ( stored ) . toBe ( 200 ) ;
13114+ expect ( response . data )
13115+ . withContext ( stored )
13116+ . toEqual ( { updatedAt : jasmine . any ( String ) , field } ) ;
13117+ }
13118+ } ) ;
13119+ }
13120+ }
13121+
13122+ it ( 'succeeds for a Remove on a missing parent field with the master key' , async ( ) => {
13123+ const response = await update (
13124+ { } ,
13125+ { 'field.items' : { __op : 'Remove' , objects : [ 'y' ] } } ,
13126+ masterHeaders
13127+ ) ;
13128+ expect ( response . status ) . toBe ( 200 ) ;
13129+ expect ( response . data . updatedAt ) . toEqual ( jasmine . any ( String ) ) ;
13130+ } ) ;
13131+
13132+ it_only_db ( 'mongo' ) (
13133+ 'returns an empty parent for a Remove on a missing parent field with the master key' ,
13134+ async ( ) => {
13135+ const response = await update (
13136+ { } ,
13137+ { 'field.items' : { __op : 'Remove' , objects : [ 'y' ] } } ,
13138+ masterHeaders
13139+ ) ;
13140+ expect ( response . data ) . toEqual ( { updatedAt : jasmine . any ( String ) , field : { } } ) ;
13141+ const obj = await new Parse . Query ( 'WriteOnly' ) . get ( response . id , { useMasterKey : true } ) ;
13142+ expect ( obj . get ( 'field' ) ) . toBeUndefined ( ) ;
13143+ }
13144+ ) ;
13145+
13146+ it_only_db ( 'mongo' ) (
13147+ 'keeps the object clean after a Remove on a missing parent field with the master key' ,
13148+ async ( ) => {
13149+ const obj = await new Parse . Object ( 'WriteOnly' ) . save ( { other : 1 } , { useMasterKey : true } ) ;
13150+ obj . remove ( 'field.items' , 'y' ) ;
13151+ await obj . save ( null , { useMasterKey : true } ) ;
13152+ expect ( obj . dirtyKeys ( ) ) . toEqual ( [ ] ) ;
13153+ const stored = await new Parse . Query ( 'WriteOnly' ) . get ( obj . id , { useMasterKey : true } ) ;
13154+ expect ( stored . get ( 'field' ) ) . toBeUndefined ( ) ;
13155+ }
13156+ ) ;
13157+
13158+ it_only_db ( 'mongo' ) (
13159+ 'returns the request values of a Remove below an array index for every stored value' ,
13160+ async ( ) => {
13161+ const body = { 'list.1.items' : { __op : 'Remove' , objects : [ 'y' ] } } ;
13162+ const storedLists = {
13163+ 'a stored path' : { list : [ { items : [ 'y' ] } , { items : [ 'y' ] } ] } ,
13164+ 'a shorter array' : { list : [ { items : [ 'y' ] } ] } ,
13165+ 'a missing field' : { } ,
13166+ } ;
13167+ for ( const [ stored , values ] of Object . entries ( storedLists ) ) {
13168+ const response = await update ( values , body ) ;
13169+ expect ( response . status ) . withContext ( stored ) . toBe ( 200 ) ;
13170+ expect ( response . data )
13171+ . withContext ( stored )
13172+ . toEqual ( { updatedAt : jasmine . any ( String ) , list : [ { items : [ ] } ] } ) ;
13173+ }
13174+ }
13175+ ) ;
13176+ } ) ;
13177+
13178+ describe ( 'create' , ( ) => {
13179+ it ( 'returns the request value of a dot notation operation' , async ( ) => {
13180+ const response = await create ( { 'field.count' : { __op : 'Increment' , amount : 1 } } ) ;
13181+ expect ( response . status ) . toBe ( 201 ) ;
13182+ expect ( response . data ) . toEqual ( {
13183+ objectId : jasmine . any ( String ) ,
13184+ createdAt : jasmine . any ( String ) ,
13185+ field : { count : 1 } ,
13186+ } ) ;
13187+ } ) ;
13188+
13189+ it ( 'succeeds for a dot notation operation with the master key' , async ( ) => {
13190+ const response = await create (
13191+ { 'field.count' : { __op : 'Increment' , amount : 1 } } ,
13192+ masterHeaders
13193+ ) ;
13194+ expect ( response . status ) . toBe ( 201 ) ;
13195+ expect ( response . data . objectId ) . toEqual ( jasmine . any ( String ) ) ;
13196+ } ) ;
13197+
13198+ it ( 'keeps the object clean after a create with a dot notation operation' , async ( ) => {
13199+ const obj = new Parse . Object ( 'WriteOnly' ) ;
13200+ obj . increment ( 'field.count' ) ;
13201+ await obj . save ( null , { useMasterKey : true } ) ;
13202+ expect ( obj . dirtyKeys ( ) ) . toEqual ( [ ] ) ;
13203+ } ) ;
13204+ } ) ;
13205+ } ) ;
1304813206} ) ;
0 commit comments