fix(web): validate desktop session callback port - #2084
Merged
Conversation
The `port` query parameter on the desktop sign-in callback (GET /api/desktop/session/request) was validated only as an optional string and interpolated directly into the callback URL. Constrain it to a numeric port (1-65535) and build the loopback URL through a fixed-host helper so the callback always targets 127.0.0.1. Escape the values embedded in the desktop fallback page's inline script and href attribute as well. The desktop app obtains this port from its local OAuth callback server, which is always numeric, so sign-in behaviour is unchanged for valid ports; a non-numeric port now returns 400. The no-port deep-link path and the platform/type defaults are untouched. Move the schema, URL builder, and page renderer into apps/web/lib/desktop-session.ts and add unit tests.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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.
What
The desktop sign-in callback (
GET /api/desktop/session/request) accepted itsportquery parameter as an optional string and interpolated it directly into the callback URL. This constrainsportto a numeric port (1-65535) and constructs the loopback callback URL through a fixed-host helper, so the callback target is always127.0.0.1.It also escapes the values rendered into the desktop fallback page's inline
<script>block and itshrefattribute.Why it is safe for the desktop app
The desktop app supplies
portfrom its local OAuth callback server (plugin:oauth|start), which always returns a numeric loopback port, so it still passes validation. Behaviour for valid ports is unchanged; only a non-numeric port now returns400instead of redirecting. The no-port deep-link path and theplatform/typedefaults are untouched.Changes
apps/web/lib/desktop-session.ts(new): request schema,buildLoopbackCallbackUrl, and the fallback page renderer with output escaping.apps/web/app/api/desktop/[...route]/session.ts: use the shared schema and helper.apps/web/__tests__/unit/desktop-session-port.test.ts(new): 32 tests covering schema accept/reject, the loopback invariant across the full port range, the request boundary, and the fallback page escaping.Testing
pnpm --dir apps/web exec vitest run __tests__/unit/desktop-session-port.test.ts(32 passing)Greptile Summary
The PR secures the desktop session callback against off-loopback redirects and fallback-page injection.
127.0.0.1host.Confidence Score: 5/5
The PR appears safe to merge, with no concrete changed-code failure identified.
Valid desktop callback ports remain accepted, callback credentials remain constrained to the loopback host, and the extracted fallback-page renderer preserves behavior while eliminating its injection sinks.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(web): validate desktop session callb..." | Re-trigger Greptile
Context used: