1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.ec-cube.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\EventListener; |
15
|
|
|
|
16
|
|
|
use Eccube\Request\Context; |
17
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
19
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Safariの一部のバージョンでSameSite=Noneを正しく扱われないバグ対応. |
23
|
|
|
* |
24
|
|
|
* @see https://bugs.webkit.org/show_bug.cgi?id=198181 |
25
|
|
|
*/ |
26
|
|
|
class SameSiteCookieHotfixListener implements EventSubscriberInterface |
27
|
|
|
{ |
28
|
|
|
private static $TARGET_UA_PATTERNS = [ |
29
|
|
|
'/^.*iPhone; CPU iPhone OS 1[0-2].*$/', |
30
|
|
|
'/^.*iPad; CPU OS 1[0-2].*$/', |
31
|
|
|
'/^.*iPod touch; CPU iPhone OS 1[0-2].*$/', |
32
|
|
|
'/^.*Macintosh; Intel Mac OS X.*Version\/1[0-2].*Safari.*$/', |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Context |
37
|
|
|
*/ |
38
|
|
|
protected $requestContext; |
39
|
|
|
|
40
|
|
|
public function __construct(Context $requestContext) |
41
|
|
|
{ |
42
|
|
|
$this->requestContext = $requestContext; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function onKernelRequest(GetResponseEvent $event) |
46
|
|
|
{ |
47
|
|
|
if (!$event->isMasterRequest()) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$ua = $event->getRequest()->headers->get('User-Agent'); |
52
|
|
|
$isUnsupported = array_filter(self::$TARGET_UA_PATTERNS, function ($pattern) use ($ua) { |
53
|
|
|
return preg_match($pattern, $ua); |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
if ($isUnsupported) { |
|
|
|
|
57
|
|
|
$event->setResponse(new Response('お使いのブラウザーではご利用いただけません。')); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public static function getSubscribedEvents() |
65
|
|
|
{ |
66
|
|
|
return [ |
67
|
|
|
'kernel.request' => ['onKernelRequest', 256], |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.