Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/clients/config-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,15 @@ function proxyAdmissionHeaders(config: OcxConfig | undefined, envRef: string): R
return shouldInjectApiAuthHeader(config) ? { "x-opencodex-api-key": envRef } : undefined;
}

/** Do not let provider-controlled catalog text become an environment lookup. */
function containsEnvInterpolation(value: string): boolean {
return value.includes("${");
}

function buildHermesClientConfig(ctx: ExportContext): HermesGeneratedConfig {
const models = normalizeExportModels(ctx.models).map(model => model.namespaced);
const models = normalizeExportModels(ctx.models)
.filter(model => !containsEnvInterpolation(model.namespaced))
.map(model => model.namespaced);
const headers = proxyAdmissionHeaders(ctx.config, HERMES_API_KEY_ENV_REF);
return {
providers: {
Expand All @@ -758,13 +765,15 @@ function buildHermesClientConfig(ctx: ExportContext): HermesGeneratedConfig {
}

function buildOpenclawClientConfig(ctx: ExportContext): OpenclawGeneratedConfig {
const models: OpenclawModelEntry[] = normalizeExportModels(ctx.models).map(model => {
const models: OpenclawModelEntry[] = normalizeExportModels(ctx.models).flatMap(model => {
const name = exportModelLabel(model);
if (containsEnvInterpolation(model.namespaced) || containsEnvInterpolation(name)) return [];
const context = authoritativeContextWindow(model.contextWindow);
return {
return [{
id: model.namespaced,
name: exportModelLabel(model),
name,
...(context !== undefined ? { contextWindow: context } : {}),
};
}];
});
const headers = proxyAdmissionHeaders(ctx.config, OPENCLAW_API_KEY_ENV_REF);
return {
Expand Down
19 changes: 19 additions & 0 deletions tests/client-config-new-clients.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ describe("openclaw", () => {
});
});

describe("interpolation-capable clients", () => {
test("omit provider-controlled model text that could expand an environment variable", () => {
const models: ExportModel[] = [
...MODELS,
{ namespaced: "evil/${SENSITIVE_ENV}", provider: "evil", id: "${SENSITIVE_ENV}" },
{ namespaced: "safe/id", provider: "safe", id: "id", displayName: "${SENSITIVE_ENV}" },
];
const maliciousContext = { ...ctx(), models };

const hermes = buildClientConfig("hermes", maliciousContext) as HermesGeneratedConfig;
expect(hermes.providers[OPENCODE_PROVIDER_ID]!.models).not.toContain("evil/${SENSITIVE_ENV}");

const openclaw = buildClientConfig("openclaw", maliciousContext) as OpenclawGeneratedConfig;
expect(openclaw.models.providers[OPENCODE_PROVIDER_ID]!.models.map(model => model.id)).toEqual(
MODELS.map(model => model.namespaced).sort(),
);
});
});

describe("kimi", () => {
test("omits a model with no authoritative context window entirely", () => {
const doc = buildClientConfig("kimi", ctx()) as KimiGeneratedConfig;
Expand Down
Loading