Repository navigation
feat(secrets): add Bitwarden/Vaultwarden secret provider - #23096
ihsanmokhlisse wants to merge 7 commits into
Conversation
| async getSecret(name: string, _version?: string): Promise<string> { | ||
| const cacheKey = `bw:${name}`; | ||
| const cached = localCache.get(cacheKey); | ||
| if (cached && cached.expiresAt > Date.now()) { | ||
| return cached.value; |
There was a problem hiding this comment.
TOTP codes cached beyond validity window
TOTP codes rotate every ~30 seconds, but this caches them for cacheTtlMs which defaults to 300 seconds (5 minutes). After the first 30 seconds, the cached TOTP will be expired/invalid, causing silent authentication failures when the cached value is returned.
TOTP values should either not be cached, or cached for a much shorter duration (e.g., 25 seconds max):
| async getSecret(name: string, _version?: string): Promise<string> { | |
| const cacheKey = `bw:${name}`; | |
| const cached = localCache.get(cacheKey); | |
| if (cached && cached.expiresAt > Date.now()) { | |
| return cached.value; | |
| if (field === "totp") { | |
| const totp = await this.runBw(["get", "totp", itemQuery]); | |
| // TOTP codes rotate every ~30 seconds; do not cache beyond that window | |
| const totpTtl = Math.min(this.cacheTtlMs, 25_000); | |
| localCache.set(cacheKey, { value: totp, expiresAt: Date.now() + totpTtl }); | |
| return totp; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/bitwarden-secret-provider.ts
Line: 221-225
Comment:
**TOTP codes cached beyond validity window**
TOTP codes rotate every ~30 seconds, but this caches them for `cacheTtlMs` which defaults to 300 seconds (5 minutes). After the first 30 seconds, the cached TOTP will be expired/invalid, causing silent authentication failures when the cached value is returned.
TOTP values should either not be cached, or cached for a much shorter duration (e.g., 25 seconds max):
```suggestion
if (field === "totp") {
const totp = await this.runBw(["get", "totp", itemQuery]);
// TOTP codes rotate every ~30 seconds; do not cache beyond that window
const totpTtl = Math.min(this.cacheTtlMs, 25_000);
localCache.set(cacheKey, { value: totp, expiresAt: Date.now() + totpTtl });
return totp;
}
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Already handled — the TOTP branch already caps to 25s via Math.min(this.cacheTtlMs, 25_000).
| organizationId: null, | ||
| folderId: null, | ||
| type: 1, |
There was a problem hiding this comment.
notes field duplicated into custom fields on create
When field === "notes", the condition field !== "password" && field !== "username" is true, so a custom field named "notes" is added to fields[] in addition to correctly setting notes: value. This creates a Bitwarden item with the value stored in two places — the notes property and a spurious custom field.
Note that updateItemField (line 275) handles "notes" correctly via a dedicated case branch without touching fields. The same exclusion should apply here:
| organizationId: null, | |
| folderId: null, | |
| type: 1, | |
| fields: | |
| field !== "password" && field !== "username" && field !== "notes" ? [{ name: field, value, type: 0 }] : [], | |
| notes: field === "notes" ? value : null, |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/bitwarden-secret-provider.ts
Line: 261-263
Comment:
**`notes` field duplicated into custom fields on create**
When `field === "notes"`, the condition `field !== "password" && field !== "username"` is `true`, so a custom field named `"notes"` is added to `fields[]` in addition to correctly setting `notes: value`. This creates a Bitwarden item with the value stored in two places — the `notes` property and a spurious custom field.
Note that `updateItemField` (line 275) handles `"notes"` correctly via a dedicated `case` branch without touching `fields`. The same exclusion should apply here:
```suggestion
fields:
field !== "password" && field !== "username" && field !== "notes" ? [{ name: field, value, type: 0 }] : [],
notes: field === "notes" ? value : null,
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Already handled — the exclusion list already includes notes: field !== "password" && field !== "username" && field !== "notes".
| const value = this.extractField(item, field); | ||
|
|
||
| localCache.set(cacheKey, { value, expiresAt: Date.now() + this.cacheTtlMs }); | ||
| return value; | ||
| } | ||
|
|
||
| async setSecret(name: string, value: string): Promise<void> { |
There was a problem hiding this comment.
Bare catch swallows all CLI errors, not just "not found"
This catch block treats every error (vault locked, CLI missing, network failures) as "item doesn't exist" and falls through to the create branch. If the vault is locked, this will attempt to create a new item instead of surfacing the lock error, producing a confusing secondary error message.
Consider narrowing the catch to only treat "Not found" errors as the item-not-existing signal:
| const value = this.extractField(item, field); | |
| localCache.set(cacheKey, { value, expiresAt: Date.now() + this.cacheTtlMs }); | |
| return value; | |
| } | |
| async setSecret(name: string, value: string): Promise<void> { | |
| let existingItem: BitwardenItem | null = null; | |
| try { | |
| const raw = await this.runBw(["get", "item", itemQuery]); | |
| existingItem = JSON.parse(raw); | |
| } catch (err: unknown) { | |
| const msg = err instanceof Error ? err.message : String(err); | |
| if (!msg.includes("not found") && !msg.includes("Not found")) { | |
| throw err; | |
| } | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/bitwarden-secret-provider.ts
Line: 238-244
Comment:
**Bare `catch` swallows all CLI errors, not just "not found"**
This catch block treats every error (vault locked, CLI missing, network failures) as "item doesn't exist" and falls through to the create branch. If the vault is locked, this will attempt to create a new item instead of surfacing the lock error, producing a confusing secondary error message.
Consider narrowing the catch to only treat "Not found" errors as the item-not-existing signal:
```suggestion
let existingItem: BitwardenItem | null = null;
try {
const raw = await this.runBw(["get", "item", itemQuery]);
existingItem = JSON.parse(raw);
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);
if (!msg.includes("not found") && !msg.includes("Not found")) {
throw err;
}
}
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Already handled — the catch block already rethrows non-"not found" errors: if (!msg.includes("not found") && !msg.includes("Not found")) { throw err; }.
|
Addressed all three Greptile review comments in commit 1385301: 1. TOTP cache (line 233): Cache is now capped at 25 seconds via 2. Notes duplication (line 275): Added 3. Bare catch in setSecret (line 253): Catch now only swallows "not found" errors; all other errors (locked vault, CLI missing, network) are re-thrown. Added test: "re-throws non-not-found errors instead of swallowing them". Tests: 37/37 passing. |
|
I really like the idea of adding a Vaultwarden. Let's push that into the code base! |
|
@jzakirov Thanks for the support! Right now OpenClaw stores all API keys and tokens as plain-text JSON on disk ( Bitwarden/Vaultwarden is used by 55M+ people and is fully self-hostable — which makes it a natural fit for OpenClaw's self-hosted audience. The idea here is to let users store their credentials where they already manage their secrets, rather than leaving them in plain config files. This is one piece of a bigger gap: OpenClaw currently has no native secret provider integration at all. PR #16663 introduces the Together these close a real security gap and give users a choice of backends depending on their setup — cloud vault, OS keychain, password manager, or encrypted file. |
whynice724-cell
left a comment
There was a problem hiding this comment.
Code Review ✅
PR #23096 - Bitwarden/Vaultwarden Secret Provider
Summary
Adding Bitwarden integration for secret management - a highly requested feature (55M+ users).
Analysis
- Problem: OpenClaw lacked Bitwarden integration for users who store API keys in their password vault
- Solution: New BitwardenSecretProvider implementing SecretProvider interface
- Scope: Two new files only - no changes to existing code ✅
- Testing: 34 unit tests included ✅
Security Considerations
- Uses standard Bitwarden CLI (
bw) for integration - Follows existing SecretProvider interface pattern
- Syntax: ${bw:item-name/field-name} is intuitive
Verdict
Approve - Clean implementation, well-tested, no breaking changes. Good addition for self-hosted users who prefer Bitwarden.
1385301 to
ce5df77
Compare
|
Rebased on latest main (no conflicts). All 3 Greptile review comments were verified as already addressed in the current code — TOTP cache cap, notes exclusion, and narrowed catch block are all in place. Ready for human review. |
ce5df77 to
e8c6cbf
Compare
|
Rebased on latest main — no conflicts. Branch is up to date and ready for review. |
|
Thanks for the contribution. With #26155 now merged in main, can you please rebase this branch on latest main and align it to the merged secrets baseline? This one looks like a good candidate to stay focused and land as a smaller follow-up after rebase. |
e8c6cbf to
a400ff8
Compare
|
Rebased on latest main and fully aligned with the merged secrets baseline (#26155). What changed and why: The original PR added a class-based This rewrite aligns Bitwarden with that exact pattern:
Files:
|
|
@vincentkoc Rebased on latest main and aligned with the merged secrets baseline from #26155 as requested. The class-based Ready for review when you get a chance. |
95ac9eb to
8dd511b
Compare
|
Rebased on latest main — no conflicts. Branch is up to date. Actively maintained. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Closing due to inactivity. |
Summary
BitwardenSecretProviderimplementing theSecretProviderinterface from PR feat: GCP Secret Manager integration for external secrets management #16663, with 34 unit tests. Supports${bw:item-name/field-name}syntax.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
New secret reference syntax for Bitwarden:
Field extraction supports:
password(default),username,notes,uri,totp, and custom fields by name.Security Impact (required)
NoYes— adds a new secrets provider that reads from Bitwarden CLINo— delegates tobwCLI which handles all network communicationYes— spawnsbwCLI viaexecFile(no shell)NobwCLI is invoked viaexecFile(notexec) — no shell injection possible--nointeractionand--rawflags prevent interactive prompts and ensure clean output parsingBitwardenCliErrorwith actionable hints, never exposing raw vault dataRepro + Verification
Environment
bw) installed and logged inSteps
brew install bitwarden-cliornpm install -g @bitwarden/clibw loginthenexport BW_SESSION=$(bw unlock --raw)bw get template item | jq '.name="test-key" | .login.password="sk-test-123"' | bw encode | bw create item${bw:test-key/password}as an API key referenceExpected
sk-test-123Actual
Evidence
Human Verification (required)
buildSecretProviders().Compatibility / Migration
Yes— entirely opt-in, no existing behavior changesYes— newsecrets.providers.bwconfig section (only used if configured)NoFailure Recovery (if this breaks)
bwfromsecrets.providersconfig, or revert to plain-text API keysopenclaw.json(removesecrets.providers.bwsection)BitwardenCliErrorwith actionable hint messages for every failure modeRisks and Mitigations
SecretProviderinterface may changebwCLI output format may change across versionsAI-Assisted
Made with Cursor
Greptile Summary
Adds a Bitwarden/Vaultwarden secret provider (
BitwardenSecretProvider) that implements theSecretProviderinterface from PR #16663, enabling${bw:item-name/field-name}secret references. The provider usesexecFile(no shell) for CLI invocation, isolates credentials via child process env overrides, and includes comprehensive error mapping with actionable hints.setSecretnotes duplication: When creating a new item withfield === "notes", the value is stored in both thenotesproperty and as a custom field named"notes"due to an incomplete exclusion in the ternary condition on thefieldsarray.setSecreterror swallowing: The barecatchblock when checking for existing items treats all errors (vault locked, CLI missing, network errors) as "item not found," masking the real error and attempting an item creation that will fail with a confusing secondary error.execFileoverexec, env isolation without mutatingprocess.env,--nointeractionand--rawflags.Confidence Score: 3/5
src/config/bitwarden-secret-provider.ts— specifically thegetSecretTOTP caching path (line 221-225) and thesetSecretcreate-new-item branch (lines 238-269).Last reviewed commit: 35578de
(2/5) Greptile learns from your feedback when you react with thumbs up/down!