aboutsummaryrefslogtreecommitdiff
path: root/misc.php
blob: 796506688a70e6985c981094ff02d0f820a15689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}