




















@@ -14,11 +14,14 @@ import {
1414analyzeShellCommand,
1515isWindowsPlatform,
1616matchAllowlist,
17+resolveExecutableTrustPath,
1718resolveExecutionTargetCandidatePath,
1819resolveExecutionTargetResolution,
20+resolveExecutionTargetTrustPath,
1921resolveCommandResolutionFromArgv,
2022resolvePolicyTargetCandidatePath,
2123resolvePolicyTargetResolution,
24+resolvePolicyTargetTrustPath,
2225splitCommandChain,
2326splitCommandChainWithOperators,
2427type ExecCommandAnalysis,
@@ -96,13 +99,14 @@ export function isSafeBinUsage(params: {
9699if (!matchesSafeBin) {
97100return false;
98101}
99-if (!resolution?.resolvedPath) {
102+const trustPath = resolveExecutableTrustPath(resolution);
103+if (!trustPath) {
100104return false;
101105}
102106const isTrustedPath = params.isTrustedSafeBinPathFn ?? isTrustedSafeBinPath;
103107if (
104108!isTrustedPath({
105-resolvedPath: resolution.resolvedPath,
109+resolvedPath: trustPath,
106110trustedDirs: params.trustedSafeBinDirs,
107111})
108112) {
@@ -212,15 +216,16 @@ function isSkillAutoAllowedSegment(params: {
212216}
213217const resolution = params.segment.resolution;
214218const execution = resolveExecutionTargetResolution(resolution);
215-if (!execution?.resolvedPath) {
219+const trustPath = resolveExecutionTargetTrustPath(resolution);
220+if (!execution?.resolvedPath || !trustPath) {
216221return false;
217222}
218223const rawExecutable = execution.rawExecutable?.trim() ?? "";
219224if (!rawExecutable || isPathScopedExecutableToken(rawExecutable)) {
220225return false;
221226}
222227const executableName = normalizeSkillBinName(execution.executableName);
223-const resolvedPath = normalizeSkillBinResolvedPath(execution.resolvedPath);
228+const resolvedPath = normalizeSkillBinResolvedPath(trustPath);
224229if (!executableName || !resolvedPath) {
225230return false;
226231}
@@ -439,6 +444,7 @@ function executableResolutionsReferToSameTarget(
439444return (
440445left.rawExecutable === right.rawExecutable &&
441446left.resolvedPath === right.resolvedPath &&
447+left.resolvedRealPath === right.resolvedRealPath &&
442448left.executableName === right.executableName
443449);
444450}
@@ -534,9 +540,10 @@ function resolveSegmentAllowlistMatch(params: {
534540params.segment.resolution,
535541params.context.cwd,
536542);
543+const trustPath = resolvePolicyTargetTrustPath(params.segment.resolution, params.context.cwd);
537544const candidateResolution =
538545candidatePath && executableResolution
539- ? { ...executableResolution, resolvedPath: candidatePath }
546+ ? { ...executableResolution, resolvedPath: candidatePath, resolvedRealPath: trustPath }
540547 : executableResolution;
541548const inlineCommand = extractBindableShellWrapperInlineCommand(allowlistSegment.argv);
542549const powerShellFileScriptArgv = resolvePowerShellFileScriptArgv({
@@ -573,6 +580,7 @@ function resolveSegmentAllowlistMatch(params: {
573580{
574581rawExecutable: shellPositionalArgvCandidatePath,
575582resolvedPath: shellPositionalArgvCandidatePath,
583+resolvedRealPath: resolveCandidateTrustPath(shellPositionalArgvCandidatePath),
576584executableName: path.basename(shellPositionalArgvCandidatePath),
577585},
578586undefined,
@@ -602,6 +610,7 @@ function resolveSegmentAllowlistMatch(params: {
602610{
603611rawExecutable: shellScriptCandidatePath,
604612resolvedPath: shellScriptCandidatePath,
613+resolvedRealPath: resolveCandidateTrustPath(shellScriptCandidatePath),
605614executableName: path.basename(shellScriptCandidatePath),
606615},
607616shellScriptArgv,
@@ -1096,6 +1105,17 @@ function addAllowAlwaysPattern(
10961105}
10971106}
109811071108+function resolveCandidateTrustPath(candidatePath: string | undefined): string | undefined {
1109+if (!candidatePath) {
1110+return undefined;
1111+}
1112+return resolveExecutableTrustPath({
1113+rawExecutable: candidatePath,
1114+resolvedPath: candidatePath,
1115+executableName: path.basename(candidatePath),
1116+});
1117+}
1118+10991119function collectAllowAlwaysPatterns(params: {
11001120segment: ExecCommandSegment;
11011121cwd?: string;
@@ -1123,7 +1143,7 @@ function collectAllowAlwaysPatterns(params: {
11231143resolution: resolveCommandResolutionFromArgv(trustPlan.argv, params.cwd, params.env),
11241144};
112511451126-const candidatePath = resolveExecutionTargetCandidatePath(segment.resolution, params.cwd);
1146+const candidatePath = resolveExecutionTargetTrustPath(segment.resolution, params.cwd);
11271147if (!candidatePath) {
11281148return;
11291149}
@@ -1152,7 +1172,10 @@ function collectAllowAlwaysPatterns(params: {
11521172})
11531173 : undefined;
11541174if (positionalArgvPath) {
1155-addAllowAlwaysPattern(params.out, positionalArgvPath);
1175+addAllowAlwaysPattern(
1176+params.out,
1177+resolveCandidateTrustPath(positionalArgvPath) ?? positionalArgvPath,
1178+);
11561179return;
11571180}
11581181if (!inlineCommand) {
@@ -1163,13 +1186,14 @@ function collectAllowAlwaysPatterns(params: {
11631186cwd: params.cwd,
11641187});
11651188if (scriptPath) {
1189+const scriptTrustPath = resolveCandidateTrustPath(scriptPath) ?? scriptPath;
11661190const argPattern = buildScriptArgPatternFromArgv(
11671191powerShellFileScriptArgv ?? params.segment.argv,
11681192scriptPath,
11691193params.cwd,
11701194params.platform,
11711195);
1172-addAllowAlwaysPattern(params.out, scriptPath, argPattern);
1196+addAllowAlwaysPattern(params.out, scriptTrustPath, argPattern);
11731197}
11741198return;
11751199}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。