From 428d9e9001fe518945abf342aeb51b01f899dd1b Mon Sep 17 00:00:00 2001 From: Zankaria Date: Tue, 7 May 2024 22:40:51 +0200 Subject: [PATCH] functions net.php: add Tor connections to secure connections --- inc/functions/net.php | 11 +++++++++-- inc/mod/auth.php | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/inc/functions/net.php b/inc/functions/net.php index ab08c3cb..4319a3f3 100644 --- a/inc/functions/net.php +++ b/inc/functions/net.php @@ -3,8 +3,15 @@ namespace Vichan\Functions\Net; /** - * @return bool Returns if the client-server connection is an encrypted one (HTTPS). + * @return bool Returns if the client-server connection is an HTTPS one. */ -function is_connection_secure(): bool { +function is_connection_https(): bool { return !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'; } + +/** + * @return bool Returns if the client-server connection is an encrypted one (HTTPS or Tor loopback). + */ +function is_connection_secure(): bool { + return is_connection_https() || (!empty($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] === '127.0.0.1'); +} diff --git a/inc/mod/auth.php b/inc/mod/auth.php index b749d521..958b7ba5 100644 --- a/inc/mod/auth.php +++ b/inc/mod/auth.php @@ -107,7 +107,7 @@ function setCookies() { if (!$mod) error('setCookies() was called for a non-moderator!'); - $is_https = Net\is_connection_secure(); + $is_https = Net\is_connection_https(); setcookie($config['cookies']['mod'], $mod['username'] . // username @@ -120,7 +120,7 @@ function setCookies() { function destroyCookies() { global $config; - $is_https = Net\is_connection_secure(); + $is_https = Net\is_connection_https(); // Delete the cookies setcookie($config['cookies']['mod'], 'deleted', time() - $config['cookies']['expire'], $config['cookies']['jail']?$config['cookies']['path'] : '/', null, $is_https, true); }