4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
32 private $proxyServers;
37 private $proxyServersComplex;
45 * @param string[] $proxyServers Simple list of IPs
46 * @param string[] $proxyServersComplex Complex list of IPs/ranges
48 public function __construct( $proxyServers, $proxyServersComplex ) {
49 $this->proxyServers
= $proxyServers;
50 $this->proxyServersComplex
= $proxyServersComplex;
54 * Checks if an IP matches a proxy we've configured
59 public function isConfiguredProxy( $ip ) {
60 // Quick check of known singular proxy servers
61 if ( in_array( $ip, $this->proxyServers
) ) {
65 // Check against addresses and CIDR nets in the complex list
66 if ( !$this->proxyIPSet
) {
67 $this->proxyIPSet
= new IPSet( $this->proxyServersComplex
);
69 return $this->proxyIPSet
->match( $ip );
73 * Checks if an IP is a trusted proxy provider.
74 * Useful to tell if X-Forwarded-For data is possibly bogus.
75 * CDN cache servers for the site are whitelisted.
80 public function isTrustedProxy( $ip ) {
81 $trusted = $this->isConfiguredProxy( $ip );
82 Hooks
::run( 'IsTrustedProxy', [ &$ip, &$trusted ] );