Skip to content

fix: Forward Set-Cookie and strip Bearer token#1289

Merged
edwinjosechittilappilly merged 3 commits intomainfrom
fix-google-auth
Apr 1, 2026
Merged

fix: Forward Set-Cookie and strip Bearer token#1289
edwinjosechittilappilly merged 3 commits intomainfrom
fix-google-auth

Conversation

@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

frontend/app/api/[...path]/route.ts: Ensure Set-Cookie headers from proxied responses are forwarded explicitly by iterating response.headers.getSetCookie() and appending each cookie to responseHeaders (entries() may omit them). This preserves cookies for proxied streaming responses.

src/session_manager.py: Accept Authorization headers with a "Bearer " prefix by stripping the prefix before calling jwt.decode. This prevents passing the literal "Bearer ..." string to the decoder and fixes token verification failures when Bearer tokens are used.

frontend/app/api/[...path]/route.ts: Ensure Set-Cookie headers from proxied responses are forwarded explicitly by iterating response.headers.getSetCookie() and appending each cookie to responseHeaders (entries() may omit them). This preserves cookies for proxied streaming responses.

src/session_manager.py: Accept Authorization headers with a "Bearer " prefix by stripping the prefix before calling jwt.decode. This prevents passing the literal "Bearer ..." string to the decoder and fixes token verification failures when Bearer tokens are used.
Copilot AI review requested due to automatic review settings March 27, 2026 15:36
@github-actions github-actions bot added frontend 🟨 Issues related to the UI/UX backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. labels Mar 27, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves auth/session interoperability between the Next.js proxy layer and the Python backend by ensuring cookies and Bearer tokens are handled correctly during proxying and JWT verification.

Changes:

  • Forward Set-Cookie headers explicitly in the Next.js proxy route using response.headers.getSetCookie().
  • Strip the "Bearer " prefix in SessionManager.verify_token() before calling jwt.decode() to support Authorization-style tokens.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/session_manager.py Strips Bearer prefix before JWT decoding to prevent verification failures.
frontend/app/api/[...path]/route.ts Ensures proxied Set-Cookie headers are preserved (including for streaming responses).
Comments suppressed due to low confidence (1)

src/session_manager.py:226

  • verify_token() now accepts Authorization-style values by stripping the Bearer prefix, but this behavior isn't currently covered by a unit/integration test. Adding a test that verify_token("Bearer <jwt>") successfully decodes the same as the raw JWT would prevent regressions (especially since the cookie value is stored as Bearer ...).
            raw = token[7:] if token.startswith("Bearer ") else token
            payload = jwt.decode(
                raw,
                self.public_key,
                algorithms=[self.algorithm],
                audience=["opensearch", "openrag"],
            )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def verify_token(self, token: str) -> Optional[Dict[str, Any]]:
"""Verify JWT token and return user info"""
try:
raw = token[7:] if token.startswith("Bearer ") else token
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

Avoid the hard-coded slice length (token[7:]) when stripping the Bearer prefix. Since the project requires Python >= 3.13, using token.removeprefix("Bearer ") (optionally combined with a .strip() if desired) makes the intent clearer and removes the magic number.

Suggested change
raw = token[7:] if token.startswith("Bearer ") else token
raw = token.removeprefix("Bearer ")

Copilot uses AI. Check for mistakes.
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.

agree w/ this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@github-actions github-actions bot removed the bug 🔴 Something isn't working. label Apr 1, 2026
@github-actions github-actions bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Apr 1, 2026
@github-actions github-actions bot added the lgtm label Apr 1, 2026
@edwinjosechittilappilly edwinjosechittilappilly merged commit dda7bcd into main Apr 1, 2026
11 checks passed
@github-actions github-actions bot deleted the fix-google-auth branch April 1, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. frontend 🟨 Issues related to the UI/UX lgtm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants