-
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.
added browser version check on plugin (missed).
- Loading branch information
1 parent
dbac2e1
commit 9c84bc6
Showing
7 changed files
with
75 additions
and
46 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,64 @@ | ||
<?php | ||
namespace Veriteworks\CookieFix\Plugin\Session; | ||
|
||
use Magento\Framework\HTTP\Header; | ||
use Magento\Framework\Session\Config; | ||
use Veriteworks\CookieFix\Validator\SameSite; | ||
|
||
class AddSameSite | ||
{ | ||
/** | ||
* @var SameSite | ||
*/ | ||
private $validator; | ||
/** | ||
* @var Header | ||
*/ | ||
private $header; | ||
|
||
/** | ||
* AddSameSite constructor. | ||
* @param SameSite $validator | ||
* @param Header $header | ||
*/ | ||
public function __construct( | ||
SameSite $validator, | ||
Header $header | ||
) { | ||
$this->validator = $validator; | ||
$this->header = $header; | ||
} | ||
|
||
/** | ||
* @param \Magento\Framework\Session\Config $subject | ||
* @param $result | ||
* @param string $cookiePath | ||
* @param string|null $default | ||
*/ | ||
public function afterSetCookiePath( | ||
Config $subject, | ||
$result, | ||
$cookiePath, | ||
$default = null | ||
) { | ||
$version = PHP_VERSION_ID; | ||
$agent = $this->header->getHttpUserAgent(); | ||
$sameSite = $this->validator->shouldSendSameSiteNone($agent); | ||
|
||
if (!$sameSite) { | ||
return $result; | ||
} | ||
|
||
if ($version >= 70300) { | ||
$subject->setOption('session.cookie_samesite', 'None'); | ||
} else { | ||
$path = $subject->getCookiePath(); | ||
if (!preg_match('/SameSite/', $path)) { | ||
$path .= '; SameSite=None'; | ||
$subject->setOption('session.cookie_path', $path); | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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.
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 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 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 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