Merge remote-tracking branch 'giteahttps/codex/fix-claude-tool-casing-allowlist' into main
This commit is contained in:
@@ -489,6 +489,38 @@ function toToolNameCandidates(toolName: string): string[] {
|
||||
return dedupeStrings(candidates);
|
||||
}
|
||||
|
||||
function buildCaseInsensitiveToolLookup(tools: readonly string[]): Map<string, string> {
|
||||
const lookup = new Map<string, string>();
|
||||
for (const tool of tools) {
|
||||
const normalized = tool.trim().toLowerCase();
|
||||
if (!normalized || lookup.has(normalized)) {
|
||||
continue;
|
||||
}
|
||||
lookup.set(normalized, tool);
|
||||
}
|
||||
return lookup;
|
||||
}
|
||||
|
||||
function resolveAllowedToolMatch(input: {
|
||||
candidates: readonly string[];
|
||||
allowset: ReadonlySet<string>;
|
||||
caseInsensitiveLookup: ReadonlyMap<string, string>;
|
||||
}): string | undefined {
|
||||
const direct = input.candidates.find((candidate) => input.allowset.has(candidate));
|
||||
if (direct) {
|
||||
return direct;
|
||||
}
|
||||
|
||||
for (const candidate of input.candidates) {
|
||||
const match = input.caseInsensitiveLookup.get(candidate.toLowerCase());
|
||||
if (match) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function defaultEventPayloadForStatus(status: ActorResultStatus): DomainEventPayload {
|
||||
if (status === "success") {
|
||||
return {
|
||||
@@ -1299,6 +1331,7 @@ export class PipelineExecutor {
|
||||
attempt: number;
|
||||
}): ActorToolPermissionHandler {
|
||||
const allowset = new Set(input.allowedTools);
|
||||
const caseInsensitiveAllowLookup = buildCaseInsensitiveToolLookup(input.allowedTools);
|
||||
const rulesEngine = this.securityContext?.rulesEngine;
|
||||
const toolPolicy = toAllowedToolPolicy(input.allowedTools);
|
||||
const toolAuditContext = {
|
||||
@@ -1319,7 +1352,11 @@ export class PipelineExecutor {
|
||||
}
|
||||
|
||||
const candidates = toToolNameCandidates(toolName);
|
||||
const allowMatch = candidates.find((candidate) => allowset.has(candidate));
|
||||
const allowMatch = resolveAllowedToolMatch({
|
||||
candidates,
|
||||
allowset,
|
||||
caseInsensitiveLookup: caseInsensitiveAllowLookup,
|
||||
});
|
||||
if (!allowMatch) {
|
||||
rulesEngine?.assertToolInvocationAllowed({
|
||||
tool: candidates[0] ?? toolName,
|
||||
|
||||
Reference in New Issue
Block a user