예제 #1
0
 /**
  * Check if a request comes from a CloudFlare IP.
  * @return bool
  */
 public function isCloudFlareIP()
 {
     // Store original remote address in $original_ip
     $this->original_ip = $this->getOriginalIP();
     if (!isset($this->original_ip)) {
         return false;
     }
     // Process original_ip if on cloudflare
     $ip_ranges = $this->cf_ipv4;
     if (IpUtils::isIpv6($this->original_ip)) {
         $ip_ranges = $this->cf_ipv6;
     }
     foreach ($ip_ranges as $range) {
         if (IpUtils::checkIp($this->original_ip, $range)) {
             return true;
         }
     }
     return false;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function matches(Request $request)
 {
     if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
         return false;
     }
     foreach ($this->attributes as $key => $pattern) {
         if (!preg_match('#' . str_replace('#', '\\#', $pattern) . '#', $request->attributes->get($key))) {
             return false;
         }
     }
     if (null !== $this->path) {
         $path = str_replace('#', '\\#', $this->path);
         if (!preg_match('#' . $path . '#', rawurldecode($request->getPathInfo()))) {
             return false;
         }
     }
     if (null !== $this->host && !preg_match('#' . str_replace('#', '\\#', $this->host) . '#i', $request->getHost())) {
         return false;
     }
     if (null !== $this->ip && !IpUtils::checkIp($request->getClientIp(), $this->ip)) {
         return false;
     }
     return true;
 }
예제 #3
0
 public function matches(Request $request)
 {
     if ($this->schemes && !in_array($request->getScheme(), $this->schemes)) {
         return false;
     }
     if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
         return false;
     }
     foreach ($this->attributes as $key => $pattern) {
         if (!preg_match('{' . $pattern . '}', $request->attributes->get($key))) {
             return false;
         }
     }
     if (null !== $this->path && !preg_match('{' . $this->path . '}', rawurldecode($request->getPathInfo()))) {
         return false;
     }
     if (null !== $this->host && !preg_match('{' . $this->host . '}i', $request->getHost())) {
         return false;
     }
     if (IpUtils::checkIp($request->getClientIp(), $this->ips)) {
         return true;
     }
     return count($this->ips) === 0;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function matches(Request $request)
 {
     if ($this->methods && !in_array($request->getMethod(), $this->methods)) {
         return false;
     }
     foreach ($this->attributes as $key => $pattern) {
         if (!preg_match('{' . $pattern . '}', $request->attributes->get($key))) {
             return false;
         }
     }
     if (null !== $this->path && !preg_match('{' . $this->path . '}', rawurldecode($request->getPathInfo()))) {
         return false;
     }
     if (null !== $this->host && !preg_match('{' . $this->host . '}i', $request->getHost())) {
         return false;
     }
     if (IpUtils::checkIp($request->getClientIp(), $this->ips)) {
         return true;
     }
     // Note to future implementors: add additional checks above the
     // foreach above or else your check might not be run!
     return count($this->ips) === 0;
 }
예제 #5
0
 private function isFromTrustedProxy()
 {
     return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
 }