mxc-sdk: diagnostic.js runs a PATH-resolved `whoami` at import time, even with diagnostics off
Package: @microsoft/mxc-sdk 0.8.0, dist/diagnostic.js.
What happens
At module load, diagnostic.js computes PIPE_NAME by calling getDiagnosticPipeName(). On Windows this runs
execSync('whoami /user /fo csv /nh', …). It runs on every import, whether or not the diagnostic console is enabled.
execSync goes through the shell, so whoami is resolved from PATH.
Why it matters
- On machines where another
whoamicomes beforeSystem32inPATH, that program runs instead. Git for Windows'usr/binis a common case. It printswhoami: extra operand '/user'on the host process's stderr. In a full-screen terminal application that text lands on top of the UI. - Any executable named
whoamifound earlier inPATHruns at import time with the host's rights, even though the caller never enabled diagnostics.
Suggested fix (any of these)
- Compute the pipe name lazily, only when the diagnostic console is enabled.
- Run
%SystemRoot%\System32\whoami.exeby absolute path withexecFileSync(no shell). - Obtain the SID without spawning a process.
Repro
On Windows, put Git for Windows' usr\bin before System32 in PATH, then import the package, for example with
node --input-type=module -e "await import('@microsoft/mxc-sdk')". The whoami error appears on stderr.
Also seen with 0.9.0 and 1.0.0 on Windows 11 25H2 when the host process runs from a Git Bash session: the PATH-resolved whoami is MSYS's, which prints whoami: extra operand '/user' to stderr on every import (the run continues). Resolving %SystemRoot%\System32\whoami.exe explicitly, or using the token APIs instead, would avoid both the wrong binary and the PATH lookup.
Still present in 1.1.0 on Windows (dist/diagnostic.js:33, PIPE_NAME computed at module load, line 49); 1.1.0 skips it
off Windows. Two more points from embedding it:
execSyncgoes throughcmd.exe, which looks in the current directory beforePATH(unlessNoDefaultCurrentDirectoryInExePathis set). Measured: awhoami.cmdin the importing process's cwd ran at import. For an app whose cwd can be a folder a sandboxed workload writes to, that is code from inside the sandbox running outside it.getPlatformSupport()on Windows runsexecSync('dism /online …')(dist/v1/platform.js:108) the same way, so the same applies to its first call.
What we do meanwhile: process.chdir() to the app's own folder around the import() and around every synchronous SDK
call. execFileSync with %SystemRoot%\System32\whoami.exe / dism.exe (no shell) would remove the need.