Skip to content

Fix: Account update blocked when avatar/cover file doesn't exist (#439) - #440

Closed
polevaultweb wants to merge 1 commit into
developfrom
439-fix-avatar-path-validation
Closed

Fix: Account update blocked when avatar/cover file doesn't exist (#439)#440
polevaultweb wants to merge 1 commit into
developfrom
439-fix-avatar-path-validation

Conversation

@polevaultweb

@polevaultweb polevaultweb commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

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:

  • The security check uses realpath() to validate file paths before deletion
  • realpath() returns false for non-existent files
  • strpos(false, $upload_dir) !== 0 incorrectly evaluates to true, throwing an exception

Changes:

  • Added file_exists() check before realpath() validation
  • Security check now only runs when the file actually exists
  • Users can update accounts normally when avatar/cover files are missing

Testing

  • New unit tests added: tests/wpunit/Account/Issue439Test.php
    • Tests account update succeeds when avatar path is missing
    • Tests account update succeeds when cover path is missing
    • Tests security check still blocks directory traversal when file exists
  • All existing tests pass (CI will verify)
  • Manual testing: Account updates work with missing avatar files

Issue

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.

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.
@polevaultweb

Copy link
Copy Markdown
Contributor Author

Superseded by #442 — simpler approach that removes the realpath() checks entirely and just guards wp_delete_file() calls with file_exists(). wp_delete_file() already prevents deletion outside ABSPATH in modern WordPress, making the path validation redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression bug introduced in v2.9.13 (commit b5d95fc)

1 participant