fix(dispatch): 一支裝置 token 只能有一位主人——換人登入不再收到前一位的推播(U5) - #65
Merged
Conversation
DeviceTokenRepository.Upsert 以 (role, subject_id, token) 為鍵,換人登入時舊列會留著。 FCM token 是「這台裝置上的這個 App」的識別,換人登入時它不會變;而 App 在 session 失效(401)那條路徑刻意不呼叫註銷(那支 API 只會再回一次 401)。於是: A 的 token 過期 → B 在同一台手機登入 → A 的行程通知與對話推播全部送到 B 的手機。 對話推播的本文帶訊息文字,所以這不只是雜訊,是把 A 的私訊顯示在 B 的鎖定畫面上。 - Upsert 註冊前先刪掉「同一支 token 掛在別人身上」的列(跨角色也算別人)。 - 只搬同一支 token,一人多裝置不受影響;同一人重複註冊仍冪等。 驗收:新增 device_token_integration_test.go 四案(換人移轉/跨角色移轉/重複註冊冪等/ 多裝置不受影響),真 PostGIS 容器跑過。 反向確認:移掉那段刪除,前兩案 FAIL——舊主人身上確實還留著那支 token。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Jul 29, 2026
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.
問題(隱私外洩)
DeviceTokenRepository.Upsert以(role, subject_id, token)為鍵——換人登入時舊列會留著。FCM/APNs token 是「這台裝置上的這個 App」的識別,換人登入時它不會變;
而 App 在 session 失效(401)那條路徑刻意不呼叫註銷
(那支 API 只會再回一次 401,見 fleet-app 第十一輪的設計)。於是:
對話推播的本文帶訊息文字,所以這不只是雜訊,是把 A 的私訊顯示在 B 的鎖定畫面上。
(這批推播剛上線 —— #61/#62/#63 —— 所以是新功能帶進來的新風險。)
做了什麼
Upsert註冊前先刪掉「同一支 token 掛在別人身上」的列(跨角色也算別人:同一台手機先登司機後登乘客也要搬)。
驗收
device_token_integration_test.go四案(換人移轉/跨角色移轉/重複註冊冪等/多裝置不受影響),真 PostGIS 容器跑過。
App 端要不要改?
不用,而且這正好讓 App 現行設計是安全的:401 時不去打註銷 API 是對的
(那支只會再回一次 401),漏掉的清理現在由後端在下一次註冊時完成。
🤖 Generated with Claude Code