Skip to content

Commit a382af4

Browse files
committed
addressing ci
1 parent 76b8975 commit a382af4

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/infra/exec-approvals-allowlist.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ function matchExecutableAllowlistForSegment(params: {
399399
inlineCommand: string | null;
400400
isShellWrapperInvocation: boolean;
401401
isPositionalCarrierInvocation: boolean;
402+
allowlistTargetIsExecutionTarget: boolean;
402403
}): ExecAllowlistEntry | null {
403404
if (params.isPositionalCarrierInvocation) {
404405
return null;
@@ -413,14 +414,29 @@ function matchExecutableAllowlistForSegment(params: {
413414
typeof match?.argPattern === "string" && match.argPattern.trim().length > 0;
414415
const isBareWildcardMatch = match?.pattern?.trim() === "*" && !hasBoundArgPattern;
415416
const requiresBoundArgPattern =
416-
params.inlineCommand !== null ||
417-
(params.isShellWrapperInvocation && params.effectiveArgv.length > 1);
417+
params.allowlistTargetIsExecutionTarget &&
418+
(params.inlineCommand !== null ||
419+
(params.isShellWrapperInvocation && params.effectiveArgv.length > 1));
418420
if (requiresBoundArgPattern && !hasBoundArgPattern && !isBareWildcardMatch) {
419421
return null;
420422
}
421423
return match;
422424
}
423425

426+
function executableResolutionsReferToSameTarget(
427+
left: ExecutableResolution | null,
428+
right: ExecutableResolution | null,
429+
): boolean {
430+
if (!left || !right) {
431+
return false;
432+
}
433+
return (
434+
left.rawExecutable === right.rawExecutable &&
435+
left.resolvedPath === right.resolvedPath &&
436+
left.executableName === right.executableName
437+
);
438+
}
439+
424440
function resolveShellWrapperScriptArgv(params: {
425441
shellScriptCandidatePath: string;
426442
effectiveArgv: string[];
@@ -507,6 +523,7 @@ function resolveSegmentAllowlistMatch(params: {
507523
? params.segment
508524
: { ...params.segment, argv: effectiveArgv };
509525
const executableResolution = resolvePolicyTargetResolution(params.segment.resolution);
526+
const executionResolution = resolveExecutionTargetResolution(params.segment.resolution);
510527
const candidatePath = resolvePolicyTargetCandidatePath(
511528
params.segment.resolution,
512529
params.context.cwd,
@@ -531,6 +548,10 @@ function resolveSegmentAllowlistMatch(params: {
531548
inlineCommand,
532549
isShellWrapperInvocation,
533550
isPositionalCarrierInvocation,
551+
allowlistTargetIsExecutionTarget: executableResolutionsReferToSameTarget(
552+
executableResolution,
553+
executionResolution,
554+
),
534555
});
535556
const shellPositionalArgvCandidatePath =
536557
inlineCommand !== null

0 commit comments

Comments
 (0)