-
Notifications
You must be signed in to change notification settings - Fork 5.8k
fix(mobile): block incompatible server connections #11974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
54 changes: 54 additions & 0 deletions
54
packages/client-runtime/src/connection/compatibility.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { | ||
| EnvironmentId, | ||
| ORCHESTRATION_PROTOCOL_VERSION, | ||
| type ExecutionEnvironmentDescriptor, | ||
| } from "@t3tools/contracts"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { | ||
| appendOrchestrationProtocol, | ||
| orchestrationProtocolCompatibilityError, | ||
| } from "./compatibility.ts"; | ||
|
|
||
| const descriptor = (orchestrationProtocolVersion?: number): ExecutionEnvironmentDescriptor => ({ | ||
| environmentId: EnvironmentId.make("environment-remote"), | ||
| label: "Build Mac", | ||
| platform: { os: "darwin", arch: "arm64" }, | ||
| serverVersion: "9.0.0", | ||
| ...(orchestrationProtocolVersion === undefined ? {} : { orchestrationProtocolVersion }), | ||
| capabilities: { repositoryIdentity: true }, | ||
| }); | ||
|
|
||
| describe("orchestration protocol compatibility", () => { | ||
| it("accepts the current protocol and announces it without disturbing socket credentials", () => { | ||
| expect( | ||
| orchestrationProtocolCompatibilityError(descriptor(ORCHESTRATION_PROTOCOL_VERSION)), | ||
| ).toBeNull(); | ||
|
|
||
| const socketUrl = new URL( | ||
| appendOrchestrationProtocol("wss://host.test/ws?wsTicket=secret&connectionMethod=relay"), | ||
| ); | ||
| expect(socketUrl.searchParams.get("orchestrationProtocol")).toBe( | ||
| String(ORCHESTRATION_PROTOCOL_VERSION), | ||
| ); | ||
| expect(socketUrl.searchParams.get("wsTicket")).toBe("secret"); | ||
| expect(socketUrl.searchParams.get("connectionMethod")).toBe("relay"); | ||
| }); | ||
|
|
||
| it("treats missing metadata as protocol 1", () => { | ||
| const error = orchestrationProtocolCompatibilityError(descriptor()); | ||
| if (Number(ORCHESTRATION_PROTOCOL_VERSION) === 1) { | ||
| expect(error).toBeNull(); | ||
| } else { | ||
| expect(error).toMatchObject({ reason: "unsupported" }); | ||
| } | ||
| }); | ||
|
|
||
| it("blocks a different protocol before connecting", () => { | ||
| const error = orchestrationProtocolCompatibilityError( | ||
| descriptor(ORCHESTRATION_PROTOCOL_VERSION + 1), | ||
| ); | ||
| expect(error).toMatchObject({ reason: "unsupported" }); | ||
| expect(error?.message).toContain("This client is not supported"); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { | ||
| ORCHESTRATION_PROTOCOL_QUERY_PARAM, | ||
| ORCHESTRATION_PROTOCOL_VERSION, | ||
| type ExecutionEnvironmentDescriptor, | ||
| } from "@t3tools/contracts"; | ||
|
|
||
| import { ConnectionBlockedError } from "./model.ts"; | ||
|
|
||
| export function orchestrationProtocolCompatibilityError( | ||
| descriptor: ExecutionEnvironmentDescriptor, | ||
| ): ConnectionBlockedError | null { | ||
| // Servers shipped before negotiation use the original wire protocol. | ||
| const serverProtocolVersion = descriptor.orchestrationProtocolVersion ?? 1; | ||
| if (serverProtocolVersion === ORCHESTRATION_PROTOCOL_VERSION) { | ||
| return null; | ||
| } | ||
| return new ConnectionBlockedError({ | ||
| reason: "unsupported", | ||
| detail: | ||
| serverProtocolVersion > ORCHESTRATION_PROTOCOL_VERSION | ||
| ? `This client is not supported by this server. Update your app or use a compatible release to connect to ${descriptor.label}.` | ||
| : `This client requires a newer server. Update T3 Code on ${descriptor.label} to connect.`, | ||
| }); | ||
| } | ||
|
|
||
| export function appendOrchestrationProtocol(socketUrl: string): string { | ||
| const url = new URL(socketUrl); | ||
| url.searchParams.set(ORCHESTRATION_PROTOCOL_QUERY_PARAM, String(ORCHESTRATION_PROTOCOL_VERSION)); | ||
| return url.toString(); | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Make the unsupported status non-actionable.
unavailable()assignsonReconnecttoonPress, and the renderer passes it directly to the connection pill. Pressing the unsupported pill therefore callsretryNow, which resets retry state and emitsRetryRequested. Keep this action for"offline", but omit it for"unsupported"and make the renderer's press handler and button role conditional.🤖 Prompt for AI Agents