Repository navigation
fix: accept BRAVE_SEARCH_API_KEY for Brave web search - #19186
Plutarch01 wants to merge 2 commits into
Conversation
| const fromOpenWebUIEnv = normalizeSecretInput(process.env.BRAVE_SEARCH_API_KEY); | ||
| return fromConfig || fromEnv || fromOpenWebUIEnv || undefined; |
There was a problem hiding this comment.
Audit check not updated for new alias
The hasWebSearchKey function in src/security/audit-extra.sync.ts:258-267 checks for env.BRAVE_API_KEY but does not check for env.BRAVE_SEARCH_API_KEY. This means that if a user sets only BRAVE_SEARCH_API_KEY, the web search tool will work at runtime (because of this change), but the security audit will incorrectly report the key as missing. Consider adding env.BRAVE_SEARCH_API_KEY to the hasWebSearchKey check as well:
function hasWebSearchKey(cfg: OpenClawConfig, env: NodeJS.ProcessEnv): boolean {
const search = cfg.tools?.web?.search;
return Boolean(
search?.apiKey ||
search?.perplexity?.apiKey ||
env.BRAVE_API_KEY ||
env.BRAVE_SEARCH_API_KEY ||
env.PERPLEXITY_API_KEY ||
env.OPENROUTER_API_KEY,
);
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/tools/web-search.ts
Line: 188:189
Comment:
**Audit check not updated for new alias**
The `hasWebSearchKey` function in `src/security/audit-extra.sync.ts:258-267` checks for `env.BRAVE_API_KEY` but does not check for `env.BRAVE_SEARCH_API_KEY`. This means that if a user sets only `BRAVE_SEARCH_API_KEY`, the web search tool will work at runtime (because of this change), but the security audit will incorrectly report the key as missing. Consider adding `env.BRAVE_SEARCH_API_KEY` to the `hasWebSearchKey` check as well:
```
function hasWebSearchKey(cfg: OpenClawConfig, env: NodeJS.ProcessEnv): boolean {
const search = cfg.tools?.web?.search;
return Boolean(
search?.apiKey ||
search?.perplexity?.apiKey ||
env.BRAVE_API_KEY ||
env.BRAVE_SEARCH_API_KEY ||
env.PERPLEXITY_API_KEY ||
env.OPENROUTER_API_KEY,
);
}
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Addressed in 4e7f6dc on this PR branch. hasWebSearchKey now includes BRAVE_SEARCH_API_KEY so the audit check matches runtime key resolution.
|
Good catch — fixed in 4e7f6dc. I updated in to include , so audit behavior now matches runtime key resolution. |
|
Update: addressed in commit 4e7f6dc. hasWebSearchKey in src/security/audit-extra.sync.ts now checks BRAVE_SEARCH_API_KEY in addition to BRAVE_API_KEY, so audit and runtime behavior are aligned. |
Summary
BRAVE_SEARCH_API_KEYas an env-var alias when resolving Brave web search API credentialsapiKey, thenBRAVE_API_KEY, thenBRAVE_SEARCH_API_KEYTesting
src/agents/tools/web-search.tsNotes
mainGreptile Summary
This PR adds
BRAVE_SEARCH_API_KEYas a fallback environment variable for Brave web search API credentials inresolveSearchApiKey(), preserving the existing precedence: explicit configapiKey>BRAVE_API_KEY>BRAVE_SEARCH_API_KEY. The error message is updated to mention both supported env vars. The change is minimal and well-scoped.resolveSearchApiKey()correctly chains the new env var as a third fallbackhasWebSearchKey()insrc/security/audit-extra.sync.tsalso needs to check forBRAVE_SEARCH_API_KEY, otherwise the audit will incorrectly report the key as missing when only the new alias is setBRAVE_API_KEYin user-facing guidance text (onboarding, configure wizard, config schema help, type comments) — not bugs, but worth a follow-up to mention both env vars for consistencyConfidence Score: 4/5
hasWebSearchKey()inaudit-extra.sync.tswas not updated, which could cause the security audit to misreport key availability when onlyBRAVE_SEARCH_API_KEYis set.src/security/audit-extra.sync.ts— thehasWebSearchKeyfunction needs to also check forBRAVE_SEARCH_API_KEYto match the new runtime behavior.Last reviewed commit: dc5161c
(4/5) You can add custom instructions or style guidelines for the agent here!