Repository navigation
fix(auth): accept the OAuth v2 openhands_auth session cookie - #568
Merged
Merged
Conversation
The OpenHands web UI is migrating to a dual-cookie scheme: new logins receive the small JWT openhands_auth cookie, while existing sessions keep the legacy chunked keycloak_auth cookie until it expires. Automation authenticates by forwarding the caller's cookie to OpenHands GET /api/v1/users/me, so it must accept either name or users who log in after the migration get a 401. Accept both cookies, preferring openhands_auth. The cookie is forwarded verbatim under its original name because the two structures differ and only upstream parses them; Automation itself never decodes the value.
tofarr
marked this pull request as ready for review
October 9, 2026 17:38
Contributor
|
Warning Your comment is too long (maximum is 65536 characters), so the coverage report was not added. See the job log for how to reduce it. |
tofarr
enabled auto-merge (squash)
October 9, 2026 17:45
Contributor
|
🚀 Released in 1.19.2. |
1 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The OpenHands web UI is moving to a dual-cookie authentication scheme (OpenHands/enterprise#525, epic OHE-3293): new logins receive a small JWT cookie named
openhands_auth, while existing sessions keep the legacy chunkedkeycloak_authcookie until it naturally expires. Upstream reads both and prefersopenhands_auth.Automation authenticates by forwarding the caller's cookie to OpenHands
GET /api/v1/users/me. It previously only recognizedkeycloak_auth, so any user who logs in after the migration would get a401from Automation even though their session is valid.What changed
openhands/automation/auth.py:SESSION_COOKIE_NAME = "keycloak_auth"withSESSION_COOKIE_NAMES = ("openhands_auth", "keycloak_auth")— the new cookie is checked first._extract_session_cookienow returns the(name, value)pair and checks both names, still reassembling chunked values (<name>,<name>_1, …)._extract_credentialbuilds the cookie credential asname=value._upstream_headersforwards thatname=valuepair verbatim, so the original cookie name reaches upstream.Why the name must be preserved
The two cookies have completely different structures —
keycloak_authis a chunked signed JWS wrapping Keycloak access/refresh tokens,openhands_authis a small single JWT cookie — and upstream routes them to different decoders. Automation never decodes the cookie; it treats the value as opaque and forwards it under its own name, which is the only way upstream can parse it correctly.Tests
tests/test_auth.py:openhands_authcookie authenticates, and thename=valueis forwarded unchanged;openhands_authwins when both cookies are present;keycloak_authwhen the new cookie is absent;Verification
tests/test_auth.py(non-Docker): 53 passed;tests/test_cors.py: 9 passed.ruff check,ruff format --check, andpyrightall clean.This PR was created by an AI agent (OpenHands) on behalf of the user.
@tofarr can click here to continue refining the PR