Skip to content

Auto-mount host directories referenced in wp-config.php#3099

Open
chubes4 wants to merge 2 commits intotrunkfrom
fix/auto-mount-wp-config-paths
Open

Auto-mount host directories referenced in wp-config.php#3099
chubes4 wants to merge 2 commits intotrunkfrom
fix/auto-mount-wp-config-paths

Conversation

@chubes4
Copy link
Copy Markdown

@chubes4 chubes4 commented Apr 15, 2026

Summary

On a real WordPress server with MariaDB, if you define( 'MY_PATH', '/some/dir' ) in wp-config.php, PHP can just access that path. Studio's WASM sandbox only mounts the site folder at /wordpress, so any external path silently fails — file_exists() returns false, chmod() errors, scandir() breaks.

This PR makes Studio behave like a real server by auto-detecting host directories from wp-config.php and mounting them transparently.

How it works

  1. Parses wp-config.php for define() calls with absolute path string values
  2. Filters to paths that exist on disk and are outside the site folder
  3. Skips sensitive system paths (/etc, /var, /proc, /sys, /dev)
  4. Deduplicates
  5. Mounts each path at its real host location inside WASM (e.g. /Users/me/Developer/Users/me/Developer)

Zero configuration required. Developers write normal WordPress code and it works.

Use case

Plugins and developer tools that operate on files outside the WordPress site folder — git workspaces, shared asset directories, build output paths, data directories, AI agent memory stores. Example:

// wp-config.php
define( 'MY_WORKSPACE_PATH', '/Users/me/Developer' );

Before this PR: PHP gets file_exists() = false for that path.
After this PR: PHP can read/write/list that directory normally.

Changes

  • New: tools/common/lib/wp-config-mounts.tsgetWpConfigMountPaths() utility
  • New: tools/common/lib/tests/wp-config-mounts.test.ts — 11 tests covering edge cases
  • Modified: apps/cli/wordpress-server-child.ts — auto-mounts in getBaseRunCLIArgs() (running server path)
  • Modified: apps/cli/lib/run-wp-cli-command.ts — auto-mounts in runWpCliCommand() (standalone WP-CLI path)

Testing

Manually verified with a real site that has DATAMACHINE_WORKSPACE_PATH defined in wp-config.php:

Test Production CLI This PR
file_exists('/Users/me/Developer') false true
scandir('/Users/me/Developer') fails lists 9 entries ✅
Running server path false true
Standalone WP-CLI path false true

Fixes #3082

On a real WordPress server, PHP can access any path on the filesystem.
Studio's WASM sandbox restricts PHP to the mounted site folder, causing
plugins that reference external directories (via define() constants in
wp-config.php) to silently fail.

This parses wp-config.php for define() calls with absolute path values,
filters to paths that exist on disk and are outside the site folder, and
mounts them automatically at their real host location. Zero configuration
required — developers write normal WordPress code and it works.

Both mount sites are covered:
- getBaseRunCLIArgs() in wordpress-server-child.ts (running server)
- runWpCliCommand() in run-wp-cli-command.ts (standalone WP-CLI)

Fixes #3082
@chubes4 chubes4 force-pushed the fix/auto-mount-wp-config-paths branch from 9893353 to ee1227d Compare April 15, 2026 12:13
@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented Apr 15, 2026

📊 Performance Test Results

Comparing bd14cf8 vs trunk

app-size

Metric trunk bd14cf8 Diff Change
App Size (Mac) 1439.63 MB 1439.64 MB +0.01 MB ⚪ 0.0%

site-editor

Metric trunk bd14cf8 Diff Change
load 1942 ms 1895 ms 47 ms ⚪ 0.0%

site-startup

Metric trunk bd14cf8 Diff Change
siteCreation 9129 ms 9148 ms +19 ms ⚪ 0.0%
siteStartup 4938 ms 4965 ms +27 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

chubes4 added a commit that referenced this pull request Apr 20, 2026
path.resolve('/etc/ssl') returns '\etc\ssl' on Windows, so the
literal '/etc/' prefix check never matched and the unit test
'should skip sensitive system paths' failed on the Windows CI agent.

Use the raw POSIX-style path captured from the regex (which is
guaranteed to start with '/') instead of the resolved path. The
sensitive-roots list is intentionally Unix-only — on a real Windows
host these paths will never exist anyway, and the existsSync() check
below is the actual safety net there.

Fixes the 'Unit Tests on windows' failure on PR #3099.
chubes4 added a commit that referenced this pull request Apr 20, 2026
path.resolve('/etc/ssl') returns '\etc\ssl' on Windows, so the
literal '/etc/' prefix check never matched and the unit test
'should skip sensitive system paths' failed on the Windows CI agent.

Use the raw POSIX-style path captured from the regex (which is
guaranteed to start with '/') instead of the resolved path. The
sensitive-roots list is intentionally Unix-only — on a real Windows
host these paths will never exist anyway, and the existsSync() check
below is the actual safety net there.

Fixes the 'Unit Tests on windows' failure on PR #3099.
path.resolve('/etc/ssl') returns '\etc\ssl' on Windows, so the
literal '/etc/' prefix check never matched and the unit test
'should skip sensitive system paths' failed on the Windows CI agent.

Use the raw POSIX-style path captured from the regex (which is
guaranteed to start with '/') instead of the resolved path. The
sensitive-roots list is intentionally Unix-only — on a real Windows
host these paths will never exist anyway, and the existsSync() check
below is the actual safety net there.

Fixes the 'Unit Tests on windows' failure on PR #3099.
@chubes4 chubes4 force-pushed the fix/auto-mount-wp-config-paths branch from da95589 to bd14cf8 Compare April 20, 2026 11:49
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.

Support mounting additional host directories into the WASM filesystem

2 participants