Fix: Account update blocked when avatar/cover file doesn't exist (#439) - #440
Closed
polevaultweb wants to merge 1 commit into
Closed
Fix: Account update blocked when avatar/cover file doesn't exist (#439)#440polevaultweb wants to merge 1 commit into
polevaultweb wants to merge 1 commit into
Conversation
Resolves #439 The security check added in b5d95fc used realpath() to validate avatar and cover image paths before deletion. However, realpath() returns false for non-existent files, which caused the validation to incorrectly fail and throw an exception when users tried to update their accounts. This fix adds a file_exists() check before calling realpath(). The security validation is now only performed when the file actually exists, allowing account updates to proceed normally when avatar/cover files are missing (deleted, moved, or path changed). Security note: The original intent of the realpath() check (preventing directory traversal attacks) is preserved — we still validate that existing files are within the upload directory before deletion.
5 tasks
Contributor
Author
|
Superseded by #442 — simpler approach that removes the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #439
Summary
Fixes regression introduced in commit b5d95fc where account updates fail with "Path error with existing avatar" when the avatar or cover image file no longer exists on disk.
Root cause:
realpath()to validate file paths before deletionrealpath()returnsfalsefor non-existent filesstrpos(false, $upload_dir) !== 0incorrectly evaluates totrue, throwing an exceptionChanges:
file_exists()check beforerealpath()validationTesting
tests/wpunit/Account/Issue439Test.phpIssue
Resolves #439
Risk Assessment
Risk: LOW
This is a targeted fix to restore the intended behavior from before b5d95fc. The security check (preventing directory traversal) is preserved for files that exist, while non-existent files correctly skip validation.