Skip to content

Commit 9a9f132

Browse files
author
Deepak Tiwari
committed
AC-12738: Cart update api fix
1 parent f1e2f5f commit 9a9f132

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ protected function _createFromArray($className, $data)
333333
)
334334
);
335335
}
336+
if (is_string($setterValue) && $this->containsXSS($setterValue)) {
337+
throw new InputException(
338+
new Phrase(
339+
'"%field_name" contains potentially harmful content.',
340+
['field_name' => $propertyName]
341+
)
342+
);
343+
}
336344
$this->serviceInputValidator->validateEntityValue($object, $propertyName, $setterValue);
337345
$object->{$setterName}($setterValue);
338346
}
@@ -348,6 +356,19 @@ protected function _createFromArray($className, $data)
348356
return $object;
349357
}
350358

359+
/**
360+
* Check if input value contains any XSS vector
361+
*
362+
* @param string $value
363+
* @return bool
364+
*/
365+
private function containsXSS(string $value)
366+
{
367+
// Check for <script> tags or any common XSS vectors
368+
return preg_match('/<script\b[^>]*>(.*?)<\/script>/is', $value) ||
369+
preg_match('/[<>]/', $value);
370+
}
371+
351372
/**
352373
* Convert custom attribute data array to array of AttributeValue Data Object
353374
*

0 commit comments

Comments
 (0)