Skip to content

Commit e30dce2

Browse files
authored
Refactor
1 parent 7c7b323 commit e30dce2

File tree

7 files changed

+388
-637
lines changed

7 files changed

+388
-637
lines changed

CHANGELOG.md

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

3+
## Unreleased
4+
5+
### Security
6+
7+
- **Export Directory Protection**: Added `.htaccess` file to the export directory with `Deny from all` rules (Apache 2.2 and 2.4) to prevent direct HTTP access to export files during the cleanup window. Previously only an `index.php` prevented directory listing.
8+
- **Private API Removal**: Removed usage of `_get_cron_array()` (WordPress private/internal function) from cron failure diagnostics. Uses only public APIs (`wp_next_scheduled()`, `wp_schedule_single_event()`) now.
9+
- **Filesystem Compatibility**: Replaced `glob()` with `scandir()` in `sse_bulk_cleanup_exports_handler()` for cross-platform compatibility and consistency with WordPress filesystem conventions.
10+
- **SSRF Hardening**: File download functions now use `realpath()`-resolved paths for all filesystem operations (`readfile()`, `is_readable()`, `is_file()`), preventing TOCTOU and SSRF attack vectors. `sse_validate_file_output_security()` now returns the resolved path for direct use.
11+
12+
### Bug Fixes
13+
14+
- **Documentation Fix**: Corrected README.md Security Features section from "after 1 hour" to "after 5 minutes" to match actual cleanup timer.
15+
- **Unused Variable**: Removed unused `$export_dir_name` variable assignment in `sse_exporter_page_html()`.
16+
- **phpcs Suppression**: Removed unnecessary `phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped` comment on a line already properly escaped with `esc_html()`.
17+
- **GEMINI.md Accuracy**: Updated WP-CLI Integration section to reflect that WP-CLI is a required dependency (returns `WP_Error` if unavailable), replacing outdated "graceful fallback" language.
18+
19+
### Architecture
20+
21+
- **WP_Filesystem Helper**: Extracted duplicated `WP_Filesystem` initialization from 4 functions into a single `sse_init_filesystem()` helper that returns `true|WP_Error`, reducing ~40 lines of duplicated code to ~10.
22+
- **Removed Wrapper Functions**: Inlined 3 pass-through wrapper functions (`sse_validate_download_request()`, `sse_validate_file_deletion()`, `sse_validate_export_file_for_deletion()`) — callers now invoke the underlying functions directly.
23+
- **Download Validation Consolidation**: Removed 2 redundant intermediate validation passes (`sse_validate_download_file_data()`, `sse_validate_download_file_access()`) from the download flow. Entry validation and final `readfile()` security gate remain; intermediate re-validation of already-validated data removed.
24+
- **Path Resolution Consolidation**: Consolidated 7-function-deep path resolution chain into a single `sse_resolve_file_path()` function. Removed 6 single-use intermediary functions (`sse_resolve_nonexistent_file_path()`, `sse_get_upload_directory_info()`, `sse_build_validated_file_path()`, `sse_validate_parent_directory_safety()`, `sse_construct_final_file_path()`, `sse_resolve_parent_directory()`, `sse_sanitize_filename()`).
25+
- **Dead Code Removal**: Removed no-op `sse_prepare_execution_environment()` function and its call from the export flow.
26+
- **Debug Code Removal**: Removed `sse_test_cron_scheduling()` debug function that created/verified/removed a test cron event on every export — no longer needed after v2.0.0 cron fixes.
27+
- **Cron Logging Reduction**: Reduced cron scheduling functions from 5+ log entries each to 2 (success/failure), keeping `DISABLE_WP_CRON` diagnostic on failure only.
28+
29+
### PHP 7.4 Modernization
30+
31+
- **Type Declarations**: Added PHP 7.4 parameter types and return types to all functions where deterministic. Functions returning union types (`array|WP_Error`, `string|false`, `true|WP_Error`) retain PHPDoc-only annotations since PHP 7.4 does not support union return types.
32+
- **Short Array Syntax**: Standardized all `array()` constructor calls to short `[]` syntax throughout the plugin.
33+
- **Null Coalescing Assignment**: Replaced explicit null check + assignment pattern with PHP 7.4 `??=` operator in `sse_should_exclude_file()` file size cache, and `?:` Elvis operator for the ternary fallback.
34+
335
## 2.0.0 - March 1, 2026
436

537
### Critical Bug Fixes

GEMINI.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ add_action( 'plugins_loaded', 'sse_init_plugin' );
124124

125125
### WP-CLI Integration
126126

127-
- **Database Export:** Efficient database dumps when WP-CLI available
127+
- **Database Export:** Efficient database dumps via WP-CLI
128128
- **Security Validation:** WP-CLI executable verification
129-
- **Error Handling:** Graceful fallback when WP-CLI unavailable
129+
- **Error Handling:** Returns WP_Error when WP-CLI is unavailable (required dependency)
130130
- **Root Detection:** Conditional --allow-root flag usage
131131

132132
## Development Standards

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ EngineScript Site Exporter is built with security as a priority:
7373
- **Secure Downloads**: All downloads are validated with WordPress nonces
7474
- **Request Validation**: Referrer checking for all operations
7575
- **Path Traversal Protection**: Comprehensive file path validation
76-
- **Automatic Deletion**: Exports are automatically cleaned up after 1 hour
76+
- **Automatic Deletion**: Exports are automatically cleaned up after 5 minutes
7777
- **Security Headers**: Implements proper headers for download operations
7878
- **Secure File Handling**: Uses WordPress Filesystem API for file operations
7979

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@
2020
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
2121
"php-stubs/wordpress-stubs": "^6.8",
2222
"szepeviktor/phpstan-wordpress": "^1.3",
23-
"phpstan/phpstan": "^1.0"
23+
"phpstan/phpstan": "^1.0",
24+
"phpcompatibility/phpcompatibility-wp": "^2.1"
2425
},
2526
"config": {
2627
"allow-plugins": {
2728
"dealerdirect/phpcodesniffer-composer-installer": true
2829
}
30+
},
31+
"scripts": {
32+
"lint:php": "phpcs",
33+
"analyze": "phpstan analyse"
2934
}
30-
}
35+
}

0 commit comments

Comments
 (0)