@@ -1352,3 +1352,50 @@ describe('(GHSA-q3vj-96h2-gwvg) SQL Injection via Increment amount on nested Obj
13521352 expect ( verify . get ( 'stats' ) . counter ) . toBe ( 8 ) ;
13531353 } ) ;
13541354} ) ;
1355+
1356+ describe ( '(GHSA-gqpp-xgvh-9h7h) SQL Injection via dot-notation sub-key name in Increment operation' , ( ) => {
1357+ const headers = {
1358+ 'Content-Type' : 'application/json' ,
1359+ 'X-Parse-Application-Id' : 'test' ,
1360+ 'X-Parse-REST-API-Key' : 'rest' ,
1361+ } ;
1362+
1363+ it_only_db ( 'postgres' ) ( 'does not execute injected SQL via single quote in sub-key name' , async ( ) => {
1364+ const obj = new Parse . Object ( 'SubKeyTest' ) ;
1365+ obj . set ( 'stats' , { counter : 0 } ) ;
1366+ await obj . save ( ) ;
1367+
1368+ const start = Date . now ( ) ;
1369+ await request ( {
1370+ method : 'PUT' ,
1371+ url : `http://localhost:8378/1/classes/SubKeyTest/${ obj . id } ` ,
1372+ headers,
1373+ body : JSON . stringify ( {
1374+ "stats.x' || (SELECT pg_sleep(3))::text || '" : { __op : 'Increment' , amount : 1 } ,
1375+ } ) ,
1376+ } ) . catch ( ( ) => { } ) ;
1377+ const elapsed = Date . now ( ) - start ;
1378+
1379+ // If injection succeeded, query would take >= 3 seconds
1380+ expect ( elapsed ) . toBeLessThan ( 3000 ) ;
1381+ } ) ;
1382+
1383+ it_only_db ( 'postgres' ) ( 'allows valid Increment on nested object field with normal sub-key' , async ( ) => {
1384+ const obj = new Parse . Object ( 'SubKeyTest' ) ;
1385+ obj . set ( 'stats' , { counter : 5 } ) ;
1386+ await obj . save ( ) ;
1387+
1388+ const response = await request ( {
1389+ method : 'PUT' ,
1390+ url : `http://localhost:8378/1/classes/SubKeyTest/${ obj . id } ` ,
1391+ headers,
1392+ body : JSON . stringify ( {
1393+ 'stats.counter' : { __op : 'Increment' , amount : 2 } ,
1394+ } ) ,
1395+ } ) ;
1396+
1397+ expect ( response . status ) . toBe ( 200 ) ;
1398+ const verify = await new Parse . Query ( 'SubKeyTest' ) . get ( obj . id ) ;
1399+ expect ( verify . get ( 'stats' ) . counter ) . toBe ( 7 ) ;
1400+ } ) ;
1401+ } ) ;
0 commit comments