-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
InsecureInstallationListener.php
54 lines (46 loc) · 1.26 KB
/
InsecureInstallationListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
* This file is part of Contao.
*
* Copyright (c) 2005-2017 Leo Feyer
*
* @license LGPL-3.0+
*/
namespace Contao\CoreBundle\EventListener;
use Contao\CoreBundle\Exception\InsecureInstallationException;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
/**
* Ensures that the document root is secure.
*
* @author Dominik Tomasi <https://github.com/dtomasi>
* @author Leo Feyer <https://github.com/leofeyer>
*/
class InsecureInstallationListener
{
/**
* @var array
*/
private $localIps = ['127.0.0.1', 'fe80::1', '::1'];
/**
* Throws an exception if the document root is insecure.
*
* @param GetResponseEvent $event
*
* @throws InsecureInstallationException
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
// Skip the check on localhost
if (in_array($request->getClientIp(), $this->localIps, true)) {
return;
}
// The document root is not in a subdirectory
if ('' === $request->getBasePath()) {
return;
}
throw new InsecureInstallationException(
'Your installation is not secure. Please set the document root to the /web subfolder.'
);
}
}