1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-05 13:47:37 +02:00

Update composer and fix proxy detection

This commit is contained in:
trendschau
2024-06-13 23:38:55 +02:00
parent 23d3d8a0d8
commit a8a72db90f
3 changed files with 101 additions and 87 deletions

View File

@@ -17,7 +17,7 @@
"require": {
"php": "^8.0",
"slim/slim": "4.*",
"slim/psr7": "dev-master",
"slim/psr7": "^1.5",
"php-di/php-di": "^6.3",
"php-di/slim-bridge": "^3.2",
"slim/twig-view": "^3.3",

97
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a9a1d2aca168c73196f5ba99dc56a43b",
"content-hash": "c3d172c51dcde3725ee22925a93865a5",
"packages": [
{
"name": "akrabat/proxy-detection-middleware",
@@ -1143,30 +1143,30 @@
},
{
"name": "slim/csrf",
"version": "1.4.0",
"version": "1.5.0",
"source": {
"type": "git",
"url": "https://github.com/slimphp/Slim-Csrf.git",
"reference": "f66be9740283ed4f432535aff3623540e178013a"
"reference": "179cbcf40ee1d246d4906aefed42d3e62066974b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim-Csrf/zipball/f66be9740283ed4f432535aff3623540e178013a",
"reference": "f66be9740283ed4f432535aff3623540e178013a",
"url": "https://api.github.com/repos/slimphp/Slim-Csrf/zipball/179cbcf40ee1d246d4906aefed42d3e62066974b",
"reference": "179cbcf40ee1d246d4906aefed42d3e62066974b",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0",
"psr/http-factory": "^1.1",
"psr/http-message": "^1.0 || ^2.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"phpspec/prophecy": "^1.18",
"phpspec/prophecy-phpunit": "^2.1",
"phpspec/prophecy": "^1.19",
"phpspec/prophecy-phpunit": "^2.2",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.8"
"squizlabs/php_codesniffer": "^3.10"
},
"type": "library",
"autoload": {
@@ -1195,9 +1195,9 @@
],
"support": {
"issues": "https://github.com/slimphp/Slim-Csrf/issues",
"source": "https://github.com/slimphp/Slim-Csrf/tree/1.4.0"
"source": "https://github.com/slimphp/Slim-Csrf/tree/1.5.0"
},
"time": "2024-01-22T09:08:27+00:00"
"time": "2024-06-08T16:37:18+00:00"
},
{
"name": "slim/flash",
@@ -1253,22 +1253,22 @@
},
{
"name": "slim/psr7",
"version": "dev-master",
"version": "1.7.0",
"source": {
"type": "git",
"url": "https://github.com/slimphp/Slim-Psr7.git",
"reference": "08dbc65964bf2c1fb0fe54256322a272cd02596b"
"reference": "753e9646def5ff4db1a06e5cf4ef539bfd30f467"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim-Psr7/zipball/08dbc65964bf2c1fb0fe54256322a272cd02596b",
"reference": "08dbc65964bf2c1fb0fe54256322a272cd02596b",
"url": "https://api.github.com/repos/slimphp/Slim-Psr7/zipball/753e9646def5ff4db1a06e5cf4ef539bfd30f467",
"reference": "753e9646def5ff4db1a06e5cf4ef539bfd30f467",
"shasum": ""
},
"require": {
"fig/http-message-util": "^1.1.5",
"php": "^8.0",
"psr/http-factory": "^1.0",
"psr/http-factory": "^1.1",
"psr/http-message": "^1.0 || ^2.0",
"ralouphie/getallheaders": "^3.0",
"symfony/polyfill-php80": "^1.29"
@@ -1284,11 +1284,10 @@
"php-http/psr7-integration-tests": "1.3.0",
"phpspec/prophecy": "^1.19",
"phpspec/prophecy-phpunit": "^2.2",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^9.6",
"squizlabs/php_codesniffer": "^3.9"
"squizlabs/php_codesniffer": "^3.10"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
@@ -1330,22 +1329,22 @@
],
"support": {
"issues": "https://github.com/slimphp/Slim-Psr7/issues",
"source": "https://github.com/slimphp/Slim-Psr7/tree/master"
"source": "https://github.com/slimphp/Slim-Psr7/tree/1.7.0"
},
"time": "2024-03-03T21:28:35+00:00"
"time": "2024-06-08T14:48:17+00:00"
},
{
"name": "slim/slim",
"version": "4.13.0",
"version": "4.14.0",
"source": {
"type": "git",
"url": "https://github.com/slimphp/Slim.git",
"reference": "038fd5713d5a41636fdff0e8dcceedecdd17fc17"
"reference": "5943393b88716eb9e82c4161caa956af63423913"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/038fd5713d5a41636fdff0e8dcceedecdd17fc17",
"reference": "038fd5713d5a41636fdff0e8dcceedecdd17fc17",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/5943393b88716eb9e82c4161caa956af63423913",
"reference": "5943393b88716eb9e82c4161caa956af63423913",
"shasum": ""
},
"require": {
@@ -1353,7 +1352,7 @@
"nikic/fast-route": "^1.3",
"php": "^7.4 || ^8.0",
"psr/container": "^1.0 || ^2.0",
"psr/http-factory": "^1.0",
"psr/http-factory": "^1.1",
"psr/http-message": "^1.1 || ^2.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
@@ -1370,11 +1369,12 @@
"nyholm/psr7-server": "^1.1",
"phpspec/prophecy": "^1.19",
"phpspec/prophecy-phpunit": "^2.1",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^9.6",
"slim/http": "^1.3",
"slim/psr7": "^1.6",
"squizlabs/php_codesniffer": "^3.9"
"squizlabs/php_codesniffer": "^3.10",
"vimeo/psalm": "^5.24"
},
"suggest": {
"ext-simplexml": "Needed to support XML format in BodyParsingMiddleware",
@@ -1447,7 +1447,7 @@
"type": "tidelift"
}
],
"time": "2024-03-03T21:25:30+00:00"
"time": "2024-06-13T08:54:48+00:00"
},
{
"name": "slim/twig-view",
@@ -1583,16 +1583,16 @@
},
{
"name": "symfony/event-dispatcher",
"version": "v5.4.39",
"version": "v5.4.40",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "d40fae9fd85c762b6ba378152fdd1157a85d7e4f"
"reference": "a54e2a8a114065f31020d6a89ede83e34c3b27a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d40fae9fd85c762b6ba378152fdd1157a85d7e4f",
"reference": "d40fae9fd85c762b6ba378152fdd1157a85d7e4f",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/a54e2a8a114065f31020d6a89ede83e34c3b27a4",
"reference": "a54e2a8a114065f31020d6a89ede83e34c3b27a4",
"shasum": ""
},
"require": {
@@ -1648,7 +1648,7 @@
"description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/event-dispatcher/tree/v5.4.39"
"source": "https://github.com/symfony/event-dispatcher/tree/v5.4.40"
},
"funding": [
{
@@ -1664,7 +1664,7 @@
"type": "tidelift"
}
],
"time": "2024-04-18T08:26:06+00:00"
"time": "2024-05-31T14:33:22+00:00"
},
{
"name": "symfony/event-dispatcher-contracts",
@@ -1747,16 +1747,16 @@
},
{
"name": "symfony/finder",
"version": "v5.4.39",
"version": "v5.4.40",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "f6a96e4fcd468a25fede16ee665f50ced856bd0a"
"reference": "f51cff4687547641c7d8180d74932ab40b2205ce"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/f6a96e4fcd468a25fede16ee665f50ced856bd0a",
"reference": "f6a96e4fcd468a25fede16ee665f50ced856bd0a",
"url": "https://api.github.com/repos/symfony/finder/zipball/f51cff4687547641c7d8180d74932ab40b2205ce",
"reference": "f51cff4687547641c7d8180d74932ab40b2205ce",
"shasum": ""
},
"require": {
@@ -1790,7 +1790,7 @@
"description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/finder/tree/v5.4.39"
"source": "https://github.com/symfony/finder/tree/v5.4.40"
},
"funding": [
{
@@ -1806,7 +1806,7 @@
"type": "tidelift"
}
],
"time": "2024-04-18T08:26:06+00:00"
"time": "2024-05-31T14:33:22+00:00"
},
{
"name": "symfony/polyfill-ctype",
@@ -2125,16 +2125,16 @@
},
{
"name": "symfony/yaml",
"version": "v5.4.39",
"version": "v5.4.40",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "bc780e16879000f77a1022163c052f5323b5e640"
"reference": "81cad0ceab3d61fe14fe941ff18a230ac9c80f83"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/bc780e16879000f77a1022163c052f5323b5e640",
"reference": "bc780e16879000f77a1022163c052f5323b5e640",
"url": "https://api.github.com/repos/symfony/yaml/zipball/81cad0ceab3d61fe14fe941ff18a230ac9c80f83",
"reference": "81cad0ceab3d61fe14fe941ff18a230ac9c80f83",
"shasum": ""
},
"require": {
@@ -2180,7 +2180,7 @@
"description": "Loads and dumps YAML files",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/yaml/tree/v5.4.39"
"source": "https://github.com/symfony/yaml/tree/v5.4.40"
},
"funding": [
{
@@ -2196,7 +2196,7 @@
"type": "tidelift"
}
],
"time": "2024-04-23T11:57:27+00:00"
"time": "2024-05-31T14:33:22+00:00"
},
{
"name": "twig/twig",
@@ -2341,7 +2341,6 @@
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"slim/psr7": 20,
"erusev/parsedown-extra": 20
},
"prefer-stable": true,

View File

@@ -27,26 +27,17 @@ class Urlinfo
parse_str($query, $params);
# proxy detection
if(isset($settings['proxy']) && $settings['proxy'] && isset($_SERVER['HTTP_X_FORWARDED_HOST']))
if(isset($settings['proxy']) && $settings['proxy'])
{
$trustedProxies = ( isset($settings['trustedproxies']) && !empty($settings['trustedproxies']) ) ? explode(",", $settings['trustedproxies']) : [];
$proxyuri = self::updateUri($uri, $trustedProxies);
if($proxyuri)
if(self::checkIp($trustedProxies))
{
# use uri from proxy
$uri = $proxyuri;
$uri = self::updateHost($uri);
# standard basepath is empty
$basepath = "";
# if proxy has basepath, then
if (isset($_SERVER['HTTP_X_FORWARDED_PREFIX']))
{
# Use X-Forwarded-Prefix if available
$basepath = rtrim($_SERVER['HTTP_X_FORWARDED_PREFIX'], '/') . '/';
}
$uri = self::updateHost($uri);
$basepath = self::updateBasepath($basepath);
}
}
@@ -81,29 +72,8 @@ class Urlinfo
return $uri;
}
private static function updateUri($uri, $trustedProxies)
private static function updateProto($uri)
{
# optionally check trusted proxies
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? null;
if (
$ipAddress
&& !empty($trustedProxies)
&& !in_array($ipAddress, $trustedProxies)
)
{
return false;
}
# get scheme from proxy
$scheme = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? null;
if (
$scheme
&& in_array($scheme, ['http', 'https'])
)
{
$uri = $uri->withScheme($scheme);
}
# get host from proxy
$host = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? null;
if (
@@ -122,4 +92,49 @@ class Urlinfo
return $uri;
}
private static function updateHost($uri)
{
# get scheme from proxy
$scheme = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? null;
if (
$scheme
&& in_array($scheme, ['http', 'https'])
)
{
$uri = $uri->withScheme($scheme);
}
return $uri;
}
private static function updateBasepath($basepath)
{
# $basepath = "";
# if proxy has basepath, then
if (isset($_SERVER['HTTP_X_FORWARDED_PREFIX']))
{
# Use X-Forwarded-Prefix if available
$basepath = rtrim($_SERVER['HTTP_X_FORWARDED_PREFIX'], '/') . '/';
}
return $basepath;
}
private static function checkIp($trustedProxies)
{
# optionally check trusted proxies
$ipAddress = $_SERVER['REMOTE_ADDR'] ?? null;
if (
$ipAddress
&& !empty($trustedProxies)
&& !in_array($ipAddress, $trustedProxies)
)
{
return false;
}
return true;
}
}