Skip to content

Commit 32958c8

Browse files
committed
1 parent 7b7cb7d commit 32958c8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

web/inc/prevent_csrf.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ function prevent_post_csrf()
3232
{
3333
if (!empty($_SERVER['REQUEST_METHOD'])) {
3434
if ($_SERVER['REQUEST_METHOD']==='POST') {
35-
$hostname = explode(':', $_SERVER['HTTP_HOST']);
36-
$port=$hostname[1];
37-
$hostname=$hostname[0];
35+
list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
36+
if(empty($port)){
37+
$port = 443;
38+
}
3839
if (isset($_SERVER['HTTP_ORIGIN'])) {
3940
$origin_host = parse_url($_SERVER['HTTP_ORIGIN'], PHP_URL_HOST);
4041
if (strcmp($origin_host, gethostname()) === 0 && in_array($port, array('443',$_SERVER['SERVER_PORT']))) {
@@ -55,9 +56,10 @@ function prevent_get_csrf()
5556
{
5657
if (!empty($_SERVER['REQUEST_METHOD'])) {
5758
if ($_SERVER['REQUEST_METHOD']==='GET') {
58-
$hostname = explode(':', $_SERVER['HTTP_HOST']);
59-
$port=$hostname[1];
60-
$hostname=$hostname[0];
59+
list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
60+
if(empty($port)){
61+
$port = 443;
62+
}
6163
//list of possible entries route and these should never be blocked
6264
if (in_array($_SERVER['DOCUMENT_URI'], array('/list/user/index.php', '/login/index.php','/list/web/index.php','/list/dns/index.php','/list/mail/index.php','/list/db/index.php','/list/cron/index.php','/list/backup/index.php','/reset/index.php'))) {
6365
return true;

0 commit comments

Comments
 (0)