Skip to content

Commit

Permalink
FIXED wrong URL detection
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Jun 1, 2017
1 parent 049c043 commit 26b1ca0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 1 addition & 2 deletions Api/ShieldInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ interface ShieldInterface
{
/**
* Return true if should scan request
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function shouldScan(\Magento\Framework\App\RequestInterface $request);
public function shouldScan();

/**
* Scan HTTP request and return false if no hack attempt has been detected
Expand Down
23 changes: 14 additions & 9 deletions Model/Shield.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\App\DeploymentConfig\Reader as DeploymentConfigReader;
use MSP\SecuritySuiteCommon\Api\UtilsInterface;
use MSP\Shield\Api\ShieldInterface;

class Shield implements ShieldInterface
Expand Down Expand Up @@ -59,42 +60,46 @@ class Shield implements ShieldInterface
*/
private $configReader;

/**
* @var UtilsInterface
*/
private $utils;

public function __construct(
ScopeConfigInterface $scopeConfig,
Reader $reader,
Cache $cache,
DirectoryList $directoryList,
DeploymentConfigReader $configReader
UtilsInterface $utils
) {
$this->scopeConfig = $scopeConfig;
$this->directoryList = $directoryList;
$this->reader = $reader;
$this->cache = $cache;
$this->configReader = $configReader;
$this->utils = $utils;
}

/**
* Return true if should scan request
* @param \Magento\Framework\App\RequestInterface $request
* @return bool
*/
public function shouldScan(\Magento\Framework\App\RequestInterface $request)
public function shouldScan()
{
$config = $this->configReader->load();
$adminPath = $config['backend']['frontName'];

$enabledBackend = !! $this->scopeConfig->getValue(static::XML_PATH_ENABLED_BACKEND);
if ((strpos($request->getRequestUri(), "/$adminPath/") !== false) && !$enabledBackend) {
if ($this->utils->isBackendUri() && !$enabledBackend) {
return false;
}

$adminPath = $this->utils->getBackendPath();

$whiteList = trim($this->scopeConfig->getValue(static::XML_PATH_URI_WHITELIST));
$whiteList = str_replace('$admin', $adminPath, $whiteList);
$whiteList = preg_split('/[\r\n\s,]+/', $whiteList);
$whiteList[] = '/msp_security_suite/stop/index/';

$requestUri = $this->utils->getSanitizedUri();
foreach ($whiteList as $uri) {
if (strpos($request->getRequestUri(), $uri) !== false) {
if (strpos($requestUri, $uri) === 0) {
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"description": "Advanced Intrusion Prevention System for Magento2 - Member of MageSpecialist SecuritySuite",
"require": {
"php": "~7.0.0",
"msp/phpids": "*",
"msp/phpids": ">=1.0.1",
"msp/common": "*",
"msp/security-suite-common": "*"
"msp/security-suite-common": ">=1.0.3"
},
"suggest": {
"msp/security-suite": "Full MageSpecialist Security Suite"
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MSP_Shield" setup_version="1.0.3">
<module name="MSP_Shield" setup_version="1.0.4">
</module>
</config>

0 comments on commit 26b1ca0

Please sign in to comment.