Skip to content

Commit

Permalink
Bugfix check hash value on page load (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-net authored Aug 23, 2023
1 parent 67adf95 commit 55388e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Model/Client/Type/SuggestionType/SuggestionTypeCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class SuggestionTypeCategory extends SuggestionTypeAbstract
*/
protected $urlInstance;

/**
* @var Config
*/
protected $config;

/**
* SuggestionTypeCategory constructor.
* @param CategoryRepository $categoryRepository Empty category model used to resolve urls
Expand Down
5 changes: 5 additions & 0 deletions Model/FilterFormInputProvider/HashInputProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function validateHash($request)
if ($hash === $originalHash) {
$isValid = true;
}
} else {
//hash is empty original url should also be empty
if (empty ($request->getParam('__tw_original_url'))) {
$isValid = true;
}
}

return $isValid;
Expand Down
16 changes: 15 additions & 1 deletion Model/NavigationConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Framework\UrlInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Tweakwise\Magento2Tweakwise\Model\FilterFormInputProvider\HashInputProvider;

/**
* Class NavigationConfig
Expand Down Expand Up @@ -57,6 +58,11 @@ class NavigationConfig implements ArgumentInterface, FilterFormInputProviderInte
*/
protected $request;

/**
* @var HashInputProvider
*/
protected $hashInputProvider;

/**
* NavigationConfig constructor.
* @param Config $config
Expand All @@ -74,7 +80,8 @@ public function __construct(
ProductMetadataInterface $productMetadata,
FilterFormInputProviderInterface $filterFormInputProvider,
Json $jsonSerializer,
Http $request
Http $request,
HashInputProvider $hashInputProvider
) {
$this->config = $config;
$this->jsonSerializer = $jsonSerializer;
Expand All @@ -83,13 +90,20 @@ public function __construct(
$this->productMetadata = $productMetadata;
$this->filterFormInputProvider = $filterFormInputProvider;
$this->request = $request;
$this->hashInputProvider = $hashInputProvider;
}

/**
* @inheritDoc
*/
public function getFilterFormInput(): array
{
//check request for modified values
if (!$this->hashInputProvider->validateHash($this->request)) {
//form is modified, don't accept the request. Should only happen in an xss attack
throw new \InvalidArgumentException('Incorrect/modified form parameters');
}

$filterFormInput = $this->filterFormInputProvider->getFilterFormInput();
unset($filterFormInput['p']);

Expand Down

0 comments on commit 55388e7

Please sign in to comment.