Skip to content

[POC] Login with Bitwarden consent and Agent Access handoff - #24837

Draft
JaredSnider-Bitwarden wants to merge 2 commits into
mainfrom
oauth
Draft

JaredSnider-Bitwarden wants to merge 2 commits into
mainfrom
oauth

Conversation

@JaredSnider-Bitwarden

Copy link
Copy Markdown
Contributor

🎟️ Tracking

No ticket. This draft PR shows the oauth proof-of-concept branch so that the team can review it together. Do not merge.

Companion server PR: bitwarden/server#8944

📔 Objective

Add the web vault side of "Login with Bitwarden" for registered partner agents. The consent step also delivers an Agent Access pre-shared key to the agent.

  1. Web vault: add the partner consent page, the static completion connector that forwards the browser to the agent, and a list of connected apps with revoke.
  2. Agent connections: add the AgentConnection models, state, API service, sync and push handling, and a pre-shared key generator (currently a stub), with unit tests for the agent connection service.
  3. Key rotation: re-encrypt agent connections when the user key rotates.
  4. Wiring: add the consent route and the connected apps link in the web vault, register the new services in the Angular, browser and CLI service containers, and add the feature flag, the notification types and the English strings.

📸 Screenshots

None.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: REQUEST CHANGES

Reviewed the "Login with Bitwarden" proof of concept. It adds the web consent page, the static oauth-complete connector that hands the PSK to the agent's loopback address, a connected-apps page with revoke, the AgentConnection models, state, API, sync and push handling, key rotation, and service registration in the browser, CLI and Angular containers. The stub PSK generator calls KeyGenerationService.createKeyWithPurpose, which is marked as a deprecated HAZMAT API. Per repo guidance, @bitwarden/team-key-management-dev should be aware before this moves past the POC stage.

Code Review Details
  • ⚠️ : If consent fails after the connection is created, the server-side connection is orphaned, and each retry creates a duplicate
    • apps/web/src/app/tools/agent-connection/oauth-authorize.component.ts:116
  • 🎨 : isLoopback does not check the scheme, so a javascript://localhost/... redirect would pass and run on the vault origin
    • apps/web/src/connectors/oauth-complete.ts:63
  • ❓ : package-lock.json changed without any manifest change (only optional/peer/dev flag churn). Was this intentional?
    • package-lock.json

Comment on lines +116 to +119
await this.agentConnectionApiService.post(new AgentConnectionRequest(connection));

// Record consent via the API (mints a single-use token). No PSK is sent.
const { token } = await this.brokerApiService.postConsent(this.returnUrl);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ IMPORTANT: If postConsent (or anything after it) fails, the agent connection already created on the server is left behind, and each retry creates another one.

Details and fix

agentConnectionApiService.post(...) persists the wrapped PSK server-side before consent is recorded. The catch block only clears sessionStorage, so when postConsent or buildConsentCallbackUrl throws:

  • a connection for this partner stays on the account even though no consent was granted
  • that PSK was never delivered to the agent, so the connection is unusable
  • clicking Approve again creates a second connection with a new PSK, and the duplicates then show up under "Connected apps" after the next sync

Either record consent before creating the connection, or keep the returned id and roll it back in the catch:

let createdId: string | undefined;
try {
  // ...
  const created = await this.agentConnectionApiService.post(new AgentConnectionRequest(connection));
  createdId = created.id;
  const { token } = await this.brokerApiService.postConsent(this.returnUrl);
  // ...
} catch {
  if (createdId != null) {
    await this.agentConnectionApiService.delete(createdId).catch(() => {});
  }
  // existing error handling
}

code-review

Comment on lines +63 to +67
return (
parsed.hostname === "127.0.0.1" ||
parsed.hostname === "localhost" ||
parsed.hostname === "[::1]"
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 SUGGESTED: isLoopback checks only the hostname, not the scheme, so a javascript://localhost/... URI would pass and run as script on the web vault origin.

Details and fix

For non-special schemes the WHATWG URL parser still fills in hostname from the //authority part, so new URL("javascript://localhost/%0a...").hostname === "localhost". Assigning that to window.location.href runs the payload in the vault origin. That origin can read sessionStorage, which is where the PSK is held.

The server is supposed to validate agentRedirectUri against the partner allow-list, but this function is documented as the client-side guard against leaking the secret. Pinning the scheme closes this whole class of attack with a single extra check:

return (
  parsed.protocol === "http:" &&
  (parsed.hostname === "127.0.0.1" ||
    parsed.hostname === "localhost" ||
    parsed.hostname === "[::1]")
);

code-review

const target =
`${agentRedirect}${separator}code=${encodeURIComponent(code)}&state=${encodeURIComponent(state)}` +
`#psk=${encodeURIComponent(psk)}`;
window.location.href = target;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Cross Site Scripting (XSS) via window.location.href - medium severity
Using window.location.href or similar redirection methods with unvalidated user input can lead to cross-site scripting (XSS). If an attacker controls part of the URL, they may inject malicious scripts that execute in the victim’s browser, potentially allowing session hijacking, data theft, or other unauthorized actions. Proper validation and encoding of user-controlled values are required before using them in redirects or client-side navigation.

Show fix

Remediation: Avoid using window.location.href or similar redirection methods with unvalidated user input. Only allow redirects to trusted, predefined destinations or validate the input against a strict allowlist. When possible, use fixed URLs or server-side redirection logic, and ensure any user-controlled values are properly validated and encoded before use.

Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

* resumes the authorize request — issuing the code to the registered `redirect_uri` (the completion
* page). The plaintext PSK never leaves the client and is never sent to the Bitwarden server.
*/
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OAuthAuthorizeComponent change-detection migration is marked FIXME; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment marks the component's change-detection migration as unfinished. A tracker link alone does not specify the remaining work or criteria for completion.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

@@ -0,0 +1,21 @@
// FIXME: Update this file to be type safe and remove this and next line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnectionStateProvider abstraction is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment explicitly defers making the state provider abstraction type safe and provides no completion plan.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

@@ -0,0 +1,49 @@
// FIXME: Update this file to be type safe and remove this and next line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnectionView model is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment explicitly defers making the view model type safe and provides no completion plan.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

@@ -0,0 +1,35 @@
// FIXME: Update this file to be type safe and remove this and next line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnectionStateProvider implementation is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment explicitly defers making the state provider implementation type safe and provides no completion plan.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

@@ -0,0 +1,32 @@
// FIXME: Update this file to be type safe and remove this and next line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnectionData model is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment explicitly defers making the data model type safe and provides no completion plan.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

@@ -0,0 +1,21 @@
// FIXME: Update this file to be type safe and remove this and next line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnectionRequest model is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment explicitly defers making the request model type safe and provides no completion plan.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

* Revoking deletes the connection server-side (which pushes to the user's other clients) and from
* local state; the bot's short-lived token then expires on its own (no refresh).
*/
// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnectionsComponent change-detection migration is marked FIXME; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment marks the component's change-detection migration as unfinished. A tracker link alone does not specify the remaining work or criteria for completion.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

@@ -0,0 +1,77 @@
// FIXME: Update this file to be type safe and remove this and next line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnection model is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment explicitly defers making the domain model type safe and provides no completion plan.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

@@ -0,0 +1,134 @@
// FIXME: Update this file to be type safe and remove this and next line

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AgentConnectionService is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.

Details

✨ AI Reasoning
​The comment explicitly defers making the service type safe and provides no completion plan.

🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.

Reply on this comment to give feedback or ignore the issue.
More info

@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.75989% with 270 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.14%. Comparing base (b96dc7b) to head (bd1f867).
⚠️ Report is 29 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ools/agent-connection/oauth-authorize.component.ts 0.00% 61 Missing ⚠️
apps/web/src/connectors/oauth-complete.ts 0.00% 37 Missing ⚠️
...nt-connection/services/agent-connection.service.ts 62.50% 14 Missing and 7 partials ⚠️
...ls/agent-connection/agent-connections.component.ts 0.00% 20 Missing ⚠️
...nt-connection/services/oauth-broker-api.service.ts 0.00% 19 Missing ⚠️
...-connection/services/oauth-broker-state.service.ts 0.00% 13 Missing ⚠️
...agent-connection/models/domain/agent-connection.ts 61.76% 1 Missing and 12 partials ⚠️
...nt-connection/models/view/agent-connection.view.ts 60.86% 8 Missing and 1 partial ⚠️
...onnection/services/agent-connection-api.service.ts 0.00% 9 Missing ⚠️
libs/angular/src/services/jslib-services.module.ts 0.00% 8 Missing ⚠️
... and 18 more
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #24837    +/-   ##
========================================
  Coverage   63.14%   63.14%            
========================================
  Files        4983     5019    +36     
  Lines      162261   162947   +686     
  Branches    26163    26275   +112     
========================================
+ Hits       102452   102891   +439     
- Misses      52844    53049   +205     
- Partials     6965     7007    +42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JaredSnider-Bitwarden JaredSnider-Bitwarden left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Claude (AI) did this review and wrote these comments. I have not reviewed the findings myself yet.

The findings that integration tests prove are on the server PR, bitwarden/server#8944. The two comments here cover the completion connector and come from code reading; they are not tested.

Client-side items and open questions

Inline

  1. F5, vault side: the connector forwards the PSK to any process on the loopback port.
  2. Redirect model: the connector drops iss and does not forward error.

Not tested

  1. Key rotation re-encryption of agent connections, and the push types that sync connections to clients.
  2. The PSK generator is a stub that produces a random 256-bit value.

Open questions

  1. What does Agent Access pairing let a PSK holder do, and for how long?
  2. Must every client pair with the agent? Sync sends the PSK to every client. Pairing only the device that approved would reduce exposure.

Comment on lines +45 to +50
if (agentRedirect != null && isLoopback(agentRedirect)) {
const separator = agentRedirect.includes("?") ? "&" : "?";
const target =
`${agentRedirect}${separator}code=${encodeURIComponent(code)}&state=${encodeURIComponent(state)}` +
`#psk=${encodeURIComponent(psk)}`;
window.location.href = target;

@JaredSnider-Bitwarden JaredSnider-Bitwarden Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Found by Claude (AI). An integration test proves the server-side behavior. This connector code comes from code reading and is not tested.

F5, vault side · Medium (pending threat model). The connector forwards the plaintext PSK to the process that listens on the loopback address. The server side of F5 is on bitwarden/server#8944.

Details
  1. Identity accepts any loopback port for the agent redirect, so this forward cannot tell the real agent from another local process.
  2. The forward does not use the code exchange, so the partner's client secret does not protect the PSK.
  3. isLoopback accepts localhost, but the server allow-list rejects it. The two checks should agree (this side not tested).

Comment on lines +20 to +25
const error = params.get("error");

if (error != null) {
showMessage(`Authorization failed: ${error}`);
return;
}

@JaredSnider-Bitwarden JaredSnider-Bitwarden Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Found by Claude (AI) from code reading. Not tested.

Redirect model. The connector forwards only code and state to the agent. It drops iss, and on error it shows a message but sends nothing to the agent.

Details
  1. Discovery advertises iss support, so an RFC 9207 client MUST reject a forwarded response that has no iss (§2.4).
  2. On error, the agent gets no response.

Suggested fix: forward iss, and forward error and error_description to the agent redirect.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants