Repository navigation
fix(agents): preserve blank local custom-provider API keys after onboarding - #45631
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🔵 Synthetic no-auth for loopback custom providers enables config-driven localhost SSRF/data exfiltration
DescriptionThe new synthetic auth behavior for custom providers can make OpenClaw send model prompts/transcripts to a loopback HTTP service even when the user did not configure any credentials, which meaningfully weakens the prior “missing API key blocks requests” safeguard. Why this is a security issue (when configuration is not fully trusted):
This becomes materially exploitable if an attacker can influence configuration (examples grounded in repo):
Vulnerable code (new behavior): if (providerConfig.baseUrl && isLocalBaseUrl(providerConfig.baseUrl)) {
return {
apiKey: CUSTOM_LOCAL_AUTH_MARKER,
source: `models.providers.${params.provider} (synthetic local key)`,
mode: "api-key",
};
}and later: const headers = {
...model.headers,
Authorization: null,
} as unknown as Record<string, string>;Impact:
Precondition:
RecommendationRequire explicit opt-in before sending any model traffic to loopback endpoints without credentials. Suggested approaches (choose one):
Also consider hardening config trust:
Example gating (conceptual): if (
providerConfig.baseUrl &&
isLocalBaseUrl(providerConfig.baseUrl) &&
providerConfig.allowLocalUnauthenticated === true
) {
return { apiKey: CUSTOM_LOCAL_AUTH_MARKER, source: ..., mode: "api-key" };
}This preserves UX for intentional local LLM setups while preventing silent enablement from attacker-influenced configuration. Analyzed PR: #45631 at commit Last updated on: 2026-03-14T03:37:34Z |
Greptile SummaryThis PR fixes loopback OpenAI-compatible custom providers so that a blank API key left during onboarding does not cause auth failures or send a bogus Key changes:
Issues found:
Confidence Score: 3/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: CHANGELOG.md
Line: 60
Comment:
**Unresolved git conflict marker in CHANGELOG**
Line 60 contains a bare `<<<<<<< HEAD` conflict marker that was never resolved. This means the merge conflict between the `macOS/voice wake` entry and the new `Agents/custom providers` entry was left in a broken state. As-is, this line would appear verbatim in the published changelog and would corrupt any tooling that parses the file.
The `<<<<<<< HEAD` should be removed, and only one of the two orderings of the two entries should be kept (both entries appear to be valid changes that belong in the changelog).
```suggestion
- macOS/voice wake: stop crashing wake-word command extraction when speech segment ranges come from a different transcript instance.
- Agents/custom providers: preserve blank API keys for loopback OpenAI-compatible custom providers by clearing the synthetic Authorization header at runtime, while keeping explicit apiKey and oauth/token config from silently downgrading into fake bearer auth. (#43118) Thanks @xinhuagu.
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/model-auth.ts
Line: 126-141
Comment:
**Dead-code IPv6 host comparisons (non-bracketed forms never match)**
When `new URL(...)` parses an IPv6 address, Node.js serializes the hostname **with** the surrounding brackets per the WHATWG URL spec. For example:
```
new URL("http://[::1]:8080/v1").hostname // → "[::1]"
new URL("http://[::ffff:127.0.0.1]:8080/v1").hostname // → "[::ffff:127.0.0.1]"
```
This means the three non-bracketed variants — `"::1"`, `"::ffff:7f00:1"`, and `"::ffff:127.0.0.1"` — can never be matched through this code path. The bracketed counterparts (`"[::1]"`, `"[::ffff:7f00:1]"`, `"[::ffff:127.0.0.1]"`) are sufficient and already present.
Consider removing the dead entries to avoid false confidence that both forms are covered:
```suggestion
try {
const host = new URL(baseUrl).hostname.toLowerCase();
return (
host === "localhost" ||
host === "127.0.0.1" ||
host === "0.0.0.0" ||
host === "[::1]" ||
host === "[::ffff:7f00:1]" ||
host === "[::ffff:127.0.0.1]"
);
} catch {
return false;
}
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/model-auth.ts
Line: 515-518
Comment:
**Unsafe `null` header cast may silently fail to clear `Authorization`**
The object `{ ...model.headers, Authorization: null }` is cast `as unknown as Record<string, string>` to satisfy TypeScript. At runtime, whether `null` actually removes the `Authorization` header depends entirely on how `@mariozechner/pi-ai` processes the `headers` map before passing it to the Fetch API. The Node.js `Headers` constructor rejects `null` values (`TypeError: Header value can't be null or undefined`), so if `pi-ai` does a naïve `new Headers(model.headers)`, the call will throw rather than clear the header.
The test intercepts `globalThis.fetch` *after* the SDK's own header-building step, so it validates the end-to-end outcome when the SDK handles `null` correctly, but it doesn't prevent a future SDK update from breaking this silently.
A safer and more explicit approach would be to delete the key rather than set it to `null`:
```suggestion
const { Authorization: _drop, ...restHeaders } = model.headers ?? {};
const headers = restHeaders as Record<string, string>;
```
This avoids the cast entirely and is unambiguous regardless of how the downstream library handles the headers object.
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: ab8629e |
…t base URLs Custom providers with local base URLs (127.0.0.1, localhost, ::1, etc.) no longer fail with 'No API key found' when the user leaves the API key blank during onboarding. The auth resolver now synthesizes a local auth marker for these providers, matching the existing behavior for Ollama. Fixes #42890
…127.0.0.1 coverage Address review feedback from ademczuk and Aisle: - Remove .local (mDNS/Bonjour) from isLocalBaseUrl — these resolve to LAN machines, not necessarily localhost (CWE-287) - Add ::ffff:127.0.0.1 (IPv4-mapped IPv6 loopback) support - Add test for ::ffff:127.0.0.1 path
1c8fdc5 to
57393e1
Compare
|
Review: ✅ LGTM Thorough fix for custom providers with local loopback URLs and no API key. Key things done right:
CHANGELOG entry included. Well-structured, backwards compatible. |
|
Landed in 01674c575e757e10f82cfefad4d3c74b61dd02bc from 57393e1d98d121888cab545e63b1eb0d67087501. Thanks @xinhuagu. |
Summary
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Original contributor: @xinhuagu.
This PR is a clean maintainer replacement for #43118 after that contributor branch was auto-closed as dirty during maintainer prep.
User-visible / Behavior Changes
apiKeyconfig still behaves like an explicit credential requirement.auth: token/auth: oauthconfig is no longer silently downgraded into synthetic api-key auth.Bearer custom-local.Security Impact (required)
Yes/No) NoYes/No) YesYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
openai-completionsprovider with loopbackbaseUrlmodels.providers.<id>.baseUrl=http://127.0.0.1:11434/v1, blankapiKeySteps
baseUrland no API key.Expected
Actual
Evidence
Human Verification (required)
What you personally verified (not just CI), and how:
pnpm exec vitest run src/agents/model-auth.test.ts->24 passedpnpm build-> passedpnpm checkcurrently fails on existingmaintyping debt unrelated to this PR (src/cli/daemon-cli/status.test.ts,src/commands/onboard-non-interactive.gateway.test.ts,src/commands/onboard-non-interactive/local.ts,src/infra/outbound/deliver.lifecycle.test.ts,src/infra/outbound/deliver.test-helpers.ts,src/infra/outbound/deliver.test.ts). The latestmainCI run (23077863921) fails on the same set.Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
apiKey/authmode for the custom provider.src/agents/model-auth.tssrc/agents/model-auth.test.tssrc/agents/pi-embedded-runner/run.tssrc/agents/pi-embedded-runner/compact.tsBearer custom-localheaders on loopback requestsRisks and Mitigations