A free, self-hostable news aggregator…
Fix infinite redirect loop due to `SCRIPT_NAME` in `PATH_INFO` (#9282)
Inverle2cabd29d1b20
diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.phpindex 400d3e408..96db10bc6 100644--- a/lib/Minz/FrontController.php+++ b/lib/Minz/FrontController.php@@ -46,8 +46,7 @@ class Minz_FrontController {empty($url['params']) || !is_array($url['params']) ? [] : $url['params'],array_filter($_POST, 'is_string', ARRAY_FILTER_USE_KEY));- $pathInfo = $_SERVER['PATH_INFO'] ?? $_SERVER['ORIG_PATH_INFO'] ?? '';- Minz_Request::forward($url, redirect: $pathInfo !== '');+ Minz_Request::forward($url, redirect: Minz_Request::pathInfo() !== '');} catch (Minz_Exception $e) {Minz_Log::error($e->getMessage());self::killApp($e->getMessage());diff --git a/lib/Minz/Request.php b/lib/Minz/Request.phpindex 1f1bd0a49..a63e9aabf 100644--- a/lib/Minz/Request.php+++ b/lib/Minz/Request.php@@ -282,6 +282,25 @@ class Minz_Request {return $remoteIp;}+ /**+ * Returns `PATH_INFO` with `SCRIPT_NAME` stripped from the beginning of it,+ * if it's there on some shared hosting configurations.+ */+ public static function pathInfo(): string {+ $pathInfo = $_SERVER['PATH_INFO'] ?? $_SERVER['ORIG_PATH_INFO'] ?? '';+ if (!is_string($pathInfo)) {+ $pathInfo = '';+ }+ $scriptName = $_SERVER['SCRIPT_NAME'] ?? '';+ if (!is_string($scriptName)) {+ $scriptName = '';+ }+ if ($pathInfo !== '' && $scriptName !== '' && str_starts_with($pathInfo, $scriptName)) {+ $pathInfo = substr($pathInfo, strlen($scriptName));+ }+ return $pathInfo;+ }+/*** Return true if the request is over HTTPS, false otherwise (HTTP)*/diff --git a/p/api/index.php b/p/api/index.phpindex 7433bdf84..633d87c96 100644--- a/p/api/index.php+++ b/p/api/index.php@@ -12,7 +12,7 @@ $frameAncestors = FreshRSS_Context::systemConf()->attributeString('csp.frame-ancheader("Content-Security-Policy: default-src 'self'; frame-ancestors $frameAncestors");header('X-Content-Type-Options: nosniff');-if (($_SERVER['PATH_INFO'] ?? $_SERVER['ORIG_PATH_INFO'] ?? '') !== '') {+if (Minz_Request::pathInfo() !== '') {// Do not allow trailing slashesheader('HTTP/1.1 400 Bad Request');die('Invalid path!');diff --git a/p/api/query.php b/p/api/query.phpindex 6b38aad51..c843a2436 100644--- a/p/api/query.php+++ b/p/api/query.php@@ -38,7 +38,7 @@ if (!FreshRSS_Context::hasSystemConf() || !FreshRSS_Context::systemConf()->api_edie('Service Unavailable!');}-if (($_SERVER['PATH_INFO'] ?? $_SERVER['ORIG_PATH_INFO'] ?? '') !== '') {+if (Minz_Request::pathInfo() !== '') {// Do not allow trailing slashesheader('HTTP/1.1 400 Bad Request');die('Invalid path!');