Repository navigation
fix: v1.59 リリース前レビューの残り指摘を消化する (#1012) #1017
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
Changes from all commits
b6d5c19
209c723
3b362c6
e12fcbd
4150681
6205756
efe761a
aab451f
e139d4e
b3f27c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,6 @@ class AccountStorage { | |
| /// (`mastodon://user@host`)の JSON 配列で、**host + username だけを持つ | ||
| /// 非秘匿値**(secret は secure storage 側)。 | ||
| static const accountListKey = 'capsicum_account_keys_v2'; | ||
| static const _accountListKey = accountListKey; | ||
| // _v1 は #643 の初版で導入したが、当時の migration / write が旧 item を | ||
| // accessibility 取りこぼしで救えておらず(後述)空振りでフラグだけ立てて | ||
| // いた。修正版を全員に再実行させるため _v2 に上げる (内部ベータ | ||
|
|
@@ -218,7 +217,7 @@ class AccountStorage { | |
| /// copies it over so existing users don't lose their account list. | ||
| Future<List<String>> getAccountKeys() async { | ||
| final prefs = await _prefs(); | ||
| final encoded = prefs.getString(_accountListKey); | ||
| final encoded = prefs.getString(accountListKey); | ||
| if (encoded != null) { | ||
| try { | ||
| return List<String>.from(jsonDecode(encoded) as List); | ||
|
|
@@ -227,7 +226,7 @@ class AccountStorage { | |
| // して前進する(Sentry には出さない。secure_storage ほどの信号 | ||
| // 価値がないため)。 | ||
| debugLogException('capsicum: failed to parse account keys', e); | ||
| await prefs.remove(_accountListKey); | ||
| await prefs.remove(accountListKey); | ||
| return []; | ||
| } | ||
| } | ||
|
|
@@ -346,6 +345,72 @@ class AccountStorage { | |
| await _writeIndex(list); | ||
| } | ||
|
|
||
| /// 索引へ**書き戻す**前に、その key の secret が残骸として残っていれば消す | ||
| /// (#1012)。 | ||
| /// | ||
| /// ⚠ **[removeAccount] は secret の delete に失敗しても索引を消す。** | ||
| /// [_deleteSecretWithObservability] は例外を握って観測に回すだけで、Linux | ||
| /// libsecret の非 op delete(#621・`delete_no_op` として計装済み)でも | ||
| /// 索引側は消える。索引から消えている間は誰も参照しないので無害だが、 | ||
| /// **削除前に取った設定バックアップを取り込むと索引だけが復活する** | ||
| /// (`settings_backup.dart` の `_mergeAccounts` は secure storage を見ずに | ||
| /// key を書き戻す)。すると次回起動の `restoreSessions` が残骸トークンを | ||
| /// 読んで probe に成功し、**削除したはずのアカウントが完全ログイン状態で | ||
| /// 戻る**。取り込み直後の UI は #967 に従って「未接続」と言うので、表示と | ||
| /// 実態も食い違う。 | ||
| /// | ||
| /// 「取り込んだアカウントはトークンを持たない」は #1001 が宣言している | ||
| /// 不変条件なので、**宣言する側で本当に成り立たせる**。 | ||
| /// | ||
| /// ⚠ **plugin 未登録は黙って諦める。** register race (#488) と、secure | ||
| /// storage を差し替えていないテストの両方がここに来る。消せなかったぶんは | ||
| /// 「元の状態のまま」=この関数を入れる前と同じなので、観測を汚してまで | ||
| /// 報告する価値が無い。 | ||
| /// | ||
| /// 戻り値は **消しきれなかった** key。#621 の非 op delete はまさにここで | ||
| /// 空振りするので、呼び出し側は**そのアカウントを索引へ書き戻してはいけない** | ||
| /// (書くと「索引あり + 残骸トークンあり」という、この関数が塞ごうとしている | ||
| /// 状態がそのまま完成する)。 | ||
| Future<List<String>> purgeStaleSecrets(Iterable<String> accountKeys) async { | ||
| final unresolved = <String>[]; | ||
| for (final accountKey in accountKeys) { | ||
| final key = 'secret_$accountKey'; | ||
| bool stale; | ||
| try { | ||
| stale = await _storage.containsKey(key: key); | ||
| } on MissingPluginException { | ||
| return unresolved; | ||
| } catch (e, st) { | ||
| debugLogException( | ||
| 'capsicum: stale secret probe failed for $accountKey', | ||
| e, | ||
| ); | ||
| _reportOnce('secret:$accountKey:purge_probe', e, st); | ||
| // 読めない=残骸の有無が分からない。**分からないときは書き戻さない** | ||
| // 側へ倒す(誤って復活させる代償のほうが大きい)。 | ||
| unresolved.add(accountKey); | ||
| continue; | ||
| } | ||
| if (!stale) continue; | ||
| // ここに来たら **#621 の非 op delete が実際に起きていた証跡**。索引から | ||
| // 消えたアカウントの secret が生き残っていたということなので、握らずに | ||
| // 残す(この経路以外では観測できない)。 | ||
| _reportOnce( | ||
| 'secret:$accountKey:stale_on_import', | ||
| StateError('stale secret survived account removal for $key'), | ||
| StackTrace.current, | ||
|
Comment on lines
+398
to
+401
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Whenever an imported account has a stale secret, this event sends a Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ); | ||
| await _deleteSecretWithObservability(accountKey); | ||
| try { | ||
| if (await _storage.containsKey(key: key)) unresolved.add(accountKey); | ||
| } catch (_) { | ||
| // 確認できないなら消えたと見なさない。 | ||
| unresolved.add(accountKey); | ||
| } | ||
| } | ||
| return unresolved; | ||
| } | ||
|
|
||
| /// `_storage.delete` の例外を握り潰さず観測し、delete 後に残骸が残れば | ||
| /// 1 度だけ再 delete を試みる (#621)。flutter_secure_storage_linux が | ||
| /// key に `:` / `/` / `@` を含む URL 形式で delete を non-op で帰す挙動 | ||
|
|
@@ -494,9 +559,9 @@ class AccountStorage { | |
| // SharedPreferences.setString は失敗時に `false` を返す(throw しない)。 | ||
| // 戻り値を無視すると失敗が成功扱いになり、legacy 移行側で legacy を | ||
| // delete → 全アカウントインデックス永久消失、となる(Codex 指摘)。 | ||
| final ok = await prefs.setString(_accountListKey, jsonEncode(keys)); | ||
| final ok = await prefs.setString(accountListKey, jsonEncode(keys)); | ||
| if (!ok) { | ||
| throw StateError('prefs.setString returned false for $_accountListKey'); | ||
| throw StateError('prefs.setString returned false for $accountListKey'); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /// Windows の push 診断コードのうち「正常系」の集合 (#1012)。 | ||
| /// | ||
| /// ⚠⚠ **ネイティブ `windows/runner/push_diagnostics.cpp` の `IsBenignCode` と | ||
| /// 完全一致させること。** 片方だけに足すと: | ||
| /// | ||
| /// - **Dart にだけある** … ネイティブは異常系として扱うので、単一スロットの | ||
| /// 診断レコードで正常系が異常系を上書きしなくなる(#997 で仕組んだ「異常を | ||
| /// 優先して残す」が効かない) | ||
| /// - **ネイティブにだけある** … Dart が warning で上げるので、**正常運転の | ||
| /// コードが平常時の端末から毎回 warning で届く**(#997 の | ||
| /// `wns.announcement_deduped` がまさにこの形だった) | ||
| /// | ||
| /// これまで一致を守っていたのは**両側のコメントだけ**で、検査が無かった。 | ||
| /// C++ 側のテストは tag ビルドでしか回らない(`docs/tech-notes.md`「Windows | ||
| /// ネイティブを触ったときの検証手順」)ので、突き合わせは Dart 側の | ||
| /// `test/wns_benign_codes_parity_test.dart` が `.cpp` を読んで行う。 | ||
| /// | ||
| /// ⚠ **`*.shown` 系は「表示に成功したときだけ」記録される** (#957 / #978 / | ||
| /// #997)。表示失敗(`bgtask.show_failed` / `bgtask.announcement_show_failed` / | ||
| /// `wns.show_failed` / `wns.announcement_show_failed`)をここへ入れない。 | ||
| library; | ||
|
|
||
| /// 正常運転として `info` で上げるコード。ここに無いものは `warning`。 | ||
| const wnsBenignDiagnosticCodes = <String>{ | ||
| 'bgtask.shown', | ||
| 'bgtask.announcement_shown', | ||
| 'bgtask.not_encrypted', | ||
| 'bgtask.not_raw', | ||
| 'wns.announcement_shown', | ||
| // WebSocket 経路 (#569) が先に出したので抑止した = 通常運転 (#997)。 | ||
| 'wns.announcement_deduped', | ||
| }; |
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.
When
containsKeythrowsMissingPluginExceptionduring backup import, this returns the unresolved keys accumulated so far—normally an empty list—so_mergeAccountstreats every unexamined account as safe and writes it into the index. If a deleted account still has a token because its earlier deletion was a no-op, the next launch can restore that supposedly deleted account as fully authenticated. Return the current and remaining account keys as unresolved, or retry the plugin operation, rather than treating the probe failure as success.Useful? React with 👍 / 👎.
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.
#1020 / PR #1021 で消化しました。
⚠ 指摘のとおり fail-open でした。「消せなかったぶんは元のまま」という doc の理屈は #1012 より前の話で、#1012 で呼び出し側の契約が「返らなかった key は書き戻してよい」に変わっていたのを見落としていました。未調査ぶんも未解決として返す fail-closed にしています。
⚠⚠ この挙動はテストで「正しいもの」として固定されていました(「plugin 未登録なら取り込みを止めない」)。逆向きに書き直したうえで、2 件目以降を取りこぼさない検査も足しています(最初の 1 件で打ち切って返す実装なので、そこが緩いと残りが「きれい」として索引へ入ります)。