Skip URI base on ALLOWED_RELATIVE_SCHEMES in rewrite_relative

This commit is contained in:
Philip Klempin 2021-06-07 00:51:02 +02:00
parent 92c78beb90
commit b3bedd0a94
1 changed files with 7 additions and 2 deletions

View File

@ -1,5 +1,11 @@
<?php <?php
class UrlHelper { class UrlHelper {
const ALLOWED_RELATIVE_SCHEMES = [
"magnet",
"mailto",
"tel"
];
static $fetch_last_error; static $fetch_last_error;
static $fetch_last_error_code; static $fetch_last_error_code;
static $fetch_last_error_content; static $fetch_last_error_content;
@ -36,8 +42,7 @@ class UrlHelper {
} else if (strpos($rel_url, "//") === 0) { } else if (strpos($rel_url, "//") === 0) {
# protocol-relative URL (rare but they exist) # protocol-relative URL (rare but they exist)
return self::validate("https:" . $rel_url); return self::validate("https:" . $rel_url);
} else if (strpos($rel_url, "magnet:") === 0) { } else if (array_search($rel_parts["scheme"] ?? "", self::ALLOWED_RELATIVE_SCHEMES, true) !== false) {
# allow magnet links
return $rel_url; return $rel_url;
} else { } else {
$base_parts = parse_url($base_url); $base_parts = parse_url($base_url);