Skip to content

fix for copilot token#2491

Merged
amikofalvy merged 3 commits intomainfrom
fix/copilot-token
Mar 3, 2026
Merged

fix for copilot token#2491
amikofalvy merged 3 commits intomainfrom
fix/copilot-token

Conversation

@amikofalvy
Copy link
Copy Markdown
Collaborator

No description provided.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agents-docs Ready Ready Preview, Comment Mar 3, 2026 6:33am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
agents-api Ignored Ignored Preview Mar 3, 2026 6:33am
agents-manage-ui Ignored Ignored Preview Mar 3, 2026 6:33am

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 3, 2026

🦋 Changeset detected

Latest commit: a2f83e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@inkeep/agents-manage-ui Patch
@inkeep/agents-api Patch
@inkeep/agents-cli Patch
@inkeep/agents-core Patch
@inkeep/agents-email Patch
@inkeep/agents-mcp Patch
@inkeep/agents-sdk Patch
@inkeep/agents-work-apps Patch
@inkeep/ai-sdk-provider Patch
@inkeep/create-agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@amikofalvy amikofalvy marked this pull request as ready for review March 3, 2026 06:33
@amikofalvy amikofalvy merged commit e8f1549 into main Mar 3, 2026
10 checks passed
@amikofalvy amikofalvy deleted the fix/copilot-token branch March 3, 2026 06:33
@pullfrog
Copy link
Copy Markdown
Contributor

pullfrog Bot commented Mar 3, 2026

Switches copilot token authentication from a server-side API key (INKEEP_COPILOT_API_KEY) to the user's session cookies, so the manage UI copilot chat authenticates as the logged-in user instead of a shared service credential.

  • agents-manage-ui/src/lib/actions/copilot-token.ts — Removes INKEEP_COPILOT_API_KEY usage and its validation check; reads session cookies via cookies() before the fetch (moved from post-response to pre-request); forwards them as x-forwarded-cookie header instead of Authorization: Bearer; adds an early return if no session cookies are present
  • .changeset/solar-rose-elk.md — Patch changeset for @inkeep/agents-manage-ui

Pullfrog  | View workflow run | Using Claude Code | Triggered by Pullfrogpullfrog.com𝕏

Copy link
Copy Markdown
Contributor

@pullfrog pullfrog Bot left a comment

Choose a reason for hiding this comment

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

The auth approach switch — from a static API key to session-cookie-based auth via x-forwarded-cookie — is correct and consistent with the established pattern in manageAuth.ts/sessionAuth.ts. One security issue: unlike api-config.ts, this forwards all cookies unfiltered rather than scoping to better-auth cookies only.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow runpullfrog.com𝕏

try {
const cookieStore = await cookies();
const allCookies = cookieStore.getAll();
const cookieHeader = allCookies.map((c) => `${c.name}=${c.value}`).join('; ');
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.

Security: Forward only auth cookies, not all cookies. The established pattern in api-config.ts (lines 46, 55) filters to only better-auth cookies before forwarding — e.g. allCookies.filter((c) => c.name.includes('better-auth')). This forwards every cookie (analytics, preferences, third-party trackers, etc.) to the API and then back to the client via the response. Filter to auth cookies only:

Suggested change
const cookieHeader = allCookies.map((c) => `${c.name}=${c.value}`).join('; ');
const cookieHeader = allCookies.filter((c) => c.name.includes('better-auth')).map((c) => `${c.name}=${c.value}`).join('; ');

Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

PR Review Summary

(0) Total Issues | Risk: Low

This PR changes the copilot token authentication mechanism from a static API key approach (INKEEP_COPILOT_API_KEY with Bearer header) to session-based authentication via the x-forwarded-cookie header pattern already established throughout the codebase.

Key Observations

Authentication pattern alignment — The x-forwarded-cookie header is already used in sessionAuth.ts, manageAuth.ts, and A2A handlers. This PR correctly adopts the same pattern.

Security improvement — Session-based auth is more secure than static API keys:

  • Sessions are tied to specific users with time limits
  • Sessions can be revoked at logout
  • Static API keys have broader exposure and longer lifespans

Correct middleware flow — The manageBearerOrSessionAuth middleware falls back to sessionAuth() when no Bearer header is present, which reads x-forwarded-cookie and validates the session. This flow is correct.

Proper error handling — The empty cookie check (if (!cookieHeader)) correctly detects missing sessions since getAll().map().join() on an empty array produces an empty string.

Clean code — Moving cookie reading before the fetch (rather than after) is a cleaner approach for authentication-first validation.


✅ APPROVE

Summary: Clean, minimal change that correctly adopts an established authentication pattern in the codebase. The shift from static API key to session-based auth is a security improvement. Ship it! 🚀

Reviewers (2)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
pr-review-standards 0 0 0 0 0 0 0
pr-review-security-iam 0 0 0 0 0 0 0
Total 0 0 0 0 0 0 0

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant