Skip to content

fix(WireFileTools): remove redundant strpos check in rmdir scandir loop - #326

Open
gebeer wants to merge 3 commits into
processwire:devfrom
gebeer:fix/wiretmpdir
Open

fix(WireFileTools): remove redundant strpos check in rmdir scandir loop#326
gebeer wants to merge 3 commits into
processwire:devfrom
gebeer:fix/wiretmpdir

Conversation

@gebeer

@gebeer gebeer commented Mar 9, 2026

Copy link
Copy Markdown

Summary

WireFileTools::rmdir() line 131 has an overly broad strpos check that prevents legitimate files from being deleted during recursive directory removal.

// Before
if($file == '.' || $file == '..' || strpos($file, '..') !== false) continue;

// After
if($file == '.' || $file == '..') continue;

scandir() returns bare filenames (no slashes), so directory traversal via .. is impossible in this context. The only dangerous entry is the literal '..' string, already handled by $file == '..'.

The strpos check incorrectly skips any file whose basename contains .. (e.g. image resize variants like name.m.d..500x0.jpg), leaving temp dirs permanently un-deletable and causing files-errors log spam on every request.

Note: lines 296 and 307 in the same file correctly use only $file == '..' without the strpos check.

Reported in: processwire/processwire-issues#2191

gebeer and others added 3 commits April 6, 2023 15:16
scandir() returns bare filenames with no slashes, so directory traversal
via '..' is impossible. The strpos check incorrectly skips legitimate files
whose basenames contain '..', preventing cleanup of temp dirs for images
with consecutive dots in their filename (e.g. name.m.d..500x0.jpg).

The literal '..' parent dir entry is already handled by $file == '..'.

Fixes: processwire/processwire-issues#2191

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant