Skip to content

Commit 6b94e66

Browse files
committed
B2B-3035: Add Salting Mechanism to GraphQL Resolver Cache Key Generation
1 parent 70f8114 commit 6b94e66

File tree

1 file changed

+12
-1
lines changed
  • app/code/Magento/GraphQlResolverCache/Model/Resolver/Result/CacheKey

1 file changed

+12
-1
lines changed

app/code/Magento/GraphQlResolverCache/Model/Resolver/Result/CacheKey/Calculator.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey;
99

10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\Config\ConfigOptionsListConstants;
1012
use Magento\Framework\ObjectManagerInterface;
1113
use Magento\GraphQl\Model\Query\ContextFactoryInterface;
1214
use Magento\GraphQlResolverCache\Model\Resolver\Result\ValueProcessorInterface;
@@ -16,6 +18,11 @@
1618
*/
1719
class Calculator
1820
{
21+
/**
22+
* @var DeploymentConfig
23+
*/
24+
private $deploymentConfig;
25+
1926
/**
2027
* @var ContextFactoryInterface
2128
*/
@@ -42,17 +49,20 @@ class Calculator
4249
private ValueProcessorInterface $valueProcessor;
4350

4451
/**
52+
* @param DeploymentConfig $deploymentConfig
4553
* @param ContextFactoryInterface $contextFactory
4654
* @param ObjectManagerInterface $objectManager
4755
* @param ValueProcessorInterface $valueProcessor
4856
* @param string[] $factorProviders
4957
*/
5058
public function __construct(
59+
DeploymentConfig $deploymentConfig,
5160
ContextFactoryInterface $contextFactory,
5261
ObjectManagerInterface $objectManager,
5362
ValueProcessorInterface $valueProcessor,
5463
array $factorProviders = []
5564
) {
65+
$this->deploymentConfig = $deploymentConfig;
5666
$this->contextFactory = $contextFactory;
5767
$this->factorProviders = $factorProviders;
5868
$this->objectManager = $objectManager;
@@ -76,7 +86,8 @@ public function calculateCacheKey(?array $parentData = null): ?string
7686
try {
7787
$this->initializeFactorProviderInstances();
7888
$factors = $this->getFactors($parentData);
79-
$keysString = strtoupper(implode('|', array_values($factors)));
89+
$salt = (string)$this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
90+
$keysString = strtoupper(implode('|', array_values($factors))). "|$salt";
8091
return hash('sha256', $keysString);
8192
} catch (\Throwable $e) {
8293
throw new CalculationException($e->getMessage(), $e->getCode(), $e);

0 commit comments

Comments
 (0)