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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user