Skip to content

Commit 9448fae

Browse files
fix account lookup invalid key fallback
1 parent b32716f commit 9448fae

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/routing/account-lookup.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ describe("resolveNormalizedAccountEntry", () => {
9494
),
9595
expected: undefined,
9696
},
97+
{
98+
name: "does not resolve invalid raw keys through the default account fallback",
99+
accounts: {
100+
"constructor ": { id: "blocked" },
101+
} as Record<string, { id: string }>,
102+
resolve: (accounts: Record<string, { id: string }>) =>
103+
resolveNormalizedAccountEntry(accounts, "default", normalizeRoutingAccountId),
104+
expected: undefined,
105+
},
97106
{
98107
name: "ignores prototype-chain values",
99108
resolve: () => undefined,

src/routing/account-lookup.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Account lookup helpers resolve route accounts from normalized account ids.
22
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
33
import { isBlockedObjectKey } from "../infra/prototype-keys.js";
4+
import { normalizeOptionalAccountId } from "./account-id.js";
45

56
// Case-insensitive account lookup for config maps that may preserve user
67
// casing. Exact keys win so callers can still distinguish intentional entries.
@@ -39,8 +40,12 @@ export function resolveNormalizedAccountEntry<T>(
3940
if (isBlockedObjectKey(key)) {
4041
return false;
4142
}
42-
const normalizedKey = normalizeAccountId(key);
43-
return !isBlockedObjectKey(normalizedKey) && normalizedKey === normalized;
43+
const candidate = normalizeAccountId(key);
44+
return (
45+
Boolean(normalizeOptionalAccountId(key)) &&
46+
!isBlockedObjectKey(candidate) &&
47+
candidate === normalized
48+
);
4449
});
4550
return matchKey ? accounts[matchKey] : undefined;
4651
}

0 commit comments

Comments
 (0)