Skip to content

🐛 Handle open_basedir restrictions in closest() directory traversal#512

Merged
retlehs merged 1 commit intomainfrom
fix/closest-open-basedir
Mar 8, 2026
Merged

🐛 Handle open_basedir restrictions in closest() directory traversal#512
retlehs merged 1 commit intomainfrom
fix/closest-open-basedir

Conversation

@retlehs
Copy link
Member

@retlehs retlehs commented Mar 8, 2026

Summary

  • Add isWithinOpenBasedir() boundary check to closest() to prevent traversing into directories outside open_basedir restrictions on shared hosting environments
  • Uses path-boundary-aware comparison (rtrim($path, '/') . '/') to avoid false positives on sibling paths (e.g. /home/user2 not matching /home/user)
  • Suppresses warnings with @ on isReadable()/isFile() as a safety net for edge cases (e.g. symlinks) the boundary check may miss
  • Adds unit test for isWithinOpenBasedir() covering allowed paths, sibling prefix traps, outside paths, and empty restriction entries

The root cause was closest() walking up the directory tree unbounded — when it hit a directory outside open_basedir, is_readable() emitted a warning that Acorn's error handler escalated into an exception. This was reported on shared hosting with both Sage and non-Bedrock installs.

Closes #380

Verification

Verified on Radicle (Bedrock) and Sage (theme) installs. Full test suite passes (89 tests, 0 failures).

🤖 Generated with Claude Code

Add an `isWithinOpenBasedir()` check to prevent `closest()` from
attempting to traverse into directories outside the `open_basedir`
restriction, which caused `is_readable()` warnings that Acorn's error
handler escalated into exceptions on shared hosting environments.

Uses path-boundary-aware comparison to avoid false positives on sibling
paths (e.g. `/home/user2` is not within `/home/user`).

The `@` operator on `isReadable()` and `isFile()` calls provides a
safety net for edge cases the boundary check may miss (e.g. symlinks).

Closes #380

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@retlehs retlehs self-assigned this Mar 8, 2026
@retlehs retlehs merged commit fbf649f into main Mar 8, 2026
3 checks passed
@retlehs retlehs deleted the fix/closest-open-basedir branch March 8, 2026 23:42
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.

open_basedir php warning restriction with shared hostings due to "closest" method

1 participant