Repository navigation
fix(transfer): require local initiation, pairing confirmation, and one-time session authorization - #6893
fix(transfer): require local initiation, pairing confirmation, and one-time session authorization#6893SeniorZhai wants to merge 3 commits into
Conversation
…e-time session authorization
…-session-auth # Conflicts: # app/src/main/java/one/mixin/android/ui/transfer/TransferActivity.kt # app/src/main/java/one/mixin/android/ui/transfer/TransferClient.kt # app/src/main/java/one/mixin/android/ui/transfer/TransferServer.kt
|
AI review done for Quality: Needs fixes before merge. Source inspection and a focused JVM check confirmed the findings, with Android runtime behavior still unverified.
|
There was a problem hiding this comment.
AI review · Codex (Grok failed) · 7d39caa
git diff --check and XML parsing passed, and three targeted JVM checks reproduced the reported behaviors they covered. Android assembly, lint, and unit tests were blocked before execution because the wrapper could not download Gradle 9.9.2 and the installed Gradle could not initialize file locking in the sandbox.
| toast(R.string.transfer_pairing_expired_or_cancelled) | ||
| return@setPositiveButton | ||
| } | ||
| pushRequest() |
There was a problem hiding this comment.
Pass the approved authorization to pushRequest(). It currently replaces the approved session, then sendMessage() looks up the linked desktop again, so a desktop relink while the dialog is open can send the transfer credentials to a different session. Send the credentials only to the approved extension session and require that authorization when the server accepts CONNECT.
| jobManager.addJobInBackground(AsyncProcessTransferAttachmentFileJob(getAttachmentPath())) | ||
| mutableList.clear() | ||
| transferSessionManager.cancelSession(currentAuthorization?.sessionId) | ||
| clearCacheDirectory() |
There was a problem hiding this comment.
Deleting the staging directory here can leave imported messages with missing media. Message batches are committed before FINISH, so a connection drop can leave their rows in the database while this branch deletes attachments that already arrived. Preserve staged files that match committed messages, as the previous cleanup job did.
| ) { | ||
| val session = currentSession ?: return | ||
| if (session.accountId == accountId && | ||
| (session.expectedExtensionSessionId == null || session.expectedExtensionSessionId == extensionSessionId) && |
There was a problem hiding this comment.
A cancellation from the linked desktop can abort an unrelated phone restore. Phone restores have a null expectedExtensionSessionId, which this condition treats as a match. The isolated check confirmed that the restore becomes CANCELLED and loses write authorization. Require an exact, non-null extension session match before applying a desktop cancellation.
| onConnectionFailed, | ||
| val ip = requireNotNull(transferCommandData.ip) | ||
| val port = requireNotNull(transferCommandData.port) | ||
| val key = requireNotNull(transferCommandData.secretKey).decodeBase64() |
There was a problem hiding this comment.
Confirming a phone restore can crash when the QR code contains a nonblank, malformed Base64 key. Validation accepts it, then the decoder throws before TransferClient can handle the failure, and the confirmation coroutine has no exception handler. Decode and validate the key before showing the confirmation dialog and report invalid input as a data error.
| super.onStop() | ||
| transferDisposable?.dispose() | ||
| transferSpeedDisposable?.dispose() | ||
| transferControlDisposable?.dispose() |
There was a problem hiding this comment.
A desktop restore can get stuck on Waiting if the reply arrives while this activity is stopped. onStop() removes the subscriber, the bus does not replay the reply, and the message is marked read. Returning to the screen leaves Start disabled. Retain the pending reply for the active session and handle it when the activity resumes.
There was a problem hiding this comment.
AI review · Codex (Grok failed) · 761a49e
Three defects remain after reviewing the changes since the previous revision. Both Git diff checks and XML parsing passed, and the simulated-clock JVM check reproduced expiry in both sending directions. Gradle failed during native-service initialization, before Android assembly, lint, or unit tests ran.
| } | ||
| lifecycleScope.launch { | ||
| transferServer.startServer(selectConversation, selectDate) { transferData -> | ||
| transferServer.startServer(sessionId, selectConversation, selectDate) { transferData -> |
There was a problem hiding this comment.
A desktop relink can redirect the credentials for an approved transfer. This call retains the local session ID, but sendMessage() looks up the linked desktop again when it runs, so the newly linked session can receive the connection details and key. Use the extension session recorded in the approval as the recipient and bind the server’s CONNECT check to that authorization.
| jobManager.addJobInBackground(AsyncProcessTransferAttachmentFileJob(getAttachmentPath())) | ||
| mutableList.clear() | ||
| transferSessionManager.cancelSession(currentAuthorization?.sessionId) | ||
| clearCacheDirectory() |
There was a problem hiding this comment.
An interrupted restore can leave committed messages with missing attachments. processJson() commits batches before FINISH, and this branch deletes the staging directory on disconnect. The finally block also deletes files left behind when attachment processing aborts. Restore the cleanup job’s recovery behavior for staged files that match committed messages.
| private fun expireIfNeeded(session: TransferSession) { | ||
| if (clock() <= session.expiresAtMillis) return | ||
| if (session.state == TransferSessionState.INITIATED || session.state == TransferSessionState.AWAITING_PAIRING || | ||
| session.state == TransferSessionState.SENDING || (session.state == TransferSessionState.CONSUMED && session.direction.isSending) |
There was a problem hiding this comment.
Applying the pairing deadline to SENDING can cut off an active transfer. A clock test confirmed that after four minutes of setup, both sending directions expire just over one minute into sending. The server checks that state before each socket write. Give active transfers a separate deadline that starts after the connection is verified.
No description provided.