Skip to content

Commit 0972f2f

Browse files
committed
Use fixed executables for tenant checks
Satisfy the secure process execution validator by replacing the generic tenant CLI runner with fixed literal execFileSync call sites for pac, az, and cmd.exe. Copilot-Session: a9952624-0a25-4d6e-ae67-537c962a8a60
1 parent 1b5bd69 commit 0972f2f

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

plugins/power-pages/scripts/lib/cli-tenant-alignment.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,37 @@ function tenantIdFromToken(token) {
3535
return normalizeGuid(payload && payload.tid);
3636
}
3737

38-
function runCli(command, args, { execFile = execFileSync, platform = process.platform } = {}) {
38+
function runPacAuthWho({ execFile = execFileSync, platform = process.platform } = {}) {
3939
if (platform === 'win32') {
40-
// On Windows, `az` is commonly an `az.cmd` shim, while PAC installs as
41-
// `pac.exe`. Node's execFile can miss shell-resolved shims even when the same
42-
// command works interactively. Route through cmd.exe with fixed,
43-
// code-controlled arguments so the helper matches what users run manually.
44-
const executable = command === 'pac' ? 'pac.exe' : `${command}.cmd`;
45-
return execFile('cmd.exe', ['/d', '/s', '/c', executable, ...args], { encoding: 'utf8', timeout: 15000 });
40+
// PAC installs as pac.exe on Windows. Route through cmd.exe so PATH lookup
41+
// matches the user's terminal while keeping the executable literal fixed for
42+
// the secure-process validator.
43+
return execFile('cmd.exe', ['/d', '/s', '/c', 'pac.exe', 'auth', 'who'], { encoding: 'utf8', timeout: 15000 });
4644
}
47-
return execFile(command, args, { encoding: 'utf8', timeout: 15000 });
45+
return execFile('pac', ['auth', 'who'], { encoding: 'utf8', timeout: 15000 });
46+
}
47+
48+
function runAzAccountShowTenant({ execFile = execFileSync, platform = process.platform } = {}) {
49+
if (platform === 'win32') {
50+
// Azure CLI installs an az.cmd shim on Windows. Route through cmd.exe so PATH
51+
// lookup matches the user's terminal while keeping the executable literal
52+
// fixed for the secure-process validator.
53+
return execFile('cmd.exe', ['/d', '/s', '/c', 'az.cmd', 'account', 'show', '--query', 'tenantId', '-o', 'tsv'], { encoding: 'utf8', timeout: 15000 });
54+
}
55+
return execFile('az', ['account', 'show', '--query', 'tenantId', '-o', 'tsv'], { encoding: 'utf8', timeout: 15000 });
4856
}
4957

5058
function getPacTenantId(execFile = execFileSync, platform = process.platform) {
5159
try {
52-
return parsePacTenantId(runCli('pac', ['auth', 'who'], { execFile, platform }));
60+
return parsePacTenantId(runPacAuthWho({ execFile, platform }));
5361
} catch {
5462
return null;
5563
}
5664
}
5765

5866
function getAzAccountTenantId(execFile = execFileSync, platform = process.platform) {
5967
try {
60-
return normalizeGuid(runCli('az', ['account', 'show', '--query', 'tenantId', '-o', 'tsv'], { execFile, platform }));
68+
return normalizeGuid(runAzAccountShowTenant({ execFile, platform }));
6169
} catch {
6270
return null;
6371
}
@@ -106,7 +114,8 @@ function validateCliTenantAlignment({ envUrl, token, pacTenantId, azTenantId, to
106114
module.exports = {
107115
decodeJwtPayload,
108116
parsePacTenantId,
109-
runCli,
117+
runAzAccountShowTenant,
118+
runPacAuthWho,
110119
tenantIdFromToken,
111120
validateCliTenantAlignment,
112121
};

0 commit comments

Comments
 (0)