MediaWiki REL1_41
ProxyLookup.php
Go to the documentation of this file.
1<?php
2
22namespace MediaWiki\Request;
23
26use Wikimedia\IPSet;
27
32
34 private $proxyServers;
35
37 private $proxyServersComplex;
38
40 private $proxyIPSet;
41
43 private $hookRunner;
44
50 public function __construct(
51 $proxyServers,
52 $proxyServersComplex,
53 HookContainer $hookContainer
54 ) {
55 $this->proxyServers = $proxyServers;
56 $this->proxyServersComplex = $proxyServersComplex;
57 $this->hookRunner = new HookRunner( $hookContainer );
58 }
59
66 public function isConfiguredProxy( $ip ) {
67 // Quick check of known singular proxy servers
68 if ( in_array( $ip, $this->proxyServers, true ) ) {
69 return true;
70 }
71
72 // Check against addresses and CIDR nets in the complex list
73 if ( !$this->proxyIPSet ) {
74 $this->proxyIPSet = new IPSet( $this->proxyServersComplex );
75 }
76 return $this->proxyIPSet->match( $ip );
77 }
78
87 public function isTrustedProxy( $ip ) {
88 $trusted = $this->isConfiguredProxy( $ip );
89 $this->hookRunner->onIsTrustedProxy( $ip, $trusted );
90 return $trusted;
91 }
92}
93
97class_alias( ProxyLookup::class, 'ProxyLookup' );
This class provides an implementation of the core hook interfaces, forwarding hook calls to HookConta...
isConfiguredProxy( $ip)
Checks if an IP matches a proxy we've configured.
__construct( $proxyServers, $proxyServersComplex, HookContainer $hookContainer)
isTrustedProxy( $ip)
Checks if an IP is a trusted proxy provider.