aboutsummaryrefslogtreecommitdiff
path: root/misc.php
diff options
context:
space:
mode:
Diffstat (limited to 'misc.php')
-rw-r--r--misc.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/misc.php b/misc.php
new file mode 100644
index 0000000..7965066
--- /dev/null
+++ b/misc.php
@@ -0,0 +1,27 @@
+<?php
+namespace Psso;
+
+function isValidRedirect(string $target, array $config): bool {
+ $redirHost = parse_url($target, PHP_URL_HOST);
+
+ $primary = explode('.', $config['site']['primary-domain'], 2)[1];
+ if (str_ends_with($redirHost, '.' . $primary) || $redirHost == $primary) {
+ return true;
+ }
+
+ foreach ($config['site']['cookie-domains'] ?? [] as $cdomain) {
+ $upper = explode('.', $cdomain, 2)[1];
+ if (str_ends_with($redirHost, '.' . $upper) || $redirHost == $upper) {
+ return true;
+ }
+ }
+
+ foreach ($config['site']['redirect-domains'] ?? [] as $rdomain) {
+ if (str_ends_with($redirHost, '.' . $rdomain) ||
+ $redirHost == $rdomain) {
+ return true;
+ }
+ }
+
+ return false;
+}