Skip to content

Commit 148120b

Browse files
authored
Updates
1 parent 7d04af6 commit 148120b

4 files changed

Lines changed: 49 additions & 99 deletions

File tree

.github/copilot-instructions.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ You must read files completely and thoroughly, with a minimum of 1500 lines per
3535
- Follow WordPress theme and plugin development guidelines.
3636
- Use WordPress REST API for custom endpoints and data retrieval.
3737
- Ensure all code is compatible with the WordPress ecosystem, including themes and plugins.
38-
- As this is a WordPress-focused project, avoid using frameworks or libraries that are not compatible with WordPress.
39-
- Do not use frameworks or libraries that are not commonly used in the WordPress ecosystem.
38+
- As this is a WordPress-focused project, avoid using frameworks or libraries that are not compatible or commonly used with WordPress.
4039
- Avoid using non-standard or experimental features that are not widely adopted in the WordPress community.
41-
- For any project that utilizes WooCommerce, ensure minimum version compatibility with WooCommerce 5.0+.
4240

4341
## WordPress Coding Standards
4442

@@ -63,7 +61,7 @@ You must read files completely and thoroughly, with a minimum of 1500 lines per
6361
- WordPress 6.5+ (minimum)
6462
- PHP 7.4+ (minimum)
6563
- WooCommerce 5.0+ (if applicable)
66-
- Do not use features or functions that are not available in these versions.
64+
- Do not use features or functions that are deprecated or not available in these versions.
6765

6866
## Version Control and Documentation
6967

@@ -86,8 +84,8 @@ You must read files completely and thoroughly, with a minimum of 1500 lines per
8684
- Note: changelog.txt has been removed from this project. Only maintain readme.txt (for WordPress.org) and CHANGELOG.md (for developers).
8785
- Please do not skip these locations, as the changelog files must be in sync with each other, and the version numbers must be consistent across all files.
8886
- I will instruct you when to update the version number, and you should not do this automatically. Always ask for confirmation before updating the version number.
89-
- When the version number is updated, ensure that the new version number is reflected in all relevant files, including the plugin header, changelog files, and documentation files.
90-
- WHen the version number is updated, make special note to update the "Unreleased" section in the changelog files to reflect the new version number and a brief description of the changes made. This ensures that all changes are documented and easily accessible for future reference.
87+
- When the version number is updated, ensure that the new version number is reflected in all relevant files, as outlined in Version Locations above.
88+
- When the version number is updated, make special note to update the "Unreleased" section in the changelog files to reflect the new version number and a brief description of the changes made. This ensures that all changes are documented and easily accessible for future reference.
9189

9290
# General Coding Standards
9391

@@ -132,7 +130,7 @@ You must read files completely and thoroughly, with a minimum of 1500 lines per
132130
- If you encounter a security vulnerability in the codebase, do not disclose it publicly. Instead, report it privately to the project maintainers or through a responsible disclosure process.
133131
- If you are unsure about the security implications of a specific code change, ask for clarification or guidance before proceeding.
134132
- Always follow the principle of least privilege when implementing security features, ensuring that users and processes have only the permissions they need to perform their tasks.
135-
- If you encounter a security vulnerability in a third-party library or dependency, check if there is an updated version that addresses the issue. If not, consider alternatives or report the vulnerability to the library maintainers.
133+
- If you encounter a security vulnerability in a third-party library or dependency, check if there is an updated version that addresses the issue. If not, consider alternatives and notify me of the situation.
136134
- If there is a possible security vulnerability in the codebase, you should always ask for confirmation before proceeding with any changes. This ensures that the project maintainers are aware of the potential risk and can provide guidance on how to address it safely.
137135
- If I ask you to make changes that could potentially introduce security vulnerabilities, you should always ask for confirmation before proceeding. This ensures that the project maintainers are aware of the potential risk and can provide guidance on how to address it safely.
138136

@@ -150,7 +148,6 @@ You must read files completely and thoroughly, with a minimum of 1500 lines per
150148
- Only ask for confirmation when an action is destructive (e.g., data loss, deletion)
151149
- Always attempt to identify and fix bugs automatically
152150
- Only ask for manual intervention if domain-specific knowledge is required
153-
- Auto-generate missing files, boilerplate, and tests when possible
154151
- Auto-lint and format code using standard tools (e.g., Prettier, ESLint, dotnet format)
155152
- Changes should be made directly to the file in question. Example: admin.php should be modified directly, not by creating a new file like admin-changes.php.
156153
- New files may be created when appropriate, but they should be relevant to the task at hand, so long as they are not a rewrite of an existing file. We want to avoid unnecessary duplication of files.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog for Simple WP Site Exporter
22

3+
## Unreleased
4+
5+
### Security Fix
6+
- **Critical Security Fix**: Resolved a fatal error caused by a missing `sse_get_safe_wp_cli_path()` function. This function is essential for securely locating the WP-CLI executable, and its absence prevented the database export process from running. The new function ensures that the plugin can reliably find WP-CLI in common locations, allowing the export to proceed as intended.
7+
38
## 1.8.1 - July 11, 2025
49
### Documentation Workflow Updates
510
- **Version Control**: Removed `changelog.txt` file to streamline documentation; maintaining only `readme.txt` (WordPress.org) and `CHANGELOG.md` (for developers).

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: enginescript
33
Tags: backup, export, migration, site export, database export
44
Requires at least: 6.5
55
Tested up to: 6.8
6-
Stable tag: 1.8.1
6+
Stable tag: 1.8.2
77
Requires PHP: 7.4
88
License: GPLv3 or later
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -89,6 +89,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
8989

9090
== Changelog ==
9191

92+
= 1.8.2 =
93+
* **Critical Security Fix**: Resolved a fatal error caused by a missing `sse_get_safe_wp_cli_path()` function. This function is essential for securely locating the WP-CLI executable, and its absence prevented the database export process from running. The new function ensures that the plugin can reliably find WP-CLI in common locations, allowing the export to proceed as intended.
94+
9295
= Unreleased =
9396
* **Documentation Workflow**: Removed changelog.txt file to streamline documentation process
9497
* **Version Control**: Maintaining only readme.txt (WordPress.org) and CHANGELOG.md (developers) for changelog management

simple-wp-site-exporter.php

Lines changed: 35 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: Simple WP Site Exporter
44
* Description: Exports the site files and database as a zip archive.
5-
* Version: 1.8.1
5+
* Version: 1.8.2
66
* Author: EngineScript
77
* License: GPL v3 or later
88
* Text Domain: Simple-WP-Site-Exporter
@@ -17,7 +17,7 @@
1717

1818
// Define plugin version.
1919
if ( ! defined( 'ES_WP_SITE_EXPORTER_VERSION' ) ) {
20-
define( 'ES_WP_SITE_EXPORTER_VERSION', '1.8.1' );
20+
define( 'ES_WP_SITE_EXPORTER_VERSION', '1.8.2' );
2121
}
2222

2323
/**
@@ -391,6 +391,38 @@ function sse_create_index_file( $export_dir ) {
391391
sse_log('Failed to write index.php file or directory not writable: ' . $export_dir, 'error');
392392
}
393393

394+
/**
395+
* Finds a safe path to the WP-CLI executable.
396+
*
397+
* @return string|WP_Error The path to WP-CLI on success, or a WP_Error on failure.
398+
*/
399+
function sse_get_safe_wp_cli_path() {
400+
// Check for WP-CLI in common paths.
401+
$common_paths = array(
402+
ABSPATH . 'wp-cli.phar',
403+
dirname( ABSPATH ) . '/wp-cli.phar',
404+
'/usr/local/bin/wp',
405+
'/usr/bin/wp',
406+
);
407+
408+
foreach ( $common_paths as $path ) {
409+
if ( is_executable( $path ) ) {
410+
return $path;
411+
}
412+
}
413+
414+
// Check if 'wp' is in the system's PATH.
415+
// Use 'where' for Windows and 'command -v' for Unix-like systems.
416+
$command = ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) ? 'where wp' : 'command -v wp';
417+
$path = shell_exec( $command ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec -- Safe command to find executable.
418+
419+
if ( ! empty( $path ) ) {
420+
return trim( $path );
421+
}
422+
423+
return new WP_Error( 'wp_cli_not_found', __( 'WP-CLI executable not found. Please ensure it is installed and in your server\'s PATH.', 'Simple-WP-Site-Exporter' ) );
424+
}
425+
394426
/**
395427
* Exports the database and returns file information.
396428
*
@@ -998,7 +1030,7 @@ function sse_sanitize_filename( $filename ) {
9981030
*
9991031
* @param string|false $real_file_path The real file path or false if resolution failed.
10001032
* @param string $real_base_dir The real base directory path.
1001-
* @return bool True if file is within base directory, false otherwise.
1033+
* @return bool True if the file is within the base directory, false otherwise.
10021034
*/
10031035
function sse_check_path_within_base( $real_file_path, $real_base_dir ) {
10041036
// Ensure both paths are available for comparison
@@ -1518,91 +1550,4 @@ function sse_serve_file_download( $fileData ) {
15181550

15191551
// Output file content
15201552
sse_output_file_content( $sanitizedData['filepath'], $sanitizedData['filename'] );
1521-
}
1522-
1523-
/**
1524-
* Safely get and validate WP-CLI path with enhanced security checks.
1525-
*
1526-
* @return string|WP_Error WP-CLI path on success, WP_Error on failure.
1527-
*/
1528-
function sse_get_safe_wp_cli_path() {
1529-
// First try to get WP-CLI path
1530-
$wp_cli_path = trim( shell_exec( 'which wp 2>/dev/null' ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec -- Required for WP-CLI path discovery: uses system 'which' command with constant parameters
1531-
1532-
$basic_validation = sse_validate_wp_cli_path($wp_cli_path);
1533-
if (is_wp_error($basic_validation)) {
1534-
return $basic_validation;
1535-
}
1536-
1537-
$security_check = sse_validate_wp_cli_security($wp_cli_path);
1538-
if (is_wp_error($security_check)) {
1539-
return $security_check;
1540-
}
1541-
1542-
$binary_verification = sse_verify_wp_cli_binary($wp_cli_path);
1543-
if (is_wp_error($binary_verification)) {
1544-
return $binary_verification;
1545-
}
1546-
1547-
return $wp_cli_path;
1548-
}
1549-
1550-
/**
1551-
* Validates basic WP-CLI path format.
1552-
*
1553-
* @param string $wp_cli_path The WP-CLI path to validate.
1554-
* @return true|WP_Error True on success, WP_Error on failure.
1555-
*/
1556-
function sse_validate_wp_cli_path($wp_cli_path) {
1557-
if ( empty( $wp_cli_path ) ) {
1558-
return new WP_Error( 'wp_cli_not_found', __( 'WP-CLI not found on this server.', 'Simple-WP-Site-Exporter' ) );
1559-
}
1560-
1561-
// Validate path format (must be absolute path)
1562-
if ( strpos( $wp_cli_path, '/' ) !== 0 && strpos( $wp_cli_path, '\\' ) !== 0 ) {
1563-
return new WP_Error( 'wp_cli_not_absolute', __( 'WP-CLI path is not absolute.', 'Simple-WP-Site-Exporter' ) );
1564-
}
1565-
1566-
return true;
1567-
}
1568-
1569-
/**
1570-
* Validates WP-CLI path for security issues.
1571-
*
1572-
* @param string $wp_cli_path The WP-CLI path to validate.
1573-
* @return true|WP_Error True on success, WP_Error on failure.
1574-
*/
1575-
function sse_validate_wp_cli_security($wp_cli_path) {
1576-
// Check if path looks suspicious (basic security check)
1577-
if ( strpos( $wp_cli_path, ';' ) !== false || strpos( $wp_cli_path, '|' ) !== false ||
1578-
strpos( $wp_cli_path, '&' ) !== false || strpos( $wp_cli_path, '$' ) !== false ) {
1579-
return new WP_Error( 'wp_cli_suspicious', __( 'Suspicious characters detected in WP-CLI path.', 'Simple-WP-Site-Exporter' ) );
1580-
}
1581-
1582-
// Check if file exists and is executable
1583-
if ( ! file_exists( $wp_cli_path ) ) {
1584-
return new WP_Error( 'wp_cli_not_exists', __( 'WP-CLI executable not found at detected path.', 'Simple-WP-Site-Exporter' ) );
1585-
}
1586-
1587-
if ( ! is_executable( $wp_cli_path ) ) {
1588-
return new WP_Error( 'wp_cli_not_executable', __( 'WP-CLI file is not executable.', 'Simple-WP-Site-Exporter' ) );
1589-
}
1590-
1591-
return true;
1592-
}
1593-
1594-
/**
1595-
* Verifies that the binary is actually WP-CLI.
1596-
*
1597-
* @param string $wp_cli_path The WP-CLI path to verify.
1598-
* @return true|WP_Error True on success, WP_Error on failure.
1599-
*/
1600-
function sse_verify_wp_cli_binary($wp_cli_path) {
1601-
// Additional security: verify it's actually WP-CLI by running --version
1602-
$version_check = shell_exec( escapeshellarg( $wp_cli_path ) . ' --version 2>/dev/null' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec -- Required for WP-CLI binary verification: path is validated and escaped with escapeshellarg()
1603-
if ( empty( $version_check ) || strpos( $version_check, 'WP-CLI' ) === false ) {
1604-
return new WP_Error( 'wp_cli_invalid_binary', __( 'Detected file is not a valid WP-CLI executable.', 'Simple-WP-Site-Exporter' ) );
1605-
}
1606-
1607-
return true;
16081553
}

0 commit comments

Comments
 (0)