diff --git a/app/Debug.php b/app/Debug.php index c6965f47f..3f582af09 100644 --- a/app/Debug.php +++ b/app/Debug.php @@ -240,14 +240,12 @@ class Debug { } } - if (DEBUG_WARNINGS) { - self::$Errors[] = [ - str_replace(SERVER_ROOT . '/', '', $Error), - str_replace(SERVER_ROOT . '/', '', $File) . ":$Line", - $Call, - $Args - ]; - } + self::$Errors[] = [ + str_replace(SERVER_ROOT . '/', '', $Error), + str_replace(SERVER_ROOT . '/', '', $File) . ":$Line", + $Call, + $Args + ]; return true; } diff --git a/app/SessionCookie.php b/app/SessionCookie.php index 0607b7e34..e44925b89 100644 --- a/app/SessionCookie.php +++ b/app/SessionCookie.php @@ -69,7 +69,7 @@ class SessionCookie { [ 'expires' => $expiryEpoch, 'path' => '/', - 'secure' => !DEBUG_MODE, + 'secure' => SECURE_COOKIE, 'httponly' => true, 'samesite' => 'Lax', ] @@ -83,7 +83,7 @@ class SessionCookie { [ 'expires' => time() - 86_400 * 90, 'path' => '/', - 'secure' => !DEBUG_MODE, + 'secure' => SECURE_COOKIE, 'httponly' => true, 'samesite' => 'Lax', ] diff --git a/app/User.php b/app/User.php index 95944423b..aab584201 100644 --- a/app/User.php +++ b/app/User.php @@ -109,7 +109,7 @@ class User extends BaseAttrObject { setcookie('session', '', [ 'expires' => time() - 60 * 60 * 24 * 90, 'path' => '/', - 'secure' => !DEBUG_MODE, + 'secure' => SECURE_COOKIE, 'httponly' => true, 'samesite' => 'Strict', ]); diff --git a/app/Util/Twig.php b/app/Util/Twig.php index 8c0032ffb..80c47bacd 100644 --- a/app/Util/Twig.php +++ b/app/Util/Twig.php @@ -24,7 +24,7 @@ class Twig { self::$userMan = $userMan; $twig = new \Twig\Environment( new \Twig\Loader\FilesystemLoader(__DIR__ . '/../../' . TEMPLATE_PATH), [ - 'debug' => DEBUG_MODE, + 'debug' => DEBUG_TWIG, 'cache' => __DIR__ . '/../../cache/twig' ]); diff --git a/classes/sphinxql.class.php b/classes/sphinxql.class.php index 144172ab9..0ff21832c 100644 --- a/classes/sphinxql.class.php +++ b/classes/sphinxql.class.php @@ -92,7 +92,7 @@ class Sphinxql extends mysqli { 86_400, ); if ($halt === true) { - if (DEBUG_MODE || $Viewer->permitted('site_debug')) { + if ($Viewer->permitted('site_debug')) { echo '
' . display_str($error) . ''; die(); } else { diff --git a/gazelle.php b/gazelle.php index ff7784c65..e9c9ee416 100644 --- a/gazelle.php +++ b/gazelle.php @@ -121,7 +121,7 @@ if ($Viewer) { } $Debug->mark('load page'); -if (DEBUG_MODE || $Viewer?->permitted('site_debug')) { +if (DEBUG_TWIG) { $Twig->addExtension(new \Twig\Extension\DebugExtension()); } @@ -169,7 +169,7 @@ try { } $errorLog = $Debug->saveError($e); Error500::error( - DEBUG_MODE || $Viewer?->permitted('site_debug') + $Viewer?->permitted('site_debug') ? ($e->getMessage() . " ({$errorLog->link()})") : "That is not supposed to happen. Check to see whether someone has created a thread in the the Bugs forum, or create a new thread to explain what you were doing and reference the Error ID {$errorLog->id}." ); diff --git a/lib/config.php b/lib/config.php index 64e603460..c95d37d19 100644 --- a/lib/config.php +++ b/lib/config.php @@ -479,11 +479,8 @@ defined('HTTP_PROXY') or define('HTTP_PROXY', false); // Block Opera Mini proxy? defined('BLOCK_OPERA_MINI') or define('BLOCK_OPERA_MINI', true); -// Should PHP errors be shown in the output? -defined('DEBUG_MODE') or define('DEBUG_MODE', false); - -// Can developer+ see PHP warnings in the site footer? -defined('DEBUG_WARNINGS') or define('DEBUG_WARNINGS', true); +// Is the debug() function available in Twig? +defined('DEBUG_TWIG') or define('DEBUG_TWIG', false); // Do upload notifications need to be traced? (Results written to TMPDIR) defined('DEBUG_UPLOAD_NOTIFICATION') or define('DEBUG_UPLOAD_NOTIFICATION', false); @@ -509,12 +506,6 @@ defined('LASTFM_API_KEY') or define('LASTFM_API_KEY', false); // Fake useragent (to override default cURL useragent string). defined('FAKE_USERAGENT') or define('FAKE_USERAGENT', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.1 Safari/537.11'); -// How much upload buffer to members start out with? (3 GiB) -defined('STARTING_UPLOAD') or define('STARTING_UPLOAD', 3 * 1024 * 1024 * 1024); - -// Can freeleech (FL) tokens be stacked? -defined('STACKABLE_FREELEECH_TOKENS') or define('STACKABLE_FREELEECH_TOKENS', true); - // How long does an activated token last before it is purged? defined('FREELEECH_TOKEN_EXPIRY_DAYS') or define('FREELEECH_TOKEN_EXPIRY_DAYS', 30); @@ -542,6 +533,15 @@ defined('DELETE_USER_STATS_DAILY_DAY') or define('DELETE_USER_STATS_DAILY_DAY', // Retain this many months of daily snapshots. defined('DELETE_USER_STATS_MONTHLY_DAY') or define('DELETE_USER_STATS_MONTHLY_DAY', 120); +// Is the secure attribute set on cookies? +defined('SECURE_COOKIE') or define('SECURE_COOKIE', true); + +// Can freeleech (FL) tokens be stacked? +defined('STACKABLE_FREELEECH_TOKENS') or define('STACKABLE_FREELEECH_TOKENS', true); + +// How much upload buffer to members start out with? (3 GiB) +defined('STARTING_UPLOAD') or define('STARTING_UPLOAD', 3 * 1024 * 1024 * 1024); + // How many invites do new users receive? defined('STARTING_INVITES') or define('STARTING_INVITES', 0); diff --git a/misc/example.local.config.php b/misc/example.local.config.php index 6ab3efb70..9bce21e68 100644 --- a/misc/example.local.config.php +++ b/misc/example.local.config.php @@ -9,11 +9,11 @@ define('DISABLE_TRACKER', true); define('DISABLE_IRC', true); define('DEBUG_EMAIL', true); -define('DEBUG_MODE', true); -define('DEBUG_WARNINGS', true); +define('DEBUG_TWIG', true); define('DEBUG_UPLOAD_NOTIFICATION', true); define('OPEN_REGISTRATION', true); +define('SECURE_COOKIE', false); define('MEMCACHE_HOST_LIST', [['host' => 'memcached', 'port' => 11211, 'buckets' => 1]]); diff --git a/misc/phpstan.neon b/misc/phpstan.neon index a38e8e35d..9f03ba61d 100644 --- a/misc/phpstan.neon +++ b/misc/phpstan.neon @@ -76,10 +76,9 @@ parameters: - DEBUG - DEBUG_CONTEST_PAYOUT - DEBUG_EMAIL - - DEBUG_MODE - DEBUG_TRACKER_TOKEN_EXPIRE + - DEBUG_TWIG - DEBUG_UPLOAD_NOTIFICATION - - DEBUG_WARNINGS - FEATURE_EMAIL_REENABLE - GEOIP_SERVER - HTTP_PROXY @@ -103,6 +102,7 @@ parameters: - RECOVERY_DB - REFERRAL_SEND_EMAIL - REQUEST_TAX + - SECURE_COOKIE - SHOW_PUBLIC_INDEX - STACKABLE_FREELEECH_TOKENS - USER_LIMIT diff --git a/misc/rector.php b/misc/rector.php index 69d185222..bb3364271 100644 --- a/misc/rector.php +++ b/misc/rector.php @@ -10,8 +10,7 @@ use Rector\Php83\Rector\ClassConst\AddTypeToConstRector; use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector; // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols -define('DEBUG_MODE', true); -define('DEBUG_WARNINGS', true); +define('DEBUG_TWIG', true); define('DISABLE_IRC', false); define('FEATURE_EMAIL_REENABLE', true); define('GEOIP_SERVER', true); @@ -24,6 +23,7 @@ define('REAPER_TASK_NOTIFY', true); define('REAPER_TASK_REMOVE_UNSEEDED', true); define('REAPER_TASK_REMOVE_NEVER_SEEDED', true); define('RECOVERY_AUTOVALIDATE', true); +define('SECURE_COOKIE', false); return RectorConfig::configure() ->withPaths([ diff --git a/sections/login/disabled.php b/sections/login/disabled.php index 06d3f1b71..cf1185d92 100644 --- a/sections/login/disabled.php +++ b/sections/login/disabled.php @@ -14,7 +14,7 @@ if (isset($_POST['username'])) { setcookie('username', '', [ 'expires' => time() + 60 * 60, 'path' => '/', - 'secure' => !DEBUG_MODE, + 'secure' => SECURE_COOKIE, 'httponly' => true, 'samesite' => 'Strict', ]); diff --git a/sections/login/login.php b/sections/login/login.php index 5dc130655..c3184596c 100644 --- a/sections/login/login.php +++ b/sections/login/login.php @@ -29,7 +29,7 @@ if (!empty($_POST['username']) && !empty($_POST['password'])) { setcookie('username', urlencode($user->username()), [ 'expires' => time() + 60 * 60, 'path' => '/', - 'secure' => !DEBUG_MODE, + 'secure' => SECURE_COOKIE, 'httponly' => true, 'samesite' => 'Strict', ]); diff --git a/templates/index/private-footer.twig b/templates/index/private-footer.twig index 3f8229326..fc846d2bc 100644 --- a/templates/index/private-footer.twig +++ b/templates/index/private-footer.twig @@ -1,6 +1,6 @@