-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to Magento2.4.1 compatible implementation (beta version).
- Loading branch information
1 parent
b4c3a5d
commit d3a948a
Showing
13 changed files
with
146 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
namespace Veriteworks\CookieFix\Model\Config\Source; | ||
|
||
class SameSite | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
return [ | ||
['value' => 'Lax','label' => __('Lax')], | ||
['value' => 'Strict','label' => __('Strict')], | ||
['value' => 'None','label' => __('None')] | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
namespace Veriteworks\CookieFix\Plugin; | ||
|
||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\HTTP\Header; | ||
use Magento\Framework\Stdlib\Cookie\PhpCookieManager; | ||
use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Veriteworks\CookieFix\Validator\SameSite; | ||
|
||
class SwitchSameSite | ||
{ | ||
const CONFIG_PATH = 'web/cookie/samesite'; | ||
const CONFIG_AFFECTED_KEYS = 'web/cookie/affected_keys'; | ||
/** | ||
* @var SameSite | ||
*/ | ||
private $validator; | ||
/** | ||
* @var Header | ||
*/ | ||
private $header; | ||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
private $affectedKeys = []; | ||
|
||
/** | ||
* SwitchSameSite constructor. | ||
* @param Header $header | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param SameSite $validator | ||
*/ | ||
public function __construct( | ||
Header $header, | ||
ScopeConfigInterface $scopeConfig, | ||
SameSite $validator | ||
) { | ||
$this->validator = $validator; | ||
$this->header = $header; | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
|
||
/** | ||
* @param PhpCookieManager $subject | ||
* @param string $name | ||
* @param string $value | ||
* @param PublicCookieMetadata|null $metadata | ||
* @return array | ||
*/ | ||
public function beforeSetPublicCookie( | ||
PhpCookieManager $subject, | ||
$name, | ||
$value, | ||
PublicCookieMetadata $metadata = null | ||
) { | ||
if ($this->isAffectedKeys($name)) { | ||
$agent = $this->header->getHttpUserAgent(); | ||
$sameSite = $this->validator->shouldSendSameSiteNone($agent); | ||
if ($sameSite === false) { | ||
$metadata->setSameSite('None'); | ||
} else { | ||
$config = $this->scopeConfig->getValue(self::CONFIG_PATH, ScopeInterface::SCOPE_STORE); | ||
$metadata->setSameSite($config); | ||
} | ||
} | ||
|
||
return [$name, $value, $metadata]; | ||
} | ||
|
||
private function isAffectedKeys($name) | ||
{ | ||
if (!count($this->affectedKeys)) { | ||
$affectedKeys = $this->scopeConfig->getValue(self::CONFIG_AFFECTED_KEYS, ScopeInterface::SCOPE_STORE); | ||
$this->affectedKeys = explode(',', strtolower($affectedKeys)); | ||
} | ||
|
||
return in_array(strtolower($name), $this->affectedKeys); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.