@@ -270,9 +270,11 @@ router.patch('/:lineId/bounds', auth0Middleware(), async (req, res) => {
270270 if ( ! ( await projectObj . checkUserAccess ( user . _id , ACTIONS . UPDATE , SCOPES . SELECTOR , ENTITIES . LINE ) ) ) {
271271 return respondWithError ( res , 403 , 'You do not have permission to update line bounds in this project' )
272272 }
273- if ( typeof req . body !== 'object' || ! req . body . x || ! req . body . y || ! req . body . w || ! req . body . h ) {
274- return respondWithError ( res , 400 , 'Invalid request body. Expected an object with x, y, w, and h properties.' )
273+ const isValidBound = v => ( Number . isInteger ( v ) && v >= 0 ) || ( typeof v === 'string' && / ^ \d + $ / . test ( v ) )
274+ if ( ! req . body || typeof req . body !== 'object' || Array . isArray ( req . body ) || ! isValidBound ( req . body . x ) || ! isValidBound ( req . body . y ) || ! isValidBound ( req . body . w ) || ! isValidBound ( req . body . h ) ) {
275+ return respondWithError ( res , 400 , 'Invalid request body. Expected an object with x, y, w, and h as non-negative integers.' )
275276 }
277+ const bounds = { x : parseInt ( req . body . x , 10 ) , y : parseInt ( req . body . y , 10 ) , w : parseInt ( req . body . w , 10 ) , h : parseInt ( req . body . h , 10 ) }
276278 const project = await getProjectById ( req . params . projectId )
277279 const page = await findPageById ( req . params . pageId , req . params . projectId )
278280 const findOldLine = page . items ?. find ( l => l . id . split ( '/' ) . pop ( ) === req . params . lineId ?. split ( '/' ) . pop ( ) )
@@ -283,7 +285,7 @@ router.patch('/:lineId/bounds', auth0Middleware(), async (req, res) => {
283285 let oldLine = await fetch ( findOldLine . id ) . then ( res => res . json ( ) )
284286 delete oldLine . label
285287 const line = new Line ( oldLine )
286- const updatedLine = await line . updateBounds ( req . body , { creator : user . _id } )
288+ const updatedLine = await line . updateBounds ( bounds , { creator : user . _id } )
287289 const lineIndex = page . items . findIndex ( l => l . id . split ( '/' ) . pop ( ) === req . params . lineId ?. split ( '/' ) . pop ( ) )
288290 page . items [ lineIndex ] = updatedLine
289291
0 commit comments