Skip to content

fix(security): skip FORBIDDEN_ROOTS check on Windows in assertSafeDir…#1267

Open
riannugraha wants to merge 1 commit into
XiaomiMiMo:mainfrom
riannugraha:fix/assert-safe-directory-windows-false-positive
Open

fix(security): skip FORBIDDEN_ROOTS check on Windows in assertSafeDir…#1267
riannugraha wants to merge 1 commit into
XiaomiMiMo:mainfrom
riannugraha:fix/assert-safe-directory-windows-false-positive

Conversation

@riannugraha

Copy link
Copy Markdown

Issue for this PR

Closes #1264

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On Windows, any project path containing \dev\ (e.g. C:\dev\test) falsely triggers "Access denied: target is a protected system directory".

assertSafeDirectory checks FORBIDDEN_ROOTS which only contains Unix paths (/dev, /etc, etc.). On Windows, path.relative("/dev", "C:\\dev\\test") returns "test" (not starting with ..), so AppFileSystem.contains() incorrectly returns true.

This fix skips the FORBIDDEN_ROOTS check when process.platform === "win32" since those Unix paths don't exist on Windows.

How did you verify your code works?

  • Ran bun dev C:\dev\test before fix: error occurs
  • Ran bun dev C:\dev\test after fix: works correctly
  • Change is 1 line, no type changes needed

Screenshots / recordings

N/A — not a UI change

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…ectory

Fixes XiaomiMiMo#1264

On Windows, assertSafeDirectory falsely rejects directories containing
'\dev\' in the path (e.g. C:\dev\test) because path.relative()
between a Unix path ('/dev') and a Windows path returns a non-'..' result,
causing AppFileSystem.contains() to incorrectly return true.

The FORBIDDEN_ROOTS list only contains Unix-specific paths (/etc, /proc,
/sys, /dev, etc.) that don't exist on Windows. Skip the check entirely
when process.platform === 'win32' to avoid false positives.

Before: Any Windows path containing \dev\ triggered 'Access denied:
target is a protected system directory'
After: The check is skipped on Windows, allowing valid project directories.
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.

Access denied: target is a protected system directory on Windows with C:\dev\ path

1 participant