aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2022-03-13 19:37:45 +0100
committerHarald Eilertsen <haraldei@anduin.net>2022-03-13 19:37:45 +0100
commitf4af532c5a8f37f69035616e2ae7908bf5b77a62 (patch)
tree90d2307d2d98972994229f5c2bc46ac56153e461
parent34ffff3947b8e89a667367277f0fde9c626fd143 (diff)
downloadvolse-hubzilla-f4af532c5a8f37f69035616e2ae7908bf5b77a62.tar.gz
volse-hubzilla-f4af532c5a8f37f69035616e2ae7908bf5b77a62.tar.bz2
volse-hubzilla-f4af532c5a8f37f69035616e2ae7908bf5b77a62.zip
Trim trailing & from query_string.
When trying to fetch an image file from the Cloud module, the default nginx config will add a trailing & if there's no args specified. Example: https://example.com/cloud/username/some_image.png This will be rewritten to: https://example.com/index.php?q=/cloud/username/some_image.png& This in turn will cause the Cloud module to try to redirect back to the original because it does not match the query_string (in which the ampersand has been converted to a question mark). And this will repeat until the browser get's tired of it.
-rw-r--r--boot.php5
1 files changed, 5 insertions, 0 deletions
diff --git a/boot.php b/boot.php
index 5fa314eee..42b162506 100644
--- a/boot.php
+++ b/boot.php
@@ -915,9 +915,14 @@ class App {
if ((x($_SERVER, 'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'], 0, 2) === "q=") {
self::$query_string = str_replace(['<', '>'], ['&lt;', '&gt;'], substr($_SERVER['QUERY_STRING'], 2));
+
// removing trailing / - maybe a nginx problem
if (substr(self::$query_string, 0, 1) == "/")
self::$query_string = substr(self::$query_string, 1);
+
+ // trim trailing '&' if no extra args are present
+ self::$query_string = rtrim(self::$query_string, '&');
+
// change the first & to ?
self::$query_string = preg_replace('/&/', '?', self::$query_string, 1);
}