Repository navigation
feat(gateway): add missing OpenAI-compatible endpoints (models and embeddings) - #53992
Conversation
🔒 Aisle Security AnalysisWe found 5 potential security issue(s) in this PR:
Vulnerabilities1. 🟠 Allowlist bypass for OpenAI/OpenResponses
|
| Property | Value |
|---|---|
| Severity | High |
| CWE | CWE-863 |
| Location | src/gateway/http-utils.ts:86-105 |
Description
resolveOpenAiCompatModelOverride() allows OpenAI-compat callers to set an arbitrary model string. The allowlist enforcement is skipped when the parsed provider is considered a "CLI provider" (isCliProvider(...)).
This creates a privilege escalation relative to the configured model allowlist:
- Input: HTTP request body
model(OpenAI/v1/chat/completionsand OpenResponses endpoints) - AuthZ check:
buildAllowedModelSet(...)is consulted only if the provider is not a CLI provider - Sink: the raw
modeloverride flows intoagentCommandFromIngresswithallowModelOverride: trueand can select therunCliAgent(...)execution path for CLI providers
If any configured CLI backend runs local binaries (common for backends like claude-cli, codex-cli, or configured cliBackends), then an authenticated remote caller can switch the agent execution to that local backend regardless of the model allowlist, potentially triggering unintended local execution and access to local resources under the gateway's OS account.
Vulnerable logic:
if (
!isCliProvider(parsed.provider, cfg) &&
!allowed.allowAny &&
!allowed.allowedKeys.has(normalized)
) {
return { errorMessage: `Model '${normalized}' is not allowed...` };
}
return { modelOverride: raw };Recommendation
Treat CLI providers the same as other providers for allowlist purposes, or introduce an explicit configuration gate for allowing CLI provider overrides via HTTP.
Minimum safer change: enforce the allowlist regardless of provider type:
const normalized = modelKey(parsed.provider, parsed.model);
if (!allowed.allowAny && !allowed.allowedKeys.has(normalized)) {
return { errorMessage: `Model '${normalized}' is not allowed for agent '${params.agentId}'.` };
}If you intentionally want to allow CLI provider use via HTTP, add a dedicated config flag (e.g. gateway.allowCliModelOverride) defaulting to false, and require it before accepting any CLI provider override. Also consider setting allowModelOverride: false by default for network-facing endpoints and only enabling it for specific trusted deployments.
2. 🟡 Client-controlled x-openclaw-message-channel allows spoofing channel context in OpenResponses HTTP endpoint
| Property | Value |
|---|---|
| Severity | Medium |
| CWE | CWE-290 |
| Location | src/gateway/openresponses-http.ts:626-633 |
Description
POST /v1/responses (OpenResponses-compatible) now enables x-openclaw-message-channel via useMessageChannelHeader: true, allowing external callers to set messageChannel for the run context.
Why this is security-relevant:
- Input: attacker-controlled HTTP header
x-openclaw-message-channel - Propagation:
resolveGatewayRequestContext()normalizes the header but does not enforce membership in a safe/allowed set; unknown values are accepted. - Sink / effect: resulting
messageChannelis passed into the agent run (runResponsesAgentCommand→ agent command ingress), and is used broadly as channel context (e.g., tool/plugin context viaagentChannel, and potentially channel-aware prompts/policies).
If any prompt templates, tool policies, plugin tool availability, moderation rules, or other enforcement decisions vary by messageChannel, a caller can spoof a more privileged/less restricted channel and bypass intended controls.
Vulnerable code (changed behavior):
const resolved = resolveGatewayRequestContext({
req,
model,
user,
sessionPrefix: "openresponses",
defaultMessageChannel: "webchat",
useMessageChannelHeader: true,
});And the header is accepted as:
normalizeMessageChannel(getHeader(req, "x-openclaw-message-channel")) ?? defaultRecommendation
Treat x-openclaw-message-channel as a trusted ingress hint, not a public client parameter.
Recommended fixes (pick one):
- Disable the header for OpenResponses (restore previous behavior):
const resolved = resolveGatewayRequestContext({
...,
useMessageChannelHeader: false,
});- Allowlist known-safe channels for this HTTP surface (reject or ignore unknowns):
import { resolveGatewayMessageChannel } from "../utils/message-channel.js";
const headerChannel = resolveGatewayMessageChannel(getHeader(req, "x-openclaw-message-channel"));
const messageChannel = headerChannel ?? "webchat";- Gate the header behind stronger authentication / internal-only usage, e.g. only honor it for trusted-proxy mode or an internal network allowlist.
Also consider documenting clearly which HTTP endpoints honor this header and what security implications it has.
3. 🔵 Unhandled exception in models route URL parsing due to unsanitized Host header
| Property | Value |
|---|---|
| Severity | Low |
| CWE | CWE-20 |
| Location | src/gateway/models-http.ts:72-74 |
Description
resolveRequestPath() constructs a WHATWG URL using the request's Host header as the base. Because req.headers.host is user-controlled, a malformed value can cause new URL() to throw a TypeError.
- Input:
req.headers.hostfrom the HTTP request - Fault point:
new URL(req.url,http://${req.headers.host}) - Impact: Triggers the top-level request handler's catch and returns 500 Internal Server Error for this route. An unauthenticated client can repeatedly send malformed
Hostheaders to cause per-request failures (request-level DoS) on/v1/models*handling.
Vulnerable code:
function resolveRequestPath(req: IncomingMessage): string {
return new URL(req.url ?? "/", `http://${req.headers.host || "localhost"}`).pathname;
}Recommendation
Avoid using a user-controlled Host header as the base URL, or defensively catch URL parsing errors.
Safer options:
- Use a constant base (preferred, since only
.pathnameis needed):
function resolveRequestPath(req: IncomingMessage): string {
try {
return new URL(req.url ?? "/", "http://localhost").pathname;
} catch {
return "/";
}
}- If you must respect host, validate/normalize it and catch exceptions:
function resolveRequestPath(req: IncomingMessage): string {
const host = typeof req.headers.host === "string" ? req.headers.host : "localhost";
try {
return new URL(req.url ?? "/", `http://${host}`).pathname;
} catch {
return new URL(req.url ?? "/", "http://localhost").pathname;
}
}This prevents malformed Host values from causing an exception-based failure path.
4. 🔵 Embedding model allowlist bypass on /v1/embeddings (agent-scoped policy not enforced)
| Property | Value |
|---|---|
| Severity | Low |
| CWE | CWE-284 |
| Location | src/gateway/embeddings-http.ts:142-208 |
Description
The OpenAI-compatible embeddings endpoint allows a caller to select any embedding model name under the agent’s configured embedding provider, without checking the agent’s configured/allowed model set.
- Input: untrusted
modelfrom the HTTP request body (payload.model) - Policy gap: only the provider is constrained via
resolveEmbeddingsTarget(...); the model id is not validated against an allowlist nor forced to the configuredmemorySearch.model. - Sink:
createEmbeddingProvider({ provider: target.provider, model: target.model, ... })will attempt to use the requested model.
Impact:
- If operators assume
agents.defaults.models(or similar model allowlists) constrain all OpenAI-compatible endpoints, a caller can request non-approved embedding models (same provider), potentially causing unexpected billing, using non-approved models, or mixing vector spaces.
Vulnerable code:
const requestModel = typeof payload.model === "string" ? payload.model.trim() : "";
...
const target = resolveEmbeddingsTarget({ requestModel, configuredProvider });
...
const options: EmbeddingProviderOptions = {
provider: target.provider,
model: target.model,
...
};Recommendation
Enforce an agent-scoped embedding model policy for /v1/embeddings.
Options (pick one, but be explicit):
- Fail-closed to the configured embedding model (recommended for memory-search consistency): ignore request
modelexcept possibly for provider prefix validation.
// Resolve provider from request only to allow/deny explicit prefixes.
const target = resolveEmbeddingsTarget({ requestModel, configuredProvider });
if ("errorMessage" in target) return ...;
// Force model to agent config.
const configuredModel = memorySearch?.model ?? "text-embedding-3-small";
const options: EmbeddingProviderOptions = {
...,
provider: target.provider,
model: configuredModel,
};- Allow overrides but enforce an allowlist: reuse the same allowlist machinery used by chat/responses (e.g.,
buildAllowedModelSet(...)/ catalog filtering) or add a dedicatedagents.*.memorySearch.allowedModelslist and validatetarget.model(plus provider) against it.
Either way, ensure the decision is agent-scoped (based on x-openclaw-agent-id) and returns 400 with an invalid_request_error when disallowed.
5. 🔵 Unintended enablement of /v1/models and /v1/embeddings when enabling only one API family
| Property | Value |
|---|---|
| Severity | Low |
| CWE | CWE-276 |
| Location | src/gateway/server-http.ts:777-840 |
Description
/v1/models and /v1/embeddings are gated by a derived flag openAiCompatEnabled that becomes true when either openAiChatCompletionsEnabled or openResponsesEnabled is enabled.
This can expand the exposed HTTP attack surface in deployments where an operator intended to enable only /v1/responses (OpenResponses) but not OpenAI-compat endpoints like model enumeration and embeddings.
- Trigger: enabling
openResponsesEnabled(or chat completions) - Effect: additional endpoints are served (
/v1/models,/v1/embeddings) without an independent enablement decision - Impact: increased surface area; potential information disclosure (model catalog details) and unexpected availability of embeddings functionality to any client that already has gateway auth
Vulnerable logic:
const openAiCompatEnabled = openAiChatCompletionsEnabled || openResponsesEnabled;
...
openAiCompatEnabled ? handleOpenAiModelsHttpRequest(...) : false
openAiCompatEnabled ? handleOpenAiEmbeddingsHttpRequest(...) : falseRecommendation
Introduce independent feature flags (and config entries) for /v1/models and /v1/embeddings, defaulting to disabled, and only enable them when explicitly configured.
Example approach:
const modelsEnabled = opts.openAiModelsEnabled === true;
const embeddingsEnabled = opts.openAiEmbeddingsEnabled === true;
...
run: () => (modelsEnabled ? handleOpenAiModelsHttpRequest(req, res, commonOpts) : false),
run: () => (embeddingsEnabled ? handleOpenAiEmbeddingsHttpRequest(req, res, commonOpts) : false),If the intent is "OpenAI compatibility mode" across both OpenResponses + ChatCompletions, make that explicit as a single config flag (e.g. gateway.http.openAiCompat.enabled) and document that it also enables /v1/models and /v1/embeddings.
Analyzed PR: #53992 at commit dac07d0
Last updated on: 2026-03-24T22:51:48Z
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2cce8e5d19
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Greptile SummaryThis PR extends the gateway's OpenAI-compatible surface with Key points from the review:
Confidence Score: 4/5
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 93001b17f8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 506bbd2323
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dac07d0585
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const cfg = loadConfig(); | ||
| const catalog = await loadGatewayModelCatalog(); | ||
| const agentId = resolveAgentIdForRequest({ req, model: undefined }); | ||
| const { allowedCatalog } = buildAllowedModelSet({ | ||
| cfg, |
There was a problem hiding this comment.
Use agent default provider when filtering model list
loadAllowedCatalog passes DEFAULT_PROVIDER into buildAllowedModelSet, so bare allowlist entries are interpreted as Anthropic even when the selected agent’s runtime default provider is different. In configs like agents.defaults.model.primary = "openai/gpt-5.4" with a bare allowlist key ("gpt-5.4"), /v1/models can emit the wrong synthetic ID (anthropic/gpt-5.4) and hide the actually allowed model. This breaks OpenAI-compatible picker round-trips for non-Anthropic defaults.
Useful? React with 👍 / 👎.
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
…beddings) (openclaw#53992) * feat(gateway): add OpenAI-compatible models and embeddings * docs(gateway): clarify model list and agent routing * Update index.md * fix(gateway): harden embeddings HTTP provider selection * fix(gateway): validate compat model overrides * fix(gateway): harden embeddings and response continuity * fix(gateway): restore compat model id handling
Summary
/v1/chat/completionsand/v1/responses, but many clients also expect/v1/modelsand many RAG setups expect/v1/embeddings.GET /v1/models,GET /v1/models/{id}, andPOST /v1/embeddings; forward explicit model overrides through chat/responses; supportx-openclaw-message-channelon responses; document the full compatibility surface.openapichannel plugin, no separate config toggles for models/embeddings, no audio/images/realtime compatibility work.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
N/A
git blame, prior PR, issue, or refactor if known):Regression Test Plan (if applicable)
N/A
User-visible / Behavior Changes
GET /v1/models,GET /v1/models/{id}, andPOST /v1/embeddingswhenever the existing compatibility surface is enabled.modelvalues now flow through as real model overrides for/v1/chat/completionsand/v1/responses, unless they areopenclaw:<agent>oragent:<agent>routing aliases./v1/responsesnow honorsx-openclaw-message-channel, matching chat completions.models + embeddings + chat + responsesas the highest-leverage compatibility set.Security Impact (required)
Yes/No) YesYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation: adds new authenticated gateway API endpoints on the existing bearer-authenticated compatibility surface; endpoints reuse existing gateway auth helpers and agent/model filtering.Repro + Verification
Environment
Steps
GET /v1/modelsorPOST /v1/embeddingswith the gateway bearer token./v1/chat/completionsor/v1/responseswith a concrete provider/model id and verify the override is forwarded.Expected
x-openclaw-message-channel.Actual
Evidence
Attach at least one:
Human Verification (required)
pnpm tsgo;pnpm test -- src/gateway/openai-http.test.ts src/gateway/openresponses-http.test.ts src/gateway/models-http.test.ts src/gateway/embeddings-http.test.ts.provider/modelids, agent-scoped model filtering, base64 embedding encoding, responses message-channel header support, model alias vs model override handling.pnpm test; live client integration against Open WebUI/LobeChat/LibreChat.Review Conversations