Skip to content
This repository was archived by the owner on Jan 25, 2021. It is now read-only.

Commit 7f9ac18

Browse files
Better check for local environments
1 parent 5a569d4 commit 7f9ac18

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

app/src/panel.php

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,47 @@ public function license() {
493493
}
494494

495495
public function isLocal() {
496-
$localhosts = array('::1', '127.0.0.1', '0.0.0.0');
497-
return (
498-
in_array(server::get('SERVER_ADDR'), $localhosts) ||
499-
server::get('SERVER_NAME') == 'localhost' ||
500-
str::endsWith(server::get('SERVER_NAME'), '.localhost') ||
501-
str::endsWith(server::get('SERVER_NAME'), '.test')
502-
);
496+
497+
$host = server::get('SERVER_NAME');
498+
$ip = server::get('SERVER_ADDR');
499+
500+
if ($host === 'localhost') {
501+
return true;
502+
}
503+
504+
if (str::endsWith($host, '.localhost') === true) {
505+
return true;
506+
}
507+
508+
if (str::endsWith($host, '.local') === true) {
509+
return true;
510+
}
511+
512+
if (str::endsWith($host, '.test') === true) {
513+
return true;
514+
}
515+
516+
if (in_array($ip, ['::1', '127.0.0.1']) === true) {
517+
518+
if (
519+
isset($_SERVER['HTTP_X_FORWARDED_FOR']) === true &&
520+
in_array($_SERVER['HTTP_X_FORWARDED_FOR'], ['::1', '127.0.0.1']) === false
521+
) {
522+
return false;
523+
}
524+
525+
if (
526+
isset($_SERVER['HTTP_CLIENT_IP']) === true &&
527+
in_array($_SERVER['HTTP_CLIENT_IP'], ['::1', '127.0.0.1']) === false
528+
) {
529+
return false;
530+
}
531+
532+
// no reverse proxy or the real client also comes from localhost
533+
return true;
534+
}
535+
536+
return false;
503537
}
504538

505539
public function notify($text) {

0 commit comments

Comments
 (0)