fix: canonicalize secret target array indexes

This commit is contained in:
Peter Steinberger
2026-05-28 12:02:21 -04:00
parent c9c53e3153
commit e67ff0c43e
2 changed files with 24 additions and 2 deletions

View File

@@ -23,6 +23,24 @@ describe("target registry pattern helpers", () => {
tokens,
),
).toBeNull();
expect(
matchPathTokens(
["agents", "list", "02", "memorySearch", "providers", "openai", "apiKey"],
tokens,
),
).toBeNull();
expect(
matchPathTokens(
["agents", "list", "+2", "memorySearch", "providers", "openai", "apiKey"],
tokens,
),
).toBeNull();
expect(
matchPathTokens(
["agents", "list", "4294967294", "memorySearch", "providers", "openai", "apiKey"],
tokens,
),
).toBeNull();
});
it("materializes sibling ref paths from wildcard and array captures", () => {
@@ -37,6 +55,9 @@ describe("target registry pattern helpers", () => {
"apiKeyRef",
]);
expect(materializePathTokens(refTokens, ["anthropic"])).toBeNull();
expect(materializePathTokens(refTokens, ["01", "anthropic"])).toBeNull();
expect(materializePathTokens(refTokens, ["+1", "anthropic"])).toBeNull();
expect(materializePathTokens(refTokens, ["4294967294", "anthropic"])).toBeNull();
});
it("matches two wildcard captures in five-segment header paths", () => {

View File

@@ -1,3 +1,4 @@
import { parseConfigPathArrayIndex } from "../shared/path-array-index.js";
import { isRecord, parseDotPath } from "./shared.js";
import type { SecretTargetRegistryEntry } from "./target-registry-types.js";
@@ -92,7 +93,7 @@ export function matchPathTokens(
return null;
}
const next = segments[index + 1];
if (!next || !/^\d+$/.test(next)) {
if (!next || parseConfigPathArrayIndex(next) === undefined) {
return null;
}
captures.push(next);
@@ -122,7 +123,7 @@ export function materializePathTokens(
continue;
}
const arrayIndex = captures[captureIndex];
if (!arrayIndex || !/^\d+$/.test(arrayIndex)) {
if (!arrayIndex || parseConfigPathArrayIndex(arrayIndex) === undefined) {
return null;
}
out.push(token.field, arrayIndex);