Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/file-manager/backend/app/Compatibility/deprecated-functions.php
+++ b/file-manager/backend/app/Compatibility/deprecated-functions.php
@@ -1,5 +1,9 @@
<?php
+if (!defined('ABSPATH')) {
+ exit;
+}
+
if (!function_exists('bfmActivate')) {
function bfmActivate()
{
--- a/file-manager/backend/app/Config.php
+++ b/file-manager/backend/app/Config.php
@@ -21,9 +21,9 @@
const VAR_PREFIX = 'bitapps_fm_';
- const VERSION = '6.9';
+ const VERSION = '6.9.1';
- const VERSION_ID = 690;
+ const VERSION_ID = 691;
const DB_VERSION = '1.0';
--- a/file-manager/backend/app/Http/Controllers/FileManagerController.php
+++ b/file-manager/backend/app/Http/Controllers/FileManagerController.php
@@ -29,7 +29,19 @@
public function connector()
{
try {
- Plugin::instance()->accessControl()->checkPermission(sanitize_key($_REQUEST['cmd']));
+ $command = isset($_REQUEST['cmd']) && is_scalar($_REQUEST['cmd'])
+ ? sanitize_key((string) $_REQUEST['cmd'])
+ : '';
+
+ $accessControl = Plugin::instance()->accessControl();
+ if ($accessControl->isConnectorEnforceable($command)) {
+ $permissionResult = $accessControl->checkPermission($command);
+ if (is_array($permissionResult) && !empty($permissionResult['preventexec'])) {
+ echo wp_json_encode($permissionResult['results']);
+ wp_die();
+ }
+ }
+
$finderProvider = new FileManagerProvider($this->getFinderOptions());
$finderProvider->getFinder()->run();
} catch (Exception $th) {
@@ -52,12 +64,13 @@
]
);
+ // Bind the gate to the `*.pre` wildcard, not an explicit command list: elFinder
+ // registers a `<cmd>.pre` handler only when the command arrives via $_POST, yet it
+ // dispatches from the merged $_GET+$_POST (plus a php://input re-parse past
+ // max_input_vars). A command sent only via query string / oversized body would skip
+ // registration but still execute, bypassing the gate. `*.pre` registers unconditionally.
$finderOptions->setBind(
- 'get.pre put.pre file.pre archive.pre back.pre chmod.pre colwidth.pre copy.pre cut.pre duplicate.pre editor.pre
- extract.pre forward.pre fullscreen.pre getfile.pre help.pre home.pre info.pre mkdir.pre mkfile.pre
- netmount.pre netunmount.pre open.pre opendir.pre paste.pre places.pre quicklook.pre reload.pre
- rename.pre resize.pre restore.pre rm.pre search.pre sort.pre up.pre upload.pre view.pre zipdl.pre
- tree.pre parents.pre ls.pre tmb.pre size.pre dim.pre',
+ '*.pre',
[
Plugin::instance()->accessControl(),
'checkPermission',
@@ -69,8 +82,6 @@
[Plugin::instance()->mediaSyncs(), 'onFileUpload']
);
- // 'zipdl.pre file.pre rename.pre put.pre upload.pre',
-
$finderOptions->setBind(
'zipdl.pre file.pre rename.pre put.pre rm.pre chmod.pre mkdir.pre mkfile.pre extract.pre',
[Plugin::instance()->logger(), 'log']
@@ -118,15 +129,32 @@
throw new PreCommandException(esc_html__('There is no readable volume. Please select an readable folder from settings', 'file-manager'));
}
+ $accessControlProvider = Plugin::instance()->accessControl();
+
foreach ($trashVolumes as $trashSeq => $trashDir) {
if (!is_dir($trashDir)) {
wp_mkdir_p($trashDir);
+ if (function_exists('bitapps_fm_harden_dir')) {
+ bitapps_fm_harden_dir($trashDir);
+ }
}
if (is_dir($trashDir)) {
$trashRoot = new FileRoot($trashDir, '', 'Trash', 'Trash');
// Explicitly set id so the volume hash is predictable: t{trashSeq}_Lw
$trashRoot->setOption('id', $trashSeq + 1);
+ // Trash lives under wp-content/uploads (web-served). Block the commands that
+ // author new file *content* so a write-granted user cannot plant a .php here
+ // (RCE), while keeping `paste`/`rm`/`mkdir`/`rename`: elFinder implements
+ // move-to-trash and restore as a cross-volume `paste`, which calls the trash
+ // volume's `mkdir` (for folders) and `rename` (name-collision resolution) — so
+ // disabling those would break trashing folders. `mkdir`/`rename` write no file
+ // content; the residual rename-to-.php is covered by the dir .htaccess (E-1).
+ // Do NOT add an upload MIME deny-list — it would block trashing an existing
+ // .php/.js/.css file.
+ $trashRoot->setAccessControl([$accessControlProvider, 'control']);
+ $trashRoot->setAcceptedName([$accessControlProvider, 'validateName']);
+ $trashRoot->setDisabled(['upload', 'put', 'mkfile', 'duplicate', 'archive', 'extract']);
$finderOptions->setRoot($trashRoot);
}
}
--- a/file-manager/backend/app/Providers/AccessControlProvider.php
+++ b/file-manager/backend/app/Providers/AccessControlProvider.php
@@ -12,6 +12,21 @@
class AccessControlProvider
{
+ /**
+ * Navigation/utility commands that read no file content and mutate nothing.
+ * The gate binds to `*.pre` (fires for every command), so these are passed
+ * explicitly to keep tree/URL browsing working for restricted users.
+ */
+ public const EXEMPT_COMMANDS = ['open', 'search', 'subdirs', 'url', 'abort', 'callback'];
+
+ /**
+ * Commands the connector-level backstop must NOT enforce. `file` (read) is
+ * authorized only by the `*.pre` bind: its path-aware `download`-grant check
+ * needs the resolved target volume, which does not exist until run() builds
+ * elFinder — a connector check that lacks those arguments can only wrongly deny it.
+ */
+ public const CONNECTOR_UNCHECKED_COMMANDS = ['file'];
+
public $settings;
private $maliciousPatterns = [
@@ -73,9 +88,22 @@
return ! (strpos($name, '.') === 0 && !$this->settings->isHiddenFolderAllowed());
}
+ /**
+ * Whether the connector may enforce this command before elFinder runs.
+ * The authoritative, argument-complete gate is the `*.pre` bind inside run().
+ *
+ * @param string $command
+ *
+ * @return bool
+ */
+ public function isConnectorEnforceable($command)
+ {
+ return $command !== '' && !in_array($command, self::CONNECTOR_UNCHECKED_COMMANDS, true);
+ }
+
public function checkPermission($command, ...$args)
{
- if (in_array($command, ['open', 'search'])) {
+ if (in_array($command, self::EXEMPT_COMMANDS, true)) {
return;
}
@@ -114,10 +142,6 @@
}
}
- if ($command == 'file' && $this->isFileAllowedToOpen($args)) {
- $error = '';
- }
-
try {
if (!empty($error)) {
throw new PreCommandException($error);
@@ -282,26 +306,6 @@
return true;
}
- private function isFileAllowedToOpen($args)
- {
- if (isset($args[1]) && $args[1] instanceof elFinder) {
- $volume = $args[1]->getVolume($args[0]['target']);
- $file = $volume->getPath($args[0]['target']);
- $fileName = wp_basename($file);
- $fileTypeAndExt = wp_check_filetype_and_ext($file, $fileName);
- if (isset($fileTypeAndExt['ext'], $fileTypeAndExt['type'])) {
- $fileType = str_replace('/' . $fileTypeAndExt['ext'], '', $fileTypeAndExt['type']);
- $enabledFileType = Plugin::instance()->permissions()->getEnabledFileType();
-
- if (in_array($fileType, $enabledFileType)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
private function scanForPattern($content, $fileName)
{
$containsJs = false;
--- a/file-manager/backend/app/Providers/FileManager/FileRoot.php
+++ b/file-manager/backend/app/Providers/FileManager/FileRoot.php
@@ -840,6 +840,13 @@
// root, leaking downscaled copies past the permission gate. '' not null —
// null is isset()-false, so elFinder falls back to its '.tmb' default.
$options['tmbPath'] = '';
+ // Force the in-process image library (never the `convert` CLI). elFinder's default
+ // `imgLib=auto` shells out to ImageMagick's `convert` binary when no PHP image
+ // extension is present; pin to imagick/gd, and to 'none' when neither is loaded
+ // ('gd' would itself fall through to the convert CLI in elFinder's detection).
+ $options['imgLib'] = extension_loaded('imagick')
+ ? 'imagick'
+ : (function_exists('gd_info') ? 'gd' : 'none');
$options['id'] = $this->getOption('_id');
$options['alias'] = $this->getOption('_alias');
$options['driver'] = $this->getOption('_driver');
--- a/file-manager/backend/app/Providers/HookProvider.php
+++ b/file-manager/backend/app/Providers/HookProvider.php
@@ -35,6 +35,9 @@
&& RequestType::is(RequestType::API)
) {
$router = new Router(RequestType::API, Config::SLUG, 'v1');
+ // Without this, route-level `cap:`/`nonce:` middleware silently no-ops on the
+ // REST API (getRegisteredMiddleware() returns null → handleMiddleware() skips it).
+ $router->setMiddlewares(Plugin::instance()->middlewares());
include_once $this->_pluginBackend . 'hooks' . DIRECTORY_SEPARATOR . 'api.php';
--- a/file-manager/backend/app/Providers/InstallerProvider.php
+++ b/file-manager/backend/app/Providers/InstallerProvider.php
@@ -48,8 +48,8 @@
public static function migration()
{
$migrations = [
- 'BFMLogsTableMigration',
- 'BFMPluginOptions',
+ 'BitAppsFMLogsTableMigration',
+ 'BitAppsFMPluginOptions',
];
return [
@@ -66,8 +66,8 @@
public static function drop()
{
$migrations = [
- 'BFMLogsTableMigration',
- 'BFMPluginOptions',
+ 'BitAppsFMLogsTableMigration',
+ 'BitAppsFMPluginOptions',
];
return [
--- a/file-manager/backend/app/Providers/MediaSynchronizer.php
+++ b/file-manager/backend/app/Providers/MediaSynchronizer.php
@@ -19,25 +19,37 @@
// Triggers when a file is uploaded and initiates the uploading process for single or batch files.
public function onFileUpload($cmd, &$result, $args, $elfinder, $volume)
{
- $targetPath = $volume->getPath($args['target']);
+ if (!Plugin::instance()->preferences()->isWpMediaSyncEnabled() || empty($result['added'])) {
+ return;
+ }
+
+ $images = [];
+ foreach ($result['added'] as $added) {
+ if (empty($added['hash']) || ($added['mime'] ?? '') === 'directory') {
+ continue; // folder-structure uploads also add dir stats; sync files only
+ }
- if (
- PermissionsProvider::realpathWithin($targetPath, $this->wpUploadBaseDirectory) !== null
- && Plugin::instance()->preferences()->isWpMediaSyncEnabled()
- ) {
- $images = [];
- for ($file = 0; $file < count($args['FILES']['upload']['name']); $file++) {
- $images[] = [
- 'name' => $args['FILES']['upload']['name'][$file],
- 'type' => wp_check_filetype($args['FILES']['upload']['name'][$file], null),
- 'path' => trailingslashit($targetPath) . $args['FILES']['upload']['name'][$file],
- 'url' => $this->abs_path_to_url(
- trailingslashit($targetPath)
- . $args['FILES']['upload']['name'][$file]
- ),
- ];
+ // Resolve the file elFinder actually saved (name basename-sanitized, collision-safe)
+ // from its own hash — never the raw client filename in $args, which can carry a `../`
+ // traversal. Confine on the FINAL path, not just the target directory.
+ $path = $volume->getPath($added['hash']);
+ if (!is_string($path) || $path === '') {
+ continue;
}
+ if (PermissionsProvider::realpathWithin($path, $this->wpUploadBaseDirectory) === null) {
+ continue;
+ }
+
+ $name = wp_basename($path);
+ $images[] = [
+ 'name' => $name,
+ 'type' => wp_check_filetype($name, null),
+ 'path' => $path,
+ 'url' => $this->abs_path_to_url($path),
+ ];
+ }
+ if (!empty($images)) {
$this->addMedia($images);
}
}
--- a/file-manager/backend/app/Providers/PermissionsProvider.php
+++ b/file-manager/backend/app/Providers/PermissionsProvider.php
@@ -240,6 +240,9 @@
&& fileSystemAdapter()->is_writable($defaultPath)
) {
wp_mkdir_p($rootPath);
+ if (function_exists('bitapps_fm_harden_dir')) {
+ bitapps_fm_harden_dir($rootPath);
+ }
}
if (!fileSystemAdapter()->exists($rootPath) || !fileSystemAdapter()->is_dir($rootPath) || !fileSystemAdapter()->is_readable($rootPath)) {
@@ -633,6 +636,20 @@
public function updatePermissionSetting($permissions)
{
+ // Validated by_user/by_role entries carry only the outer key allow-list; reduce each
+ // entry to the two fields actually consumed (path, commands) so no arbitrary sub-key
+ // is persisted into the option blob.
+ foreach (['by_user', 'by_role'] as $scope) {
+ if (!empty($permissions[$scope]) && is_array($permissions[$scope])) {
+ foreach ($permissions[$scope] as $key => $entry) {
+ $permissions[$scope][$key] = [
+ 'path' => is_array($entry) && isset($entry['path']) ? $entry['path'] : '',
+ 'commands' => is_array($entry) && isset($entry['commands']) && is_array($entry['commands']) ? $entry['commands'] : [],
+ ];
+ }
+ }
+ }
+
return Config::updateOption('permissions', $permissions, 'yes');
}
@@ -644,7 +661,12 @@
$action = sanitize_key($_REQUEST['action']);
}
- return is_user_logged_in() && $action === 'bitapps_fm_connector';
+ // The dashboard volume is rooted at the site root, so it must require the same
+ // capability as the admin File Manager screen. A valid wp_rest nonce is held by
+ // every logged-in user and is not authorization, so gate on the capability too.
+ return is_user_logged_in()
+ && $action === 'bitapps_fm_connector'
+ && Capabilities::filter('bitapps_fm_can_access_home', 'manage_options');
}
public function isRequestForShortcode()
--- a/file-manager/backend/app/Providers/PreferenceProvider.php
+++ b/file-manager/backend/app/Providers/PreferenceProvider.php
@@ -461,8 +461,11 @@
$defaultPath = Capabilities::check('manage_options')
? ABSPATH : $this->permissions()->getDefaultPublicRootPath();
+ // Return the raw stored path — it is validated on write (setRootPath()->realPath()
+ // and ValidPathRule at the request boundary). esc_attr() here would entity-encode a
+ // legal '&'/'''/'<' in the path and break the volume; escaping belongs at HTML output.
return isset($this->preferences['root_folder_path'])
- ? esc_attr($this->preferences['root_folder_path']) : $defaultPath;
+ ? $this->preferences['root_folder_path'] : $defaultPath;
}
public function realPath($path)
--- a/file-manager/backend/app/Views/Admin.php
+++ b/file-manager/backend/app/Views/Admin.php
@@ -266,7 +266,7 @@
'postMaxSize' => esc_html(ini_get('post_max_size')),
'memoryLimit' => esc_html(ini_get('memory_limit')),
'maxExecutionTime' => esc_html(ini_get('max_execution_time')),
- 'ua' => esc_html($_SERVER['HTTP_USER_AGENT']),
+ 'ua' => isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT'])) : '',
'fileEditNotAllowed' => defined('DISALLOW_FILE_EDIT') && DISALLOW_FILE_EDIT,
];
}
--- a/file-manager/backend/db/Migrations/BitAppsFMPluginOptions.php
+++ b/file-manager/backend/db/Migrations/BitAppsFMPluginOptions.php
@@ -8,7 +8,7 @@
exit;
}
-final class BFMPluginOptions extends Migration
+final class BitAppsFMPluginOptions extends Migration
{
public function up()
{
--- a/file-manager/backend/functions/global.php
+++ b/file-manager/backend/functions/global.php
@@ -27,6 +27,46 @@
wp_mkdir_p($baseDir . DIRECTORY_SEPARATOR . '.tmb');
wp_mkdir_p($baseDir . DIRECTORY_SEPARATOR . '.tmp');
wp_mkdir_p($trashDir);
+
+ bitapps_fm_harden_dir($baseDir);
+ bitapps_fm_harden_dir($baseDir . DIRECTORY_SEPARATOR . '.tmb');
+ bitapps_fm_harden_dir($baseDir . DIRECTORY_SEPARATOR . '.tmp');
+ bitapps_fm_harden_dir($trashDir);
+}
+
+/**
+ * Drop a silence-stub index + a hardening .htaccess into a plugin-created upload dir.
+ * These dirs live under wp-content/uploads (web-served), so deny direct PHP execution
+ * and directory listing as defense-in-depth against a planted script — the .htaccess
+ * applies recursively, so lazily-created user_/role_ subdirs are covered too.
+ *
+ * @param mixed $dir
+ */
+function bitapps_fm_harden_dir($dir)
+{
+ if (!is_string($dir) || $dir === '' || !is_dir($dir)) {
+ return;
+ }
+
+ $index = $dir . DIRECTORY_SEPARATOR . 'index.php';
+ if (!file_exists($index)) {
+ @file_put_contents($index, "<?phpn// Silence is golden.n");
+ }
+
+ $htaccess = $dir . DIRECTORY_SEPARATOR . '.htaccess';
+ if (!file_exists($htaccess)) {
+ $rules = "Options -Indexesn"
+ . "<FilesMatch "\.(?i:php|phtml|phar|php[0-9]|pht)$">n"
+ . " <IfModule mod_authz_core.c>n"
+ . " Require all deniedn"
+ . " </IfModule>n"
+ . " <IfModule !mod_authz_core.c>n"
+ . " Order allow,denyn"
+ . " Deny from alln"
+ . " </IfModule>n"
+ . "</FilesMatch>n";
+ @file_put_contents($htaccess, $rules);
+ }
}
function bitapps_fm_uninstall()
--- a/file-manager/backend/hooks/api.php
+++ b/file-manager/backend/hooks/api.php
@@ -14,7 +14,7 @@
function () {
Route::post('theme/update', [SettingsController::class, 'updateTheme']);
- Route::get('language/get', [SettingsController::class, 'getLanguages']);
+ Route::get('language/get', [SettingsController::class, 'getLanguages'])->middleware('cap:can_access_fm_home');
Route::post('language/update', [SettingsController::class, 'updateLanguage']);
Route::post('logs/all', [LogController::class, 'all'])->middleware('cap:bitapps_fm_can_access_logs');
@@ -31,7 +31,7 @@
Route::post('permissions/user/delete', [PermissionsController::class, 'deletePermissionByUser']);
Route::post('telemetry/tryplugin', [TelemetryPopupController::class, 'tryPlugin']);
- Route::post('telemetry_permission_handle', [TelemetryPopupController::class, 'handleTelemetryPermission']);
- Route::get('telemetry_popup_disable_check', [TelemetryPopupController::class, 'isPopupDisabled']);
+ Route::post('telemetry_permission_handle', [TelemetryPopupController::class, 'handleTelemetryPermission'])->middleware('cap:can_access_fm_home');
+ Route::get('telemetry_popup_disable_check', [TelemetryPopupController::class, 'isPopupDisabled'])->middleware('cap:can_access_fm_home');
}
);
--- a/file-manager/file-manager.php
+++ b/file-manager/file-manager.php
@@ -8,7 +8,7 @@
* Plugin URI: https://bitapps.pro/bit-file-manager
* Author: File Manager by Bit Form Team
* Author URI: https://bitapps.pro
- * Version: 6.9
+ * Version: 6.9.1
* Requires at least: 5.0
* Requires PHP: 7.4
* Text domain: file-manager
--- a/file-manager/languages/generatedString.php
+++ b/file-manager/languages/generatedString.php
@@ -1,4 +1,5 @@
<?php
+if (!defined('ABSPATH')) {exit;}
/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */
$i18n_strings = array(
'404' => __('404', 'file-manager'),
--- a/file-manager/vendor/composer/installed.php
+++ b/file-manager/vendor/composer/installed.php
@@ -1,9 +1,9 @@
<?php return array(
'root' => array(
'name' => 'bitapps/file-manager',
- 'pretty_version' => '6.9',
- 'version' => '6.9.0.0',
- 'reference' => '0182b66b2c754221fdf44b4b3af3e186ee48c44a',
+ 'pretty_version' => '6.9.1',
+ 'version' => '6.9.1.0',
+ 'reference' => '63aceca391f693aab0635febd246d872b00ecc1b',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -11,9 +11,9 @@
),
'versions' => array(
'bitapps/file-manager' => array(
- 'pretty_version' => '6.9',
- 'version' => '6.9.0.0',
- 'reference' => '0182b66b2c754221fdf44b4b3af3e186ee48c44a',
+ 'pretty_version' => '6.9.1',
+ 'version' => '6.9.1.0',
+ 'reference' => '63aceca391f693aab0635febd246d872b00ecc1b',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),