Skip to content
This repository has been archived by the owner on Jun 25, 2018. It is now read-only.

Commit

Permalink
Updating symfony/symfony (v3.2.6 => v3.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
romainnorberg committed Apr 8, 2017
1 parent 2edc0e4 commit 4e0ac05
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 59 deletions.
8 changes: 7 additions & 1 deletion app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ imports:

services:
serializer.mapping.cache.apcu:
class: Doctrine\Common\Cache\ApcuCache
class: Doctrine\Common\Cache\ApcuCache

app.twig_extension:
class: AppBundle\Twig\RawDescriptionExtension
public: false
tags:
- { name: twig.extension }
1 change: 1 addition & 0 deletions bin/simple-phpunit
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"minimum-stability": "stable",
"require": {
"php": ">=7.0",
"symfony/symfony": "3.2.6",
"symfony/symfony": "3.2.7",
"twig/twig": "~2.2",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
Expand Down
40 changes: 22 additions & 18 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<hr>

<div class="content">
{{ include(template_from_string(project_type.content|raw)) }}
{{ include(template_from_string(project_type.content|rawdescr)) }}
</div>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions src/AppBundle/Twig/RawDescriptionExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace AppBundle\Twig;

class RawDescriptionExtension extends \Twig_Extension
{
public function getFilters()
{
return array(
new \Twig_SimpleFilter('rawdescr', array($this, 'rawdescrFilter'), array('is_safe' => array('html'))),
);
}

public function rawdescrFilter($descr)
{
return $descr;
}

public function getName()
{
return 'eshop_extension';
}
}
95 changes: 57 additions & 38 deletions var/bootstrap.php.cache
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ protected $locale;
protected $defaultLocale ='en';
protected static $formats;
protected static $requestFactory;
private $isForwardedValid = true;
private static $forwardedParams = array(
self::HEADER_CLIENT_IP =>'for',
self::HEADER_CLIENT_HOST =>'host',
self::HEADER_CLIENT_PROTO =>'proto',
self::HEADER_CLIENT_PORT =>'host',
);
public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
{
$this->initialize($query, $request, $attributes, $cookies, $files, $server, $content);
Expand Down Expand Up @@ -706,32 +713,11 @@ $this->session = $session;
}
public function getClientIps()
{
$clientIps = array();
$ip = $this->server->get('REMOTE_ADDR');
if (!$this->isFromTrustedProxy()) {
return array($ip);
}
$hasTrustedForwardedHeader = self::$trustedHeaders[self::HEADER_FORWARDED] && $this->headers->has(self::$trustedHeaders[self::HEADER_FORWARDED]);
$hasTrustedClientIpHeader = self::$trustedHeaders[self::HEADER_CLIENT_IP] && $this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP]);
if ($hasTrustedForwardedHeader) {
$forwardedHeader = $this->headers->get(self::$trustedHeaders[self::HEADER_FORWARDED]);
preg_match_all('{(for)=("?\[?)([a-z0-9\.:_\-/]*)}', $forwardedHeader, $matches);
$forwardedClientIps = $matches[3];
$forwardedClientIps = $this->normalizeAndFilterClientIps($forwardedClientIps, $ip);
$clientIps = $forwardedClientIps;
}
if ($hasTrustedClientIpHeader) {
$xForwardedForClientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
$xForwardedForClientIps = $this->normalizeAndFilterClientIps($xForwardedForClientIps, $ip);
$clientIps = $xForwardedForClientIps;
}
if ($hasTrustedForwardedHeader && $hasTrustedClientIpHeader && $forwardedClientIps !== $xForwardedForClientIps) {
throw new ConflictingHeadersException('The request has both a trusted Forwarded header and a trusted Client IP header, conflicting with each other with regards to the originating IP addresses of the request. This is the result of a misconfiguration. You should either configure your proxy only to send one of these headers, or configure Symfony to distrust one of them.');
}
if (!$hasTrustedForwardedHeader && !$hasTrustedClientIpHeader) {
return $this->normalizeAndFilterClientIps(array(), $ip);
}
return $clientIps;
return $this->getTrustedValues(self::HEADER_CLIENT_IP, $ip) ?: array($ip);
}
public function getClientIp()
{
Expand Down Expand Up @@ -769,15 +755,13 @@ return $this->isSecure() ?'https':'http';
}
public function getPort()
{
if ($this->isFromTrustedProxy()) {
if (self::$trustedHeaders[self::HEADER_CLIENT_PORT] && $port = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PORT])) {
return $port;
}
if (self::$trustedHeaders[self::HEADER_CLIENT_PROTO] &&'https'=== $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO],'http')) {
return 443;
}
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_PORT)) {
$host = $host[0];
} elseif ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_HOST)) {
$host = $host[0];
} elseif (!$host = $this->headers->get('HOST')) {
return $this->server->get('SERVER_PORT');
}
if ($host = $this->headers->get('HOST')) {
if ($host[0] ==='[') {
$pos = strpos($host,':', strrpos($host,']'));
} else {
Expand All @@ -788,8 +772,6 @@ return (int) substr($host, $pos + 1);
}
return'https'=== $this->getScheme() ? 443 : 80;
}
return $this->server->get('SERVER_PORT');
}
public function getUser()
{
return $this->headers->get('PHP_AUTH_USER');
Expand Down Expand Up @@ -870,17 +852,16 @@ return''=== $qs ? null : $qs;
}
public function isSecure()
{
if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_PROTO] && $proto = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_PROTO])) {
return in_array(strtolower(current(explode(',', $proto))), array('https','on','ssl','1'));
if ($this->isFromTrustedProxy() && $proto = $this->getTrustedValues(self::HEADER_CLIENT_PROTO)) {
return in_array(strtolower($proto[0]), array('https','on','ssl','1'), true);
}
$https = $this->server->get('HTTPS');
return !empty($https) &&'off'!== strtolower($https);
}
public function getHost()
{
if ($this->isFromTrustedProxy() && self::$trustedHeaders[self::HEADER_CLIENT_HOST] && $host = $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_HOST])) {
$elements = explode(',', $host);
$host = $elements[count($elements) - 1];
if ($this->isFromTrustedProxy() && $host = $this->getTrustedValues(self::HEADER_CLIENT_HOST)) {
$host = $host[0];
} elseif (!$host = $this->headers->get('HOST')) {
if (!$host = $this->server->get('SERVER_NAME')) {
$host = $this->server->get('SERVER_ADDR','');
Expand Down Expand Up @@ -1187,6 +1168,9 @@ $baseUrl ='/'.$seg.$baseUrl;
} while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
}
$requestUri = $this->getRequestUri();
if ($requestUri !==''&& $requestUri[0] !=='/') {
$requestUri ='/'.$requestUri;
}
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) {
return $prefix;
}
Expand Down Expand Up @@ -1229,9 +1213,12 @@ $baseUrl = $this->getBaseUrl();
if (null === ($requestUri = $this->getRequestUri())) {
return'/';
}
if ($pos = strpos($requestUri,'?')) {
if (false !== $pos = strpos($requestUri,'?')) {
$requestUri = substr($requestUri, 0, $pos);
}
if ($requestUri !==''&& $requestUri[0] !=='/') {
$requestUri ='/'.$requestUri;
}
$pathInfo = substr($requestUri, strlen($baseUrl));
if (null !== $baseUrl && (false === $pathInfo ||''=== $pathInfo)) {
return'/';
Expand Down Expand Up @@ -1280,8 +1267,40 @@ public function isFromTrustedProxy()
{
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
}
private function getTrustedValues($type, $ip = null)
{
$clientValues = array();
$forwardedValues = array();
if (self::$trustedHeaders[$type] && $this->headers->has(self::$trustedHeaders[$type])) {
foreach (explode(',', $this->headers->get(self::$trustedHeaders[$type])) as $v) {
$clientValues[] = (self::HEADER_CLIENT_PORT === $type ?'0.0.0.0:':'').trim($v);
}
}
if (self::$trustedHeaders[self::HEADER_FORWARDED] && $this->headers->has(self::$trustedHeaders[self::HEADER_FORWARDED])) {
$forwardedValues = $this->headers->get(self::$trustedHeaders[self::HEADER_FORWARDED]);
$forwardedValues = preg_match_all(sprintf('{(?:%s)=(?:"?\[?)([a-zA-Z0-9\.:_\-/]*+)}', self::$forwardedParams[$type]), $forwardedValues, $matches) ? $matches[1] : array();
}
if (null !== $ip) {
$clientValues = $this->normalizeAndFilterClientIps($clientValues, $ip);
$forwardedValues = $this->normalizeAndFilterClientIps($forwardedValues, $ip);
}
if ($forwardedValues === $clientValues || !$clientValues) {
return $forwardedValues;
}
if (!$forwardedValues) {
return $clientValues;
}
if (!$this->isForwardedValid) {
return null !== $ip ? array('0.0.0.0', $ip) : array();
}
$this->isForwardedValid = false;
throw new ConflictingHeadersException(sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::$trustedHeaders[self::HEADER_FORWARDED], self::$trustedHeaders[$type]));
}
private function normalizeAndFilterClientIps(array $clientIps, $ip)
{
if (!$clientIps) {
return array();
}
$clientIps[] = $ip; $firstTrustedIp = null;
foreach ($clientIps as $key => $clientIp) {
if (preg_match('{((?:\d+\.){3}\d+)\:\d+}', $clientIp, $match)) {
Expand Down

0 comments on commit 4e0ac05

Please sign in to comment.