Skip to content

Commit d14a1ef

Browse files
feat: [MINT-4816] Update remaining xss template escaping (#221)
1 parent 2caf3d2 commit d14a1ef

File tree

12 files changed

+95
-70
lines changed

12 files changed

+95
-70
lines changed

view/adminhtml/templates/order/creditmemo/create/totals/sp-adjustment.phtml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
88
/** @var \Extend\Integration\Block\Adminhtml\Sales\Order\Creditmemo\Totals $block */
9+
/** @var $escaper \Magento\Framework\Escaper */
10+
911
$shippingProtectionPrice = $block->getShippingProtection();
1012
if ($block->isSpgSpRemovedFromCreditMemo()) {
1113
$shippingProtectionPrice = '';
@@ -15,34 +17,36 @@ if ($block->isSpgSpRemovedFromCreditMemo()) {
1517
<?php if ($block->getOriginalShippingProtection() > 0 || $block->isSpSpg()): ?>
1618
<tr>
1719
<td class="label">
18-
<?= $block->escapeHtml(__('Shipping Protection')) ?>
20+
<?= $escaper->escapeHtml(__('Shipping Protection')) ?>
1921
<div id="shipping_protection_adv"></div>
2022
<div class="sp-buttons-container" id="extend_sp_buttons_container">
2123
<?php if ($block->isSpSpg()): ?>
22-
<button name="spg-add" type="button" class="zero" id="extend_sp_buttons_container__spg_add"><?=__('Add to Refund')?></button>
23-
<button name="spg-remove" type="button" class="full" id="extend_sp_buttons_container__spg_remove"><?=__('Remove from Refund')?></button>
24+
<button name="spg-add" type="button" class="zero" id="extend_sp_buttons_container__spg_add"><?= $escaper->escapeHtml(__('Add to Refund')) ?></button>
25+
<button name="spg-remove" type="button" class="full" id="extend_sp_buttons_container__spg_remove"><?= $escaper->escapeHtml(__('Remove from Refund')) ?></button>
2426
<?php else: ?>
25-
<button name="full" type="button" class="full" id="extend_sp_buttons_container__full"><?=__('Full')?></button>
26-
<button name="zero" type="button" class="zero" id="extend_sp_buttons_container__zero"><?=__('0')?></button>
27+
<button name="full" type="button" class="full" id="extend_sp_buttons_container__full"><?= $escaper->escapeHtml(__('Full')) ?></button>
28+
<button name="zero" type="button" class="zero" id="extend_sp_buttons_container__zero"><?= $escaper->escapeHtml(__('0')) ?></button>
2729
<?php endif; ?>
2830
</div>
2931
</td>
3032
<td>
3133
<input type="text"
3234
name="creditmemo[shipping_protection]"
33-
data-full="<?= /* @noEscape */ $block->getOriginalShippingProtection() ?>"
34-
value="<?= /* @noEscape */ $shippingProtectionPrice ?>"
35+
data-full="<?= $escaper->escapeHtmlAttr($block->getOriginalShippingProtection()) ?>"
36+
value="<?= $escaper->escapeHtmlAttr($shippingProtectionPrice) ?>"
3537
class="input-text admin__control-text not-negative-amount"
3638
readonly="readonly"
3739
id="shipping_protection"/>
38-
<?php $scriptString = <<<script
40+
<?php
41+
$validationMessage = $escaper->escapeJs(__('Please enter a positive number in this field.'));
42+
$scriptString = <<<script
3943
require(['prototype'], function(){
4044
4145
//<![CDATA[
4246
Validation.addAllThese([
4347
[
4448
'not-negative-amount',
45-
'{$block->escapeJs(__('Please enter a positive number in this field.'))}',
49+
'{$validationMessage}',
4650
function (v) {
4751
if (v.length)
4852
return /^\s*\d+([,.]\d+)*\s*%?\s*$/.test(v);

view/adminhtml/templates/system/config/create_demo_integration.phtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
/** @var \Extend\Integration\Block\Adminhtml\System\Config\CreateDemoIntegration $block */
88
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
9+
/** @var $escaper \Magento\Framework\Escaper */
910
?>
10-
<?php $buttonUrl = $block->escapeJs($block->getButtonUrl()); ?>
11+
<?php $buttonUrl = $escaper->escapeJs($block->getButtonUrl()); ?>
1112
<div class="actions actions-create-integration">
1213
<p class="admin__field-error hidden" id="validation_result"></p>
1314
<button class="action-create-integration" type="button" id="<?= /* @noEscape */ $block->getHtmlId() ?>">
14-
<span><?= $block->escapeHtml($block->getButtonLabel()) ?></span>
15+
<span><?= $escaper->escapeHtml($block->getButtonLabel()) ?></span>
1516
</button>
1617
</div>
1718
<?= /* @noEscape */ $secureRenderer->renderTag('style', [], '#validation_result {margin-bottom: 10px;}', false); ?>

view/adminhtml/templates/system/config/create_prod_integration.phtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
/** @var \Extend\Integration\Block\Adminhtml\System\Config\CreateProdIntegration $block */
88
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
9+
/** @var $escaper \Magento\Framework\Escaper */
910
?>
10-
<?php $buttonUrl = $block->escapeJs($block->getButtonUrl()); ?>
11+
<?php $buttonUrl = $escaper->escapeJs($block->getButtonUrl()); ?>
1112
<div class="actions actions-create-integration">
1213
<p class="admin__field-error hidden" id="validation_result"></p>
1314
<button class="action-create-integration" type="button" id="<?= /* @noEscape */ $block->getHtmlId() ?>">
14-
<span><?= $block->escapeHtml($block->getButtonLabel()) ?></span>
15+
<span><?= $escaper->escapeHtml($block->getButtonLabel()) ?></span>
1516
</button>
1617
</div>
1718
<?= /* @noEscape */ $secureRenderer->renderTag('style', [], '#validation_result {margin-bottom: 10px;}', false); ?>

view/adminhtml/templates/system/config/finish-integration-steps.phtml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
/** @var $block \Extend\Integration\Block\Adminhtml\Integration\Edit\Tab\FinishIntegration */
3+
/** @var $escaper \Magento\Framework\Escaper */
4+
25
$status = $block->getActiveIntegrationStatusOnStore();
36
$showTimeline = $status !== 4 && $status !== 3;
47
?>
@@ -21,9 +24,9 @@ $showTimeline = $status !== 4 && $status !== 3;
2124

2225
<?php if ($status === 0): ?>
2326
<div class="extend-timeline-item-body">
24-
<p>The <strong><?= $this->getCurrentIntegrationName() ?></strong> integration is not yet enabled. Please follow the steps detailed on the <a href="<?= $block->getDefaultScopeUrl() ?>">Extend Settings</a> page to complete
27+
<p>The <strong><?= $escaper->escapeHtml($block->getCurrentIntegrationName()) ?></strong> integration is not yet enabled. Please follow the steps detailed on the <a href="<?= $escaper->escapeUrl($block->getDefaultScopeUrl()) ?>">Extend Settings</a> page to complete
2528
your setup and integration this store with Extend.</p>
26-
<button class="action-primary" name="finish_integration" type="button" onclick="document.location.href='<?= $block->getDefaultScopeUrl() ?>';">
29+
<button class="action-primary" name="finish_integration" type="button" onclick="document.location.href='<?= $escaper->escapeJs($block->getDefaultScopeUrl()) ?>';">
2730
<span><?= __('Finish Integration') ?></span>
2831
</button>
2932
</div>
@@ -35,7 +38,7 @@ $showTimeline = $status !== 4 && $status !== 3;
3538
<div class="extend-timeline-item-label">Sync Store with Extend</div>
3639
<?php if ($status === 1 || $status === 5): ?>
3740
<div class="extend-timeline-item-body">
38-
<p>The current integration is <strong><?= $this->getCurrentIntegrationName() ?></strong>.</p>
41+
<p>The current integration is <strong><?= $escaper->escapeHtml($block->getCurrentIntegrationName()) ?></strong>.</p>
3942
<div>
4043
<input type="checkbox" name="activate_current_store" id="activate_current_store" />
4144
<label for="activate_current_store">Add Store to current Integration</label>
@@ -53,16 +56,16 @@ $showTimeline = $status !== 4 && $status !== 3;
5356
<div class="extend-timeline-item-label">Integration Complete</div>
5457
<?php if ($status === 2): ?>
5558
<div class="extend-timeline-item-body">
56-
<p>The current integration is <strong><?= $this->getCurrentIntegrationName() ?></strong>.</p>
59+
<p>The current integration is <strong><?= $escaper->escapeHtml($block->getCurrentIntegrationName()) ?></strong>.</p>
5760
<div>
5861
<input type="checkbox" name="activate_current_store" id="activate_current_store" checked disabled />
5962
<label for="activate_current_store">Add Store to current Integration</label>
6063
</div>
6164
</br>
62-
<?php if ($this->getExtendStoreUuid()): ?>
65+
<?php if ($block->getExtendStoreUuid()): ?>
6366
<div>
6467
<label for="extend_store_id">Extend Store ID</label>
65-
<input type="text" value="<?= $this->getExtendStoreUuid() ?>" name="extend_store_id" id="extend_store_id" maxlength="36" disabled />
68+
<input type="text" value="<?= $escaper->escapeHtml($block->getExtendStoreUuid()) ?>" name="extend_store_id" id="extend_store_id" maxlength="36" disabled />
6669
</div>
6770
<?php endif; ?>
6871
</div>
@@ -73,7 +76,7 @@ $showTimeline = $status !== 4 && $status !== 3;
7376
<?php else: ?>
7477
<?php if ($status === 3): ?>
7578
<p>The Extend integration could not be found for the given store. Usually in this case an integration was selected and then deleted. Please
76-
go to the <a href="<?= $block->getDefaultScopeUrl() ?>">Extend Settings</a> page and select a new integration.
79+
go to the <a href="<?= $escaper->escapeUrl($block->getDefaultScopeUrl()) ?>">Extend Settings</a> page and select a new integration.
7780
</p>
7881
<?php elseif ($status === 4): ?>
7982
<p>Error retrieving the Extend integration for the given store.</p>

view/adminhtml/templates/system/config/integration-status.phtml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<?php
2+
/** @var $block \Extend\Integration\Block\Adminhtml\Integration\Edit\Tab\HowToActivate */
3+
/** @var $escaper \Magento\Framework\Escaper */
4+
?>
15
<div id="extend-integration-status">
26
<!-- Alert will initialize in a hidden state until needed -->
37
<div id="extend-alert-container" class="extend-alert extend-hidden">
@@ -19,7 +23,7 @@
1923
<ul>
2024
<li>
2125
Go to
22-
<a href="<?= /* @noEscape */ $this->getIntegrationUrl(); ?>"
26+
<a href="<?= $escaper->escapeUrl($block->getIntegrationUrl()); ?>"
2327
>integration settings</a
2428
>.
2529
</li>
@@ -121,19 +125,19 @@
121125
</div>
122126
</div>
123127

124-
<?php if ($integrations = $this->getIntegrations()): ?>
128+
<?php if ($integrations = $block->getIntegrations()): ?>
125129
<script type="text/x-magento-init">
126130
{
127131
"#extend-integration-status": {
128132
"activationStatus": [
129133
<?php foreach ($integrations as $key => $integration): ?>
130134
{
131-
"currentStep": "<?=$integration['current_step']?>",
132-
"identityLinkUrl": "<?=$integration['identity_link_url']?>",
133-
"integrationId": "<?=$integration['integration_id']?>",
134-
"integrationName": "<?=$integration['integration_name']?>",
135-
"oauthActivatedAt": "<?=$integration['oauth_activated_at']?>",
136-
"prevActivationFailed": "<?=$integration['prev_activation_failed']?>"
135+
"currentStep": "<?= $escaper->escapeJs($integration['current_step']) ?>",
136+
"identityLinkUrl": "<?= $escaper->escapeJs($integration['identity_link_url']) ?>",
137+
"integrationId": "<?= $escaper->escapeJs($integration['integration_id']) ?>",
138+
"integrationName": "<?= $escaper->escapeJs($integration['integration_name']) ?>",
139+
"oauthActivatedAt": "<?= $escaper->escapeJs($integration['oauth_activated_at']) ?>",
140+
"prevActivationFailed": "<?= $escaper->escapeJs($integration['prev_activation_failed']) ?>"
137141
}<?= array_key_last($integrations) === $key ? '' : ',' ?>
138142
<?php endforeach; ?>
139143
]

view/adminhtml/templates/system/config/recreate_pp_product.phtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
/** @var \Extend\Integration\Block\Adminhtml\System\Config\RecreatePPProduct $block */
88
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
9+
/** @var $escaper \Magento\Framework\Escaper */
910
?>
10-
<?php $buttonUrl = $block->escapeJs($block->getButtonUrl()); ?>
11+
<?php $buttonUrl = $escaper->escapeJs($block->getButtonUrl()); ?>
1112
<div class="actions actions-recreate-pp-product">
1213
<p class="admin__field-error hidden" id="validation_result"></p>
1314
<button class="action-recreate-pp-product" type="button" id="<?= /* @noEscape */ $block->getHtmlId() ?>">
14-
<span><?= $block->escapeHtml($block->getButtonLabel()) ?></span>
15+
<span><?= $escaper->escapeHtml($block->getButtonLabel()) ?></span>
1516
</button>
1617
</div>
1718
<?= /* @noEscape */ $secureRenderer->renderTag('style', [], '#validation_result {margin-bottom: 10px;}', false); ?>

view/frontend/templates/cart/item/renderer/actions/product-protection-simple-offer.phtml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
/** @var $block \Magento\Checkout\Block\Cart\Item\Renderer\Actions\Generic */
3+
/** @var $escaper \Magento\Framework\Escaper */
24

35
/** @var \Magento\Quote\Model\Quote\Item $_item */
46
$item = $block->getItem();
@@ -33,23 +35,23 @@ $sanitizedProductSku = preg_replace('/[^a-zA-Z0-9-_|]/', '', $productSku);
3335

3436
<?php if ($shouldRender) : ?>
3537
<div>
36-
<div class="product-protection-offer" id="product_protection_offer_<?= $sanitizedProductSku ?>"></div>
38+
<div class="product-protection-offer" id="product_protection_offer_<?= $escaper->escapeHtml($sanitizedProductSku) ?>"></div>
3739
</div>
3840
<script type="text/x-magento-init">
3941
{
40-
"#product_protection_offer_<?= $sanitizedProductSku ?>": {
42+
"#product_protection_offer_<?= $escaper->escapeJs($sanitizedProductSku) ?>": {
4143
"simpleProductProtectionOffer": [
4244
{
43-
"extendStoreUuid": "<?= $block
45+
"extendStoreUuid": "<?= $escaper->escapeJs($block
4446
->getData('viewModel')
45-
->getExtendStoreUuid() ?>",
46-
"activeEnvironment": "<?= $block
47+
->getExtendStoreUuid()) ?>",
48+
"activeEnvironment": "<?= $escaper->escapeJs($block
4749
->getData('viewModel')
48-
->getActiveEnvironment() ?>",
49-
"selectedProductSku": "<?= $product->getSku() ?>",
50-
"selectedProductPrice": "<?= $product->getPrice() ?>",
51-
"productCategory": "<?= $categoryName ?>",
52-
"currencyCode": "<?= $currencyCode ?>"
50+
->getActiveEnvironment()) ?>",
51+
"selectedProductSku": "<?= $escaper->escapeJs($product->getSku()) ?>",
52+
"selectedProductPrice": "<?= $escaper->escapeJs($product->getPrice()) ?>",
53+
"productCategory": "<?= $escaper->escapeJs($categoryName) ?>",
54+
"currencyCode": "<?= $escaper->escapeJs($currencyCode) ?>"
5355
}
5456
]
5557
}

view/frontend/templates/cart/minicart-simple-offer.phtml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
* Copyright Extend (c) 2023. All rights reserved.
44
* See Extend-COPYING.txt for license details.
55
*/
6+
7+
/** @var $block \Magento\Framework\View\Element\Template */
8+
/** @var $escaper \Magento\Framework\Escaper */
9+
610
$viewModel = $block->getData('viewModel');
711
$extendStoreUuid = $viewModel->getExtendStoreUuid();
812
$activeEnvironment = $viewModel->getActiveEnvironment();
@@ -18,9 +22,9 @@ $shouldRender = $viewModel->isExtendProductProtectionEnabled() && $viewModel->is
1822
"#extendMinicartSimpleOffer": {
1923
"minicartSimpleOffer": [
2024
{
21-
"extendStoreUuid": "<?= $extendStoreUuid ?>",
22-
"activeEnvironment": "<?= $activeEnvironment ?>",
23-
"currencyCode": "<?= $currencyCode ?>"
25+
"extendStoreUuid": "<?= $escaper->escapeJs($extendStoreUuid) ?>",
26+
"activeEnvironment": "<?= $escaper->escapeJs($activeEnvironment) ?>",
27+
"currencyCode": "<?= $escaper->escapeJs($currencyCode) ?>"
2428
}
2529
]
2630
}

view/frontend/templates/catalog/product/view/aftermarket-product-protection-modal-offer.phtml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
2+
/** @var $block \Magento\Framework\View\Element\Template */
3+
/** @var $escaper \Magento\Framework\Escaper */
4+
25
$viewModel = $block->getData('viewModel');
36

47
$extendStoreUuid = $viewModel->getExtendStoreUuid();
58
$activeEnvironment = $viewModel->getActiveEnvironment();
6-
7-
$leadToken = $escaper->escapeHtml($escaper->escapeJs($viewModel->getLeadTokenFromUrl()));
8-
$viewModel = $block->getData('viewModel');
9-
9+
$leadToken = $viewModel->getLeadTokenFromUrl();
1010
$currencyCode = $viewModel->getCurrencyCode();
1111
$isCurrencySupported = $viewModel->isCurrencySupported();
1212

@@ -19,10 +19,10 @@ $shouldRender = $viewModel->isExtendProductProtectionEnabled() && $viewModel->is
1919
"*": {
2020
"aftermarketProductProtectionModalOffer": [
2121
{
22-
"extendStoreUuid": "<?= $extendStoreUuid ?>",
23-
"activeEnvironment": "<?= $activeEnvironment ?>",
24-
"leadToken": "<?= /* @noEscape */ $leadToken ?>",
25-
"currencyCode": "<?= $currencyCode ?>"
22+
"extendStoreUuid": "<?= $escaper->escapeJs($extendStoreUuid) ?>",
23+
"activeEnvironment": "<?= $escaper->escapeJs($activeEnvironment) ?>",
24+
"leadToken": "<?= $escaper->escapeJs($leadToken) ?>",
25+
"currencyCode": "<?= $escaper->escapeJs($currencyCode) ?>"
2626
}
2727
]
2828
}

view/frontend/templates/catalog/product/view/product-protection-modal-offer.phtml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
/** @var $block \Magento\Catalog\Block\Product\View */
3+
/** @var $escaper \Magento\Framework\Escaper */
4+
25
$viewModel = $block->getData('viewModel');
36
$categoryModel = $block->getData('categoryModel');
47

@@ -26,19 +29,19 @@ $shouldRender = $viewModel->isExtendProductProtectionEnabled() && $viewModel->is
2629
?>
2730

2831
<?php if ($shouldRender) : ?>
29-
<div class="product_protection_modal_offer" id="product_protection_modal_offer_<?= $sanitizedProductSku ?>"></div>
32+
<div class="product_protection_modal_offer" id="product_protection_modal_offer_<?= $escaper->escapeHtml($sanitizedProductSku) ?>"></div>
3033

3134
<script type="text/x-magento-init">
3235
{
33-
"#product_protection_modal_offer_<?= $sanitizedProductSku ?>": {
36+
"#product_protection_modal_offer_<?= $escaper->escapeJs($sanitizedProductSku) ?>": {
3437
"productProtectionModalOffer": [
3538
{
36-
"extendStoreUuid": "<?= $extendStoreUuid ?>",
37-
"activeEnvironment": "<?= $activeEnvironment ?>",
38-
"productSku": "<?= $productSku ?>",
39-
"productPrice": "<?= $productPrice ?>",
40-
"productCategory": "<?= $categoryName ?>",
41-
"currencyCode": "<?= $currencyCode ?>"
39+
"extendStoreUuid": "<?= $escaper->escapeJs($extendStoreUuid) ?>",
40+
"activeEnvironment": "<?= $escaper->escapeJs($activeEnvironment) ?>",
41+
"productSku": "<?= $escaper->escapeJs($productSku) ?>",
42+
"productPrice": "<?= $escaper->escapeJs($productPrice) ?>",
43+
"productCategory": "<?= $escaper->escapeJs($categoryName) ?>",
44+
"currencyCode": "<?= $escaper->escapeJs($currencyCode) ?>"
4245
}
4346
]
4447
}

0 commit comments

Comments
 (0)