fix theme asset caching with file-based versioning

Add cache-busting query string to phpb_theme_asset by appending the file's last-modified timestamp.
Use realpath to resolve and validate the asset path before reading filemtime to prevent directory traversal.
This commit is contained in:
2026-11-23 17:48:52 +01:00
parent 920ab7df4d
commit fcc5c4a96e
+4 -1
View File
@@ -57,7 +57,10 @@ if (! function_exists('phpb_theme_asset')) {
function phpb_theme_asset(string $path): string
{
$themeFolder = phpb_config('theme.folder_url') . '/' . phpb_config('theme.active_theme');
return phpb_full_url($themeFolder . '/' . $path);
$themeRoot = __DIR__ . '/../../../themes/' . phpb_config('theme.active_theme');
$assetPath = realpath($themeRoot . '/' . $path);
$version = ($assetPath && str_starts_with($assetPath, realpath($themeRoot))) ? filemtime($assetPath) : '';
return phpb_full_url($themeFolder . '/' . $path) . '?v=' . $version;
}
}