fix(coderd/workspaceapps): prefer app session cookie over Authorization#22041
Merged
deansheather merged 1 commit intocoder:mainfrom Feb 11, 2026
Merged
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
This was referenced Feb 10, 2026
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
cdrci2
added a commit
to coder/cla
that referenced
this pull request
Feb 10, 2026
deansheather
approved these changes
Feb 11, 2026
jdomeracki-coder
approved these changes
Feb 11, 2026
ThomasK33
approved these changes
Feb 11, 2026
Member
|
Thank you for your contribution! |
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.
This PR fixes a workspace app authentication bug where requests that include an
Authorizationheader (intended for the upstream app) can cause Coder to ignore the workspace app session cookie (coder_subdomain_app_session_token_*/coder_path_app_session_token). When that happens, Coder fails to mint or renewcoder_signed_app_tokenand redirects to/api/v2/applications/auth-redirectinstead of proxying the request to the workspace.This commonly shows up when users run a frontend and backend in the same workspace and the backend requires
Authorization(for example,curl -H "Authorization: bearer ..."or browserfetch()calls).Related issues / context:
Primary bug report and repro: bug: coder_signed_app_token is not renewed when an Authorization header is sent #21467
Related symptoms reported as CORS / redirect failures for workspace apps:
Root Cause
In
coderd/workspaceapps/cookies.go,AppCookies.TokenFromRequestcheckedhttpmw.APITokenFromRequest(r)first. That helper returns a token from several places, includingAuthorization: Bearer ....As a result, when a request included an upstream
Authorizationheader, that header value was returned as the “session token” for the app proxy, andcoder_subdomain_app_session_token_*was never read. Authentication then failed and the request was treated as signed out.Fix
Change the precedence in
AppCookies.TokenFromRequest:First check the access-method-specific cookie:
coder_subdomain_app_session_token_{hash}coder_path_app_session_tokenIf not present, fall back to
httpmw.APITokenFromRequest(r)(so non-browser clients can still authenticate via query, header, or bearer tokens if they really want to).This ensures that:
Authorizationstill reach the workspace.coder_signed_app_tokencan be renewed from the app session cookie even whenAuthorizationis present.Authorizationis still forwarded to the upstream app (the reverse proxy code does not strip it).Initially, I attempted workarounds (#20667 (comment), #19728 (comment)), but adding
/auth-redirectto the permissive CORS paths and extending the validity of workspace app auth tokens from 1 minute to 1 hour only partially masked the issue. After workspace restarts and token expiry, I no longer saw CORS errors, but the tokens were still not renewed.After patching my local Nix-based setup on Coder v1.30.0 with this change, I can no longer observe this behavior.