Skip to content

Commit ee47c6f

Browse files
committed
Merge remote-tracking branch 'origin/BUG#AC-2441' into Hammer_Quality_Backlog_GraphQl_13042022
2 parents f675c08 + 738bf47 commit ee47c6f

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

dev/tests/integration/testsuite/Magento/Cookie/Model/Config/Backend/DomainTest.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
namespace Magento\Cookie\Model\Config\Backend;
77

88
use Magento\Framework\Exception\LocalizedException;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use PHPUnit\Framework\TestCase;
911

1012
/**
1113
* Test \Magento\Cookie\Model\Config\Backend\Domain
1214
*
1315
* @magentoAppArea adminhtml
1416
*/
15-
class DomainTest extends \PHPUnit\Framework\TestCase
17+
class DomainTest extends TestCase
1618
{
1719
/**
1820
* @param string $value
@@ -22,10 +24,8 @@ class DomainTest extends \PHPUnit\Framework\TestCase
2224
*/
2325
public function testBeforeSave($value, $exceptionMessage = null)
2426
{
25-
/** @var $domain \Magento\Cookie\Model\Config\Backend\Domain */
26-
$domain = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
27-
\Magento\Cookie\Model\Config\Backend\Domain::class
28-
);
27+
/** @var $domain Domain */
28+
$domain = Bootstrap::getObjectManager()->create(Domain::class);
2929
$domain->setValue($value);
3030
$domain->setPath('path');
3131
try {
@@ -45,18 +45,19 @@ public function testBeforeSave($value, $exceptionMessage = null)
4545
/**
4646
* @return array
4747
*/
48-
public function beforeSaveDataProvider()
48+
public function beforeSaveDataProvider(): array
4949
{
5050
return [
51-
'not string' => [['array'], 'Invalid domain name: must be a string'],
52-
'invalid hostname' => [
51+
'notString' => [['array'], 'Invalid domain name: must be a string'],
52+
'invalidHostname' => [
5353
'http://',
5454
'Invalid domain name: The input does not match the expected structure for a DNS hostname; '
5555
. 'The input does not appear to be a valid URI hostname; '
5656
. 'The input does not appear to be a valid local network name',
5757
],
58-
'valid hostname' => ['hostname.com'],
59-
'empty string' => [''],
58+
'validHostname' => ['hostname.com'],
59+
'emptyString' => [''],
60+
'invalidCharacter' => ['hostname,com', 'Invalid domain name: invalid character in cookie domain'],
6061
];
6162
}
6263
}

lib/internal/Magento/Framework/Session/Config/Validator/CookieDomainValidator.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,43 @@
66

77
namespace Magento\Framework\Session\Config\Validator;
88

9+
use Laminas\Validator\Hostname;
10+
use Magento\Framework\Validator\AbstractValidator;
11+
912
/**
1013
* Session cookie domain validator
1114
*/
12-
class CookieDomainValidator extends \Magento\Framework\Validator\AbstractValidator
15+
class CookieDomainValidator extends AbstractValidator
1316
{
1417
/**
1518
* @inheritDoc
1619
*/
1720
public function isValid($value)
1821
{
1922
$this->_clearMessages();
23+
2024
if (!is_string($value)) {
2125
$this->_addMessages(['must be a string']);
26+
2227
return false;
2328
}
2429

25-
$validator = new \Laminas\Validator\Hostname(\Laminas\Validator\Hostname::ALLOW_ALL);
30+
//Hostname validator allows [;,] and returns the validator as true but,
31+
//these are unacceptable cookie domain characters hence need explicit validation for the same
32+
if (preg_match('/[;,]/', $value)) {
33+
$this->_addMessages(['invalid character in cookie domain']);
34+
35+
return false;
36+
}
37+
38+
$validator = new Hostname(Hostname::ALLOW_ALL);
2639

2740
if (!empty($value) && !$validator->isValid($value)) {
2841
$this->_addMessages($validator->getMessages());
42+
2943
return false;
3044
}
45+
3146
return true;
3247
}
3348
}

0 commit comments

Comments
 (0)