From 858616f075e5a66a5e0973af421a9f300b3b9ce1 Mon Sep 17 00:00:00 2001 From: Inverle Date: Fri, 5 Sep 2025 08:16:52 +0200 Subject: Fixes for no-cache.txt (#7907) * Closes and fixes error from #7885 * `no-cache.txt` is now respected in `f.php`, `ext.php` and `serve` action in `extensionController` * And in all other places that weren't checking for `no-cache.txt` (some extensions maybe) --- app/Controllers/extensionController.php | 2 +- p/api/query.php | 20 +++++++++----------- p/ext.php | 2 +- p/f.php | 9 ++++++--- p/i/index.php | 21 ++++++++++----------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.php index ef63c38d2..38f04a277 100644 --- a/app/Controllers/extensionController.php +++ b/app/Controllers/extensionController.php @@ -330,7 +330,7 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController { header("Content-Type: {$content_type}"); header("Content-Disposition: inline; filename='{$filename}'"); header('Referrer-Policy: same-origin'); - if (!httpConditional($mtime, cacheSeconds: 604800, cachePrivacy: 2)) { + if (file_exists(DATA_PATH . '/no-cache.txt') || !httpConditional($mtime, cacheSeconds: 604800, cachePrivacy: 2)) { echo $extension->getFile($filename); } } diff --git a/p/api/query.php b/p/api/query.php index f7458e823..5d8fb3dec 100644 --- a/p/api/query.php +++ b/p/api/query.php @@ -48,17 +48,15 @@ if (!FreshRSS_Context::hasUserConf() || !FreshRSS_Context::userConf()->enabled) usleep(rand(20, 200)); } -if (!file_exists(DATA_PATH . '/no-cache.txt')) { - require(LIB_PATH . '/http-conditional.php'); - $dateLastModification = max( - FreshRSS_UserDAO::ctime($user), - FreshRSS_UserDAO::mtime($user), - @filemtime(DATA_PATH . '/config.php') ?: 0 - ); - // TODO: Consider taking advantage of $feedMode, only for monotonous queries {all, categories, feeds} and not dynamic ones {read/unread, favourites, user labels} - if (httpConditional($dateLastModification ?: time(), 0, 0, false, PHP_COMPRESSION, false)) { - exit(); //No need to send anything - } +require(LIB_PATH . '/http-conditional.php'); +$dateLastModification = max( + FreshRSS_UserDAO::ctime($user), + FreshRSS_UserDAO::mtime($user), + @filemtime(DATA_PATH . '/config.php') ?: 0 +); +// TODO: Consider taking advantage of $feedMode, only for monotonous queries {all, categories, feeds} and not dynamic ones {read/unread, favourites, user labels} +if (!file_exists(DATA_PATH . '/no-cache.txt') && httpConditional($dateLastModification ?: time(), 0, 0, false, PHP_COMPRESSION, false)) { + exit(); //No need to send anything } Minz_Translate::init(FreshRSS_Context::userConf()->language); diff --git a/p/ext.php b/p/ext.php index 5fdd3df6c..6642ff2d1 100644 --- a/p/ext.php +++ b/p/ext.php @@ -105,6 +105,6 @@ if ($mtime === false) { require(LIB_PATH . '/http-conditional.php'); -if (!httpConditional($mtime, 604800, 2)) { +if (file_exists(DATA_PATH . '/no-cache.txt') || !httpConditional($mtime, 604800, 2)) { readfile($absolute_filename); } diff --git a/p/f.php b/p/f.php index fc9a60abd..0238e5846 100644 --- a/p/f.php +++ b/p/f.php @@ -8,9 +8,12 @@ require(LIB_PATH . '/http-conditional.php'); header("Content-Security-Policy: default-src 'none'; frame-ancestors 'none'; sandbox"); header('X-Content-Type-Options: nosniff'); +$no_cache = file_exists(DATA_PATH . '/no-cache.txt'); + function show_default_favicon(int $cacheSeconds = 3600): void { + global $no_cache; $default_mtime = @filemtime(DEFAULT_FAVICON) ?: 0; - if (!httpConditional($default_mtime, $cacheSeconds, 2)) { + if ($no_cache || !httpConditional($default_mtime, $cacheSeconds, 2)) { header('Content-Type: image/x-icon'); header('Content-Disposition: inline; filename="default_favicon.ico"'); readfile(DEFAULT_FAVICON); @@ -59,11 +62,11 @@ if (($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (m } } -if (!httpConditional($ico_mtime, mt_rand(14, 21) * 86400, 2)) { +if ($no_cache || !httpConditional($ico_mtime, mt_rand(14, 21) * 86400, 2)) { $ico_content_type = contentType($ico); header('Content-Type: ' . $ico_content_type); header('Content-Disposition: inline; filename="' . $id . '.ico"'); - if (isset($_GET['t'])) { + if (!$no_cache && isset($_GET['t'])) { header('Cache-Control: immutable'); } readfile($ico); diff --git a/p/i/index.php b/p/i/index.php index 96c8e52fb..55846b952 100644 --- a/p/i/index.php +++ b/p/i/index.php @@ -35,17 +35,16 @@ if (!file_exists($applied_migrations_path)) { Minz_Session::init('FreshRSS'); Minz_Session::_param('keepAlive', 1); //To prevent the PHP session from expiring - if (!file_exists(DATA_PATH . '/no-cache.txt')) { - require(LIB_PATH . '/http-conditional.php'); - $currentUser = Minz_User::name(); - $dateLastModification = $currentUser === null ? time() : max( - FreshRSS_UserDAO::ctime($currentUser), - FreshRSS_UserDAO::mtime($currentUser), - @filemtime(DATA_PATH . '/config.php') ?: 0 - ); - if (httpConditional($dateLastModification ?: time(), 0, 0, false, PHP_COMPRESSION, true)) { - exit(); //No need to send anything - } + require(LIB_PATH . '/http-conditional.php'); + $currentUser = Minz_User::name(); + $dateLastModification = $currentUser === null ? time() : max( + FreshRSS_UserDAO::ctime($currentUser), + FreshRSS_UserDAO::mtime($currentUser), + @filemtime(DATA_PATH . '/config.php') ?: 0 + ); + if (!file_exists(DATA_PATH . '/no-cache.txt') + && httpConditional($dateLastModification ?: time(), 0, 0, false, PHP_COMPRESSION, true)) { + exit(); //No need to send anything } $error = false; -- cgit v1.2.3