Repository navigation
fix: use wp_handle_upload for import-archive intake - #17
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughZIP import-preview now uses WordPress upload helpers ( ChangesUpload stash refactoring
Sequence DiagramsequenceDiagram
participant Admin as handle_import_preview
participant FileHelpers as wp_admin_file_php
participant Uploader as wp_handle_upload
participant Scheduler as wp_schedule_single_event
participant Cleaner as cleanup_preview_file
Admin->>FileHelpers: require_once file.php
Admin->>Uploader: call wp_handle_upload for zip
Uploader-->>Admin: return file or error
Admin->>Scheduler: schedule opentrust_io_preview_cleanup(stash_path,user_id)
Scheduler->>Cleaner: call cleanup_preview_file(stash_path,user_id)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
includes/class-opentrust-admin-tools.php (1)
329-367:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftPreview ZIPs are orphaned in the public uploads directory.
wp_handle_upload()moves the file to wp-content/uploads/YYYY/MM/ and makes it publicly accessible. While the transient expires after 30 minutes, the ZIP file itself is never cleaned up—neither during normal expiry nor if the admin abandons the preview. Once the transient is gone, the file becomes an orphaned artifact accessible via direct URL indefinitely. For sensitive import archives, move the validated file to a non-public temp location with an unguessable name, or use an explicit cleanup mechanism (e.g., wp_scheduled_delete hook) that fires when the transient expires.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@includes/class-opentrust-admin-tools.php` around lines 329 - 367, The uploaded ZIP is left in the public uploads dir after wp_handle_upload() and set_transient('opentrust_io_preview_' . get_current_user_id(), ...), so change the flow to move the validated file ($stash_path after OpenTrust_IO::read_zip/validate_manifest) out of the public uploads folder into a non-public temp location (use wp_tempnam()/get_temp_dir() or similar to create an unguessable filename) and update $stash_path used for preview; additionally schedule a cleanup (use wp_schedule_single_event with a custom hook that unlinks the temp file) to run when the transient would expire (or delete the file when import completes/fails), and ensure the scheduled cleanup references the same transient key (opentrust_io_preview_{user_id}) so orphaned files are removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@uninstall.php`:
- Around line 72-79: The legacy stash cleanup currently only deletes files found
in $ot_legacy and then calls `@rmdir`($ot_stash), which will fail if nested
directories exist; update the uninstall block (the code that builds $ot_legacy
and calls wp_delete_file/@rmdir) to perform a recursive removal of $ot_stash
contents (e.g., walk the directory with a
RecursiveDirectoryIterator/RecursiveIteratorIterator or a small helper that
deletes files and directories depth-first) before removing $ot_stash, or
alternatively add an explicit check/assert that pre-1.1.0 layout was flat and
leave a comment documenting that guarantee.
---
Outside diff comments:
In `@includes/class-opentrust-admin-tools.php`:
- Around line 329-367: The uploaded ZIP is left in the public uploads dir after
wp_handle_upload() and set_transient('opentrust_io_preview_' .
get_current_user_id(), ...), so change the flow to move the validated file
($stash_path after OpenTrust_IO::read_zip/validate_manifest) out of the public
uploads folder into a non-public temp location (use wp_tempnam()/get_temp_dir()
or similar to create an unguessable filename) and update $stash_path used for
preview; additionally schedule a cleanup (use wp_schedule_single_event with a
custom hook that unlinks the temp file) to run when the transient would expire
(or delete the file when import completes/fails), and ensure the scheduled
cleanup references the same transient key (opentrust_io_preview_{user_id}) so
orphaned files are removed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 1c718b29-4cfb-4473-851d-e26aaa7d8321
📒 Files selected for processing (2)
includes/class-opentrust-admin-tools.phpuninstall.php
Claude Code reviewVerdict: Approve. The change cleanly routes the import-archive intake through What I verified
Optional nit (non-blocking)
— Claude (automated review on behalf of @nolderoos) |
…stall cleanup Address two CodeRabbit findings on PR #17: - Stash import-preview ZIPs in a plugin-private wp-content/uploads/opentrust-tmp/ via a scoped upload_dir filter around the wp_handle_upload() call, protected by an .htaccess deny-all and a blank index.html. Schedule a single-event cleanup keyed to the 30-min transient TTL with realpath-based containment guard and an active-preview check. Wires the cleanup hook from the class constructor; clears it on uninstall alongside the other scheduled events. Replaces the public-uploads exposure flagged in the PR review body without reverting wp_handle_upload (which the wporg reviewer required in 05-file-uploader). - Replace the flat glob()+is_file() walk in uninstall.php with a depth-first RecursiveDirectoryIterator / RecursiveIteratorIterator(CHILD_FIRST) so any nested directories in the stash are torn down too. Wrapped in try/catch so uninstall is never fatal. Fixes the legacy-stash cleanup gap flagged at #17 (comment). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Re: the outside-diff comment about preview ZIPs orphaned in public uploads — addressed in 2122ed7. The fix scopes an |
New methods added in 2122ed7 (stash_dir, install_stash_upload_filter, cleanup_preview_file) shifted line numbers below in includes/class-opentrust-admin-tools.php. No translatable strings were added or changed — only `#:` source-reference lines updated. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Closes #16
What
Replaces
move_uploaded_file()inOpenTrust_Admin_Tools::handle_import_preview()withwp_handle_upload(). Drops the legacyopentrust-tmp/quarantine directory; files now land inwp-content/uploads/YYYY/MM/via the standard WP upload pipeline. Adds a one-shot legacy directory sweep touninstall.phpfor sites upgrading from <1.1.0.Why
wp.org review round 1, issue 5. Direct
move_uploaded_file()bypasses WP's MIME validation (wp_check_filetype_and_ext), theupload_mimesfilter chain, and any third-party security hooks.wp_handle_upload()is the canonical wrapper.QA
wp plugin check opentrust --include-experimental— zero new errors or warnings on the changed files.is_uploaded_file()precheck all retained.OpenTrust_IO::read_zip, transient stash,wp_delete_fileinhandle_import_apply) are path-agnostic — no change.Summary by CodeRabbit
Refactor
Chores
Documentation