Skip to content

Fix Windows PowerShell resource path authorization - #7943

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
Imagineer99:fix/windows-powershell-resource-path
Aug 5, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
Imagineer99:fix/windows-powershell-resource-path

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Summary

  • keep the Defender-friendly Windows launcher shape introduced in Sign the NSIS plugin DLLs, and fail the release on any unsigned file #7819 (RemoteSigned plus CREATE_NO_WINDOW)
  • convert Tauri's Win32 verbatim resource paths to ordinary drive or UNC paths before passing install.ps1 to Windows PowerShell 5.1
  • leave ordinary paths and unsupported device namespace paths unchanged
  • cover drive, UNC, ordinary, and unsupported verbatim paths with a Windows unit test

Root cause

Tauri can resolve the bundled script as \\?\C:\...\install.ps1. Windows PowerShell 5.1's RemoteSigned authorization rejects that spelling with AuthorizationManager check failed / UnauthorizedAccess, even when the script's Authenticode signature is valid and it has no Zone.Identifier. The equivalent C:\...\install.ps1 path authorizes successfully.

This keeps RemoteSigned; it does not restore the -WindowStyle Hidden -ExecutionPolicy Bypass command shape that was removed because it matched a Microsoft Defender detection signature.

Validation

  • rustfmt --edition 2021 --check studio/src-tauri/src/install.rs
  • npm ci --no-fund --no-audit && npm run build in studio/frontend
  • cargo test powershell_script_path_normalizes_verbatim_filesystem_paths -- --nocapture on Windows: 1 passed
  • disposable Windows runner using the exact signed 0.1.52-beta installer:
    • verbatim path + RemoteSigned reproduced AuthorizationManager / UnauthorizedAccess
    • normalized path + RemoteSigned authorized the exact signed script
    • the Rust normalization implementation compiled and passed its behavioral check

The runner validates the authorization fix while retaining the Defender-friendly command shape. Absence of consumer Defender notifications still requires final testing with the fully signed release installer.

@danielhanchen

Copy link
Copy Markdown
Member

I reproduced this on a real windows-latest runner before touching anything, and the diagnosis holds. Pushed three follow-ups in 88abb32.

The root cause is confirmed, and the code path is the only one

Same file, same directory, only the spelling differs, Windows PowerShell 5.1.26100.33158:

invocation script ran error
-ExecutionPolicy RemoteSigned -File C:\Users\...\Unsloth Studio (Desktop)\install.ps1 yes none
-ExecutionPolicy RemoteSigned -File \\?\C:\Users\...\Unsloth Studio (Desktop)\install.ps1 no FullyQualifiedErrorId : UnauthorizedAccess

And the verbatim spelling is not an edge case, it is what we always hand PowerShell in a release build. Using the real crate on the same runner:

tauri_utils::platform::current_exe() = "\\?\D:\a\...\probe.exe"  verbatim=true
script path install.rs sees          = "\\?\D:\a\...\install.ps1"

The chain is resolve(Resource) -> resource_dir() -> current_exe() -> starting_binary.rs, which calls canonicalize(). Rust documents that canonicalize returns extended-length syntax that "may be incompatible with other applications (if passed to the application on the command-line)". The dev branch builds from CARGO_MANIFEST_DIR instead, which is why this never showed up locally and only bit release builds.

For the record on where it came from: #7819's whole install.rs diff was Bypass -> RemoteSigned. Bypass never invokes the AuthorizationManager, so the same verbatim path was harmless before it.

What I changed

1. Match the UNC token case insensitively. Everything after \\?\ goes to the object manager unparsed, and that is case insensitive, so \\?\unc\server\share is a legal spelling. The old comparison was against the literal \\?\UNC\, so 7 of the 8 case spellings fell through to the drive branch, failed the : check, and were returned still verbatim, i.e. still broken.

2. Do not de-verbatimize past MAX_PATH. The verbatim form is the only one that addresses a path longer than 260 characters, so stripping the prefix there swapped an authorization error for a "path too long" one. Now those are left alone.

3. Resolve powershell.exe absolutely. This is the security-relevant one. Command::new with a bare name searches the directory of the running executable before the system directory, and installMode is currentUser, so that directory is user-writable. A powershell.exe dropped next to the Studio binary would have been picked up ahead of the real one. It now resolves under %SystemRoot%\System32\WindowsPowerShell\v1.0\, falling back to the old behaviour only if that file is absent.

Verification

  • cargo check and cargo clippy --all-targets --target x86_64-pc-windows-msvc clean, rustfmt clean.
  • Differential of the old logic against the new over a 364 case generated corpus: the only inputs whose behaviour changes are the lowercase UNC spellings and paths past MAX_PATH. All four original assertions still hold, the function is idempotent, and no non-verbatim input is modified by either version, which is the property that matters for not regressing anyone.
  • Added two tests: one pinning the pass-through set (\\?\C: with no separator, \\.\, GLOBALROOT, plain UNC, relative, over-long) and one asserting the interpreter resolves under the system directory.

One thing worth fixing separately

The cfg(windows) test added here cannot run in CI. The only cargo test job is studio-tauri-smoke.yml, which is runs-on: ubuntu-22.04, and cfg(windows) items are stripped before type-checking, so neither the function nor its test is even compiled by any check on this PR. That is how #7819 shipped this into two draft desktop bundles unnoticed. Worth adding a Windows leg, but it does not need to block this.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88abb327d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/src-tauri/src/install.rs Outdated

// Only the verbatim form addresses a path past MAX_PATH; stripping it there
// would trade an authorization error for a "path too long" one.
if normalized.len() > 260 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Keep verbatim paths at the MAX_PATH boundary

When the normalized script path is exactly 260 UTF-16 code units, this strips the \\?\ prefix even though legacy Win32 MAX_PATH leaves room for only 259 path characters plus the terminating NUL. In that boundary case Windows PowerShell 5.1 receives an ordinary path it cannot open, so installations under a just-long-enough per-user path fail with a path error instead of preserving the verbatim spelling; the guard should treat >= 260 as too long.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, fixed in f4560c5. MAX_PATH is 260 counting the terminating NUL, so the longest legacy path string is 259 units, and the guard now rejects 260. Test pins both sides of the boundary: a 259 unit normalized path still strips, 260 and 300 stay verbatim.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: f4560c5534

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen marked this pull request as ready for review August 5, 2026 15:26
@danielhanchen
danielhanchen merged commit 450e592 into unslothai:main Aug 5, 2026
46 checks passed
danielhanchen added a commit that referenced this pull request Aug 6, 2026
…#7969)

The windows-unit-tests leg added in #7943 pins powershell_script_path as a pure
function. That cannot see the regression that actually shipped: #7819's entire
install.rs diff was Bypass -> RemoteSigned, and dropping the
powershell_script_path call from spawn_script leaves every existing assertion
passing while first-run install is broken on every Windows bundle.

Lift the argument vector into powershell_launch_args so the call site itself is
testable, then run the real interpreter with those flags against a script
addressed the way Tauri addresses it (fs::canonicalize, which resource
resolution bottoms out in and which is documented to return extended-length
syntax). The test asserts it reproduced a verbatim path before using it, so it
cannot pass vacuously. A second test pins the flag set so a policy swap shows
up as a diff.

No behaviour change: the arguments spawn_script passes are byte for byte the
ones it passed before.
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.

2 participants