Skip to content

Commit 02362e1

Browse files
Ignore inherited provider and Bot registry entries
1 parent 67091ed commit 02362e1

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ refused in every mode, including `allow_all`, and the browser's WebRTC traffic n
3939
filter instead of around it. A computer run without an API server can set
4040
`EGRESS_POLICY_REQUIRED=0` to keep the old behaviour.
4141

42+
### Provider and Bot lookups ignore inherited object properties
43+
44+
Unknown names such as `constructor` and `__proto__` no longer return an inherited
45+
JavaScript object as a provider or Bot entry. Unknown providers return no spec, and
46+
missing Bots raise the existing startup error. Configured providers and Bots are unchanged.
47+
4248
### `start.sh` names the port to change on macOS
4349

4450
When the API server's or the app's port was held by another process, `start.sh` was meant to say

‎shared/model-providers.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,18 @@ describe("what a Bot runs from the spec file", () => {
319319
);
320320
});
321321
});
322+
323+
describe("registry lookups ignore inherited object properties", () => {
324+
test("prototype names are not providers", () => {
325+
for (const name of ["constructor", "__proto__", "toString", "valueOf"]) {
326+
expect(providerSpec(name)).toBeUndefined();
327+
expect(keyVariableFor(name)).toBeUndefined();
328+
expect(baseUrlVariableFor(name)).toBeUndefined();
329+
}
330+
});
331+
test("prototype names are not Bot entries", () => {
332+
for (const name of ["constructor", "__proto__", "toString", "valueOf"]) {
333+
expect(() => botSettings(name, {})).toThrow(`bots has no ${name} entry`);
334+
}
335+
});
336+
});

‎shared/model-providers.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ export function providerSpec(
166166
provider: string | undefined,
167167
): ProviderSpec | undefined {
168168
const normalized = provider?.trim().toLowerCase() || "openai";
169-
return MODEL_PROVIDERS[normalized as ModelProviderId];
169+
return Object.hasOwn(MODEL_PROVIDERS, normalized)
170+
? MODEL_PROVIDERS[normalized as ModelProviderId]
171+
: undefined;
170172
}
171173

172174
/** The environment variable this provider's key arrives in, or nothing for a provider unknown. */
@@ -248,7 +250,9 @@ export function botSettings(
248250
env: Readonly<Record<string, string | undefined>> = process.env,
249251
pinnedProvider?: string,
250252
): BotSettings {
251-
const entry = BOT_ENTRIES[botId];
253+
const entry = Object.hasOwn(BOT_ENTRIES, botId)
254+
? BOT_ENTRIES[botId]
255+
: undefined;
252256
if (!entry) {
253257
fail(
254258
`bots has no ${botId} entry. Add one before this Bot reads the spec file.`,

0 commit comments

Comments
 (0)