Skip to content

Commit 9f0638a

Browse files
committed
Fix XSS
1 parent da143df commit 9f0638a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/controllers/InventoryController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,17 @@ public function actionInventoryLevelsTableData(): Response
281281
$purchasable = \Craft::$app->getElements()->getElementById($inventoryLevel['purchasableId'], siteId: Cp::requestedSite()->id);
282282
$inventoryItemDomId = sprintf("edit-$id-link-%s", mt_rand());
283283
if ($purchasable) {
284-
$inventoryLevel['purchasable'] = Cp::chipHtml($purchasable, ['labelHtml' => $purchasable->getDescription(), 'showActionMenu' => !$purchasable->getIsDraft() && $purchasable->canSave($currentUser)]);
284+
// When providing the `labelHtml` option we need to encode it ourselves
285+
$inventoryLevel['purchasable'] = Cp::chipHtml($purchasable, ['labelHtml' => Html::encode($purchasable->getDescription()), 'showActionMenu' => !$purchasable->getIsDraft() && $purchasable->canSave($currentUser)]);
285286
} else {
286-
$inventoryLevel['purchasable'] = $inventoryLevel['description'];
287+
$inventoryLevel['purchasable'] = Html::encode($inventoryLevel['description']);
287288
}
288289
if (PurchasableHelper::isTempSku($inventoryLevel['sku'])) {
289290
$inventoryLevel['sku'] = '';
290291
}
291-
$inventoryLevel['sku'] = Html::tag('span', Html::a($inventoryLevel['sku'], "#", ['id' => "$inventoryItemDomId", 'class' => 'code']));
292+
293+
// Ensure encoded SKU
294+
$inventoryLevel['sku'] = Html::tag('span', Html::a(Html::encode($inventoryLevel['sku']), "#", ['id' => "$inventoryItemDomId", 'class' => 'code']));
292295
$inventoryLevel['id'] = $id;
293296

294297
$view->registerJsWithVars(fn($id, $params, $inventoryLevelsManagerContainerId) => <<<JS

0 commit comments

Comments
 (0)