Skip to content

Commit

Permalink
Merge pull request #2897 from spryker/bugfix/core-2145-xss-injection
Browse files Browse the repository at this point in the history
core-2145: fix XSS in zed customer view page
  • Loading branch information
dereuromark authored Oct 26, 2017
2 parents ca7ffc0 + dfee078 commit 4ffedb8
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 4 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"spryker/session": "^3.0.0",
"spryker/symfony": "^3.0.0",
"spryker/util-date-time": "^1.0.0",
"spryker/util-sanitize": "^2.0.0",
"spryker/util-text": "^1.1.0",
"spryker/zed-request": "^3.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function createCustomerTable()
*/
public function createCustomerAddressTable($idCustomer)
{
return new AddressTable($this->getQueryContainer(), $idCustomer);
return new AddressTable($this->getQueryContainer(), $idCustomer, $this->getUtilSanitizeService());
}

/**
Expand Down Expand Up @@ -127,4 +127,12 @@ public function getCustomerTransferExpanderPlugins()
{
return $this->getProvidedDependency(CustomerDependencyProvider::PLUGINS_CUSTOMER_TRANSFER_EXPANDER);
}

/**
* @return \Spryker\Zed\Customer\Dependency\Service\CustomerToUtilSanitizeInterface
*/
protected function getUtilSanitizeService()
{
return $this->getProvidedDependency(CustomerDependencyProvider::SERVICE_UTIL_SANITIZE);
}
}
18 changes: 15 additions & 3 deletions src/Spryker/Zed/Customer/Communication/Table/AddressTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Orm\Zed\Customer\Persistence\Map\SpyCustomerAddressTableMap;
use Spryker\Shared\Customer\CustomerConstants;
use Spryker\Zed\Customer\Dependency\Service\CustomerToUtilSanitizeInterface;
use Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface;
use Spryker\Zed\Gui\Communication\Table\AbstractTable;
use Spryker\Zed\Gui\Communication\Table\TableConfiguration;
Expand All @@ -32,14 +33,24 @@ class AddressTable extends AbstractTable
*/
protected $idCustomer;

/**
* @var \Spryker\Zed\Customer\Dependency\Service\CustomerToUtilSanitizeInterface
*/
protected $utilSanitize;

/**
* @param \Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface $customerQueryContainer
* @param int $idCustomer
* @param \Spryker\Zed\Customer\Dependency\Service\CustomerToUtilSanitizeInterface $utilSanitize
*/
public function __construct(CustomerQueryContainerInterface $customerQueryContainer, $idCustomer)
{
public function __construct(
CustomerQueryContainerInterface $customerQueryContainer,
$idCustomer,
CustomerToUtilSanitizeInterface $utilSanitize
) {
$this->customerQueryContainer = $customerQueryContainer;
$this->idCustomer = $idCustomer;
$this->utilSanitize = $utilSanitize;
}

/**
Expand Down Expand Up @@ -125,7 +136,8 @@ protected function prepareData(TableConfiguration $config)
$tags[] = '<span class="label label-danger" title="Default shipping address">SHIPPING</span>';
}

$lines[$key][SpyCustomerAddressTableMap::COL_ADDRESS1] = (!empty($tags) ? implode('&nbsp;', $tags) . '&nbsp;' : '') . $lines[$key][SpyCustomerAddressTableMap::COL_ADDRESS1];
$address = $this->utilSanitize->escapeHtml($lines[$key][SpyCustomerAddressTableMap::COL_ADDRESS1]);
$lines[$key][SpyCustomerAddressTableMap::COL_ADDRESS1] = (!empty($tags) ? implode('&nbsp;', $tags) . '&nbsp;' : '') . $address;

$lines[$key][self::ACTIONS] = $this->buildLinks($value);
}
Expand Down
18 changes: 18 additions & 0 deletions src/Spryker/Zed/Customer/CustomerDependencyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Spryker\Zed\Customer\Dependency\Facade\CustomerToLocaleBridge;
use Spryker\Zed\Customer\Dependency\Facade\CustomerToMailBridge;
use Spryker\Zed\Customer\Dependency\Facade\CustomerToSequenceNumberBridge;
use Spryker\Zed\Customer\Dependency\Service\CustomerToUtilSanitizeBridge;
use Spryker\Zed\Kernel\AbstractBundleDependencyProvider;
use Spryker\Zed\Kernel\Container;

Expand All @@ -28,6 +29,8 @@ class CustomerDependencyProvider extends AbstractBundleDependencyProvider
const PLUGINS_CUSTOMER_ANONYMIZER = 'PLUGINS_CUSTOMER_ANONYMIZER';
const PLUGINS_CUSTOMER_TRANSFER_EXPANDER = 'PLUGINS_CUSTOMER_TRANSFER_EXPANDER';

const SERVICE_UTIL_SANITIZE = 'SERVICE_UTIL_SANITIZE';

/**
* @param \Spryker\Zed\Kernel\Container $container
*
Expand Down Expand Up @@ -77,6 +80,7 @@ public function provideCommunicationLayerDependencies(Container $container)

$container = $this->addStore($container);
$container = $this->addCustomerTransferExpanderPlugins($container);
$container = $this->addUtilSanitizeService($container);

return $container;
}
Expand Down Expand Up @@ -138,4 +142,18 @@ protected function getCustomerTransferExpanderPlugins()
{
return [];
}

/**
* @param \Spryker\Zed\Kernel\Container $container
*
* @return \Spryker\Zed\Kernel\Container
*/
protected function addUtilSanitizeService(Container $container)
{
$container[static::SERVICE_UTIL_SANITIZE] = function (Container $container) {
return new CustomerToUtilSanitizeBridge($container->getLocator()->utilSanitize()->service());
};

return $container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © 2017-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Zed\Customer\Dependency\Service;

class CustomerToUtilSanitizeBridge implements CustomerToUtilSanitizeInterface
{
/**
* @var \Spryker\Service\UtilSanitize\UtilSanitizeServiceInterface
*/
protected $utilSanitizeService;

/**
* @param \Spryker\Service\UtilSanitize\UtilSanitizeServiceInterface $utilSanitizeService
*/
public function __construct($utilSanitizeService)
{
$this->utilSanitizeService = $utilSanitizeService;
}

/**
* @param string $text
* @param bool $double
* @param string|null $charset
*
* @return string
*/
public function escapeHtml($text, $double = true, $charset = null)
{
return $this->utilSanitizeService->escapeHtml($text, $double, $charset);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © 2017-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Zed\Customer\Dependency\Service;

interface CustomerToUtilSanitizeInterface
{
/**
* @param string $text
* @param bool $double
* @param string|null $charset
*
* @return string
*/
public function escapeHtml($text, $double = true, $charset = null);
}

0 comments on commit 4ffedb8

Please sign in to comment.