Skip to content

Commit

Permalink
Release 4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Olivares committed Nov 22, 2023
1 parent 3504e93 commit d7a1804
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 134 deletions.
6 changes: 3 additions & 3 deletions backwpup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Plugin Name: BackWPup
* Plugin URI: http://backwpup.com
* Description: WordPress Backup Plugin
* Author: WP Media
* Author URI: https://wp-media.me
* Version: 4.0.1
* Author: WP MEDIA SAS
* Author URI: https://wp-media.me/
* Version: 4.0.2
* Requires at least: 3.9
* Requires PHP: 7.2
* Text Domain: backwpup
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
== Changelog ==
= 4.0.2 =
Release date: November 22, 2023

* Fixed: Disallow backups or logs directories from being outside of wp-content directory for security purposes

= 4.0.1 =
Release date: October 18, 2023

Expand Down
27 changes: 3 additions & 24 deletions inc/class-destination-folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public function edit_form_post_save(int $jobid): void
$backup_dir = trim(sanitize_text_field($_POST['backupdir']));

try {
$backup_dir = trailingslashit(self::normalizePath(BackWPup_Path_Fixer::slashify($backup_dir)));
$backup_dir = trailingslashit(
BackWPup_File::normalize_path(BackWPup_Path_Fixer::slashify($backup_dir))
);
} catch (\InvalidArgumentException $e) {
$backup_dir = self::getDefaultBackupsDirectory();
}
Expand Down Expand Up @@ -301,27 +303,4 @@ private static function getDefaultBackupsDirectory()

return str_replace($content_path, '', $backups_dir);
}

private static function normalizePath($path)
{
$parts = explode('/', $path);
$normalized = [];

foreach ($parts as $part) {
if ($part === '..') {
if (empty($normalized)) {
throw new InvalidArgumentException('Invalid path: Attempting to navigate above the root directory.');
}
array_pop($normalized);
} elseif ($part !== '.' && $part !== '') {
$normalized[] = $part;
}
}

if (empty($normalized)) {
throw new \InvalidArgumentException('The path resolves to an empty path.');
}

return implode('/', $normalized);
}
}
34 changes: 34 additions & 0 deletions inc/class-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,40 @@ public static function check_folder($folder, $donotbackup = false)
return '';
}

/**
* @throws InvalidArgumentException If path is absolute or attempts to navigate above root
*
* @return string[]
*/
public static function normalize_path(string $path): string
{
if (strpos($path, '/') === 0) {
throw new InvalidArgumentException('Absolute paths are not allowed.');
}

$parts = explode('/', $path);
$normalized = [];

foreach ($parts as $part) {
if ($part === '..') {
if (empty($normalized)) {
throw new InvalidArgumentException(
'Invalid path: Attempting to navigate above the root directory.'
);
}
array_pop($normalized);
} elseif ($part !== '.' && $part !== '') {
$normalized[] = $part;
}
}

if (empty($normalized)) {
throw new InvalidArgumentException('The path resolves to an empty path.');
}

return implode('/', $normalized);
}

/**
* Resolve internal .. within a path.
*
Expand Down
13 changes: 6 additions & 7 deletions inc/class-page-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,15 @@ public function save_post_form()

update_site_option('backwpup_cfg_jobrunauthkey', $_POST['jobrunauthkey']);

$_POST['logfolder'] = trailingslashit(
str_replace('\\', '/', trim(stripslashes(sanitize_text_field($_POST['logfolder']))))
);
try {
$_POST['logfolder'] = trailingslashit(
BackWPup_File::normalize_path(BackWPup_Path_Fixer::slashify(sanitize_text_field($_POST['logfolder'])))
);

//set def. folders
if (empty($_POST['logfolder']) || $_POST['logfolder'] === '/') {
update_site_option('backwpup_cfg_logfolder', $_POST['logfolder']);
} catch (InvalidArgumentException $e) {
delete_site_option('backwpup_cfg_logfolder');
BackWPup_Option::default_site_options();
} else {
update_site_option('backwpup_cfg_logfolder', $_POST['logfolder']);
}

$authentication = get_site_option(
Expand Down
Loading

0 comments on commit d7a1804

Please sign in to comment.