Skip to content

The agent that grows with you

fix(desktop): gate the plain-text token warning on secure storage being unavailable

xielevi5d9af50aa084
diff --git a/apps/desktop/electron/hardening.test.ts b/apps/desktop/electron/hardening.test.ts
index 48c2c1b3121..78dbeb13c5c 100644
--- a/apps/desktop/electron/hardening.test.ts
+++ b/apps/desktop/electron/hardening.test.ts
@@ -19,6 +19,7 @@ import {
resolveDirectoryForIpc,
resolvePersistedRemoteToken,
resolveReadableFileForIpc,
+ resolveRemoteTokenPlainText,
resolveRequestedPathForIpc,
resolveTimeoutMs,
SAFE_STORAGE_ENCODING,
@@ -382,6 +383,66 @@ test('resolvePersistedRemoteToken keeps the existing token when no new token is
assert.equal(called, false, 'an empty incoming token must not re-encrypt anything')
})
+test('resolveRemoteTokenPlainText stays silent in the keychain-opt-out default', () => {
+ // #117269: with encryption opted out (the default), plain text is the CHOSEN
+ // mode and probeSecureTokenStorage reports availability on purpose — every
+ // saved token is plain here, so warning off the encoding alone would fire for
+ // every default user.
+ assert.equal(
+ resolveRemoteTokenPlainText({
+ envOverride: false,
+ token: { encoding: 'plain', value: 'token' },
+ secureTokenStorage: true
+ }),
+ false
+ )
+})
+
+test('resolveRemoteTokenPlainText warns only when the token is plain and the machine cannot secure it', () => {
+ // The genuine degraded state the banner is for: the keyring has gone away
+ // (secureTokenStorage false) while a plain token sits on disk.
+ assert.equal(
+ resolveRemoteTokenPlainText({
+ envOverride: false,
+ token: { encoding: 'plain', value: 'token' },
+ secureTokenStorage: false
+ }),
+ true
+ )
+
+ // An encrypted token never warns, whatever availability reports.
+ for (const secureTokenStorage of [true, false]) {
+ assert.equal(
+ resolveRemoteTokenPlainText({
+ envOverride: false,
+ token: { encoding: 'safeStorage', value: 'blob' },
+ secureTokenStorage
+ }),
+ false
+ )
+ }
+
+ // A missing token, or an absent availability signal, never manufactures a
+ // warning — the strict `=== false` match.
+ assert.equal(resolveRemoteTokenPlainText({ envOverride: false, token: undefined, secureTokenStorage: false }), false)
+ assert.equal(
+ resolveRemoteTokenPlainText({ envOverride: false, token: { encoding: 'plain' }, secureTokenStorage: undefined }),
+ false
+ )
+ assert.equal(resolveRemoteTokenPlainText({}), false)
+
+ // The env override supplies its token from the environment, never the saved
+ // block, so a plain stored blob must not warn while the override is active.
+ assert.equal(
+ resolveRemoteTokenPlainText({
+ envOverride: true,
+ token: { encoding: 'plain', value: 'token' },
+ secureTokenStorage: false
+ }),
+ false
+ )
+})
+
test('writeSecretFileAtomic does not inherit loose bits from a stale temp file', () => {
// renameSync keeps the TEMP file's permissions, and writeFileSync's `mode`
// is ignored when the path already exists — so a temp left by a crashed
@@ -1019,6 +1080,25 @@ test('sanitizeDesktopConnectionConfig exposes secureTokenStorage and remoteToken
assert.match(returned, /\bremoteTokenPlainText\b/, 'the renderer needs the plain-text token signal')
})
+// #117269: the plain-text signal must be gated on the machine actually being
+// unable to secure the token — an inline encoding check would warn every
+// keychain-opt-out user, whose chosen mode is plain text. The signal flows
+// through resolveRemoteTokenPlainText (behavior tests above); this pins the
+// main-process wiring so the gate cannot be dropped at the call site.
+test('sanitizeDesktopConnectionConfig routes remoteTokenPlainText through the gated helper', () => {
+ const source = readMain()
+ const fnStart = source.indexOf('async function sanitizeDesktopConnectionConfig(')
+ assert.notEqual(fnStart, -1, 'sanitizeDesktopConnectionConfig must exist in main.ts')
+ const fnEnd = source.indexOf('\nfunction ', fnStart + 1)
+ const body = source.slice(fnStart, fnEnd === -1 ? undefined : fnEnd)
+
+ assert.match(
+ body,
+ /const remoteTokenPlainText = resolveRemoteTokenPlainText\(\{/,
+ 'remoteTokenPlainText must be computed by resolveRemoteTokenPlainText (gated on secure storage) (#117269)'
+ )
+})
+
// #95393: connections.save succeeded but the switcher menu (renderer
// $connectionsRegistry snapshot) never refreshed until reload. The registry
// push (broadcastConnectionsChanged) fired only on the dial-material-edit
diff --git a/apps/desktop/electron/hardening.ts b/apps/desktop/electron/hardening.ts
index b75dcad55ae..3e393502b46 100644
--- a/apps/desktop/electron/hardening.ts
+++ b/apps/desktop/electron/hardening.ts
@@ -266,6 +266,22 @@ function resolvePersistedRemoteToken({
return encryptSecret(incomingToken, { allowPlainText: allowPlainText === true })
}
+// The renderer-facing "the saved token is in plain text" warning signal for the
+// connection-config IPC path. Plain text is the CHOSEN mode while keychain
+// encryption is opted out — probeSecureTokenStorage reports availability in
+// that mode on purpose — so the warning fires only for the genuinely degraded
+// state: the token is plain AND the machine cannot secure it (the keyring-less
+// opt-in path). The env override supplies its token from the environment, not
+// the saved block, so it never warns; `secureTokenStorage === false` is matched
+// strictly so an absent signal never manufactures a warning.
+function resolveRemoteTokenPlainText({ envOverride, token, secureTokenStorage }: any = {}) {
+ if (envOverride) {
+ return false
+ }
+
+ return token?.encoding === 'plain' && secureTokenStorage === false
+}
+
function sensitiveFileBlockReason(filePath) {
const normalized = String(filePath || '')
.replace(/\\/g, '/')
@@ -567,6 +583,7 @@ export {
resolveDirectoryForIpc,
resolvePersistedRemoteToken,
resolveReadableFileForIpc,
+ resolveRemoteTokenPlainText,
resolveRequestedPathForIpc,
resolveTimeoutMs,
SAFE_STORAGE_ENCODING,
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 70fbac573fb..073f95c516b 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -240,6 +240,7 @@ import {
readFileDataUrlForIpc,
resolvePersistedRemoteToken,
resolveReadableFileForIpc,
+ resolveRemoteTokenPlainText,
resolveRequestedPathForIpc,
resolveTimeoutMs,
SAFE_STORAGE_ENCODING,
@@ -9718,10 +9719,13 @@ async function sanitizeDesktopConnectionConfig(config = readDesktopConnectionCon
// that raises the macOS password dialog (see probeSecureTokenStorage).
const secureTokenStorage = probeSecureTokenStorage()
- // Whether the currently saved token is stored in plain text (the keyring-less
- // opt-in path). The env override supplies its token from the environment, not
- // the saved block, so it never reports as plain text here.
- const remoteTokenPlainText = !envOverride && block.token?.encoding === 'plain'
+ // Whether the renderer should warn that the saved token sits in plain text.
+ // resolveRemoteTokenPlainText keeps this silent while keychain encryption is
+ // opted out (the default) — plain text is the chosen mode there, not a
+ // degraded state — and fires only when the token is plain AND the machine
+ // cannot secure it (see probeSecureTokenStorage). The env override supplies
+ // its token from the environment, so it never reports as plain text here.
+ const remoteTokenPlainText = resolveRemoteTokenPlainText({ envOverride, secureTokenStorage, token: block.token })
let remoteOauthConnected = false
@@ -9754,7 +9758,8 @@ async function sanitizeDesktopConnectionConfig(config = readDesktopConnectionCon
// Whether the OS keyring can encrypt a token; drives the plain-text opt-in
// affordance in Settings → Gateway on keyring-less Linux.
secureTokenStorage,
- // Whether the saved token is currently persisted in plain text.
+ // Whether the saved token is persisted in plain text while this machine
+ // cannot secure it (drives the warning banner in Settings → Gateway).
remoteTokenPlainText,
sshHost: (ssh || savedSsh)?.host || '',
sshUser: (ssh || savedSsh)?.user || '',
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index 406af856db0..7f9574b8339 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -913,8 +913,9 @@ export interface DesktopConnectionConfig {
// stored as plain text on disk (with an explicit opt-in).
secureTokenStorage: boolean
// Whether the currently-persisted remote token is stored with encoding
- // 'plain' (i.e. plain text on disk in connection.json), which happens when
- // the user opted in on a machine without secure storage.
+ // 'plain' AND this machine cannot secure it (plain text on disk in
+ // connection.json on a keyring-less machine). Stays false while keychain
+ // encryption is opted out — plain text is the chosen mode there.
remoteTokenPlainText: boolean
remoteUrl: string
// For a 'cloud' connection: the persisted Hermes Cloud org (slug or id) the
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index 26a225d6cf1..97118f8119a 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -1227,11 +1227,11 @@ export const en: Translations = {
pasteSessionToken: 'Paste session token',
plainTextConfirmTitle: 'Store the gateway token in plain text?',
plainTextConfirmDesc:
- 'No OS keyring service was found on this machine, so the token would be saved unencrypted in the app’s connection settings file, readable by any process running as this user. Install or enable GNOME Keyring or KWallet for encrypted storage.',
+ 'No OS keyring service was found on this machine, so the token would be saved unencrypted in the app’s connection settings file, readable by any process running as this user. Install or enable your system keychain (GNOME Keyring or KWallet on Linux) for encrypted storage.',
plainTextConfirmAction: 'Save as plain text',
plainTextStoredTitle: 'Token stored in plain text',
plainTextStoredDesc:
- 'Secure storage is unavailable, so the saved token is stored unencrypted in the app’s connection settings file on this machine. Install or enable GNOME Keyring or KWallet to encrypt it.',
+ 'Secure storage is unavailable, so the saved token is stored unencrypted in the app’s connection settings file on this machine. Install or enable your system keychain (GNOME Keyring or KWallet on Linux) to encrypt it.',
keychainEncryptionTitle: 'Encrypt saved secrets with the OS keychain',
keychainEncryptionDesc:
'Off by default. When on, gateway tokens and sign-in credentials are encrypted with your system keychain (Keychain Access, GNOME Keyring, or Windows DPAPI) — your system may ask for permission or a password. When off, they are stored as plain files readable only by your user account.',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index df4eadb6732..5acd3d71e08 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -1073,11 +1073,11 @@ export const ja = defineLocale({
pasteSessionToken: 'セッショントークンを貼り付け',
plainTextConfirmTitle: 'ゲートウェイトークンを平文で保存しますか?',
plainTextConfirmDesc:
- 'このマシンで OS のキーリングサービスが見つからなかったため、トークンはアプリの接続設定ファイルに暗号化されずに保存され、このユーザーとして実行される任意のプロセスから読み取れる状態になります。暗号化して保存するには、GNOME Keyring または KWallet をインストールまたは有効化してください。',
+ 'このマシンで OS のキーリングサービスが見つからなかったため、トークンはアプリの接続設定ファイルに暗号化されずに保存され、このユーザーとして実行される任意のプロセスから読み取れる状態になります。暗号化して保存するには、システムのキーチェーン(Linux では GNOME Keyring または KWallet)をインストールまたは有効化してください。',
plainTextConfirmAction: '平文で保存',
plainTextStoredTitle: 'トークンは平文で保存されています',
plainTextStoredDesc:
- 'セキュアストレージが利用できないため、保存済みのトークンはこのマシンのアプリの接続設定ファイルに暗号化されずに保存されています。暗号化するには GNOME Keyring または KWallet をインストールまたは有効化してください。',
+ 'セキュアストレージが利用できないため、保存済みのトークンはこのマシンのアプリの接続設定ファイルに暗号化されずに保存されています。暗号化するには、システムのキーチェーン(Linux では GNOME Keyring または KWallet)をインストールまたは有効化してください。',
keychainEncryptionTitle: 'OS キーチェーンで保存済みのシークレットを暗号化',
keychainEncryptionDesc:
'デフォルトはオフです。オンにすると、ゲートウェイのトークンとサインイン資格情報がシステムのキーチェーン(Keychain Access、GNOME Keyring、Windows DPAPI)で暗号化されます。システムから許可やパスワードを求められる場合があります。オフの場合は、現在のユーザーのみが読める通常ファイルとして保存されます。',
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index 40fd1de3074..945b88d8c5a 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -1265,11 +1265,11 @@ export const ru = defineLocale({
pasteSessionToken: 'Вставьте токен сессии',
plainTextConfirmTitle: 'Хранить токен шлюза в открытом виде?',
plainTextConfirmDesc:
- 'Служба системного хранилища ключей на этой машине не найдена, поэтому токен будет сохранён без шифрования в файле настроек соединения приложения, и его сможет прочитать любой процесс, работающий от вашего имени. Для шифрованного хранилища установите и включите GNOME Keyring или KWallet.',
+ 'Служба системного хранилища ключей на этой машине не найдена, поэтому токен будет сохранён без шифрования в файле настроек соединения приложения, и его сможет прочитать любой процесс, работающий от вашего имени. Для шифрованного хранилища установите и включите системное хранилище ключей (в Linux — GNOME Keyring или KWallet).',
plainTextConfirmAction: 'Сохранить в открытом виде',
plainTextStoredTitle: 'Токен сохранён в открытом виде',
plainTextStoredDesc:
- 'Безопасное хранилище недоступно, поэтому сохранённый токен хранится без шифрования в файле настроек соединения приложения на этой машине. Установите и включите GNOME Keyring или KWallet для шифрования.',
+ 'Безопасное хранилище недоступно, поэтому сохранённый токен хранится без шифрования в файле настроек соединения приложения на этой машине. Установите и включите системное хранилище ключей (в Linux — GNOME Keyring или KWallet) для шифрования.',
testRemote: 'Проверить удалённый',
saveForRestart: 'Сохранить до следующего перезапуска',
saveAndReconnect: 'Сохранить и переподключиться',
diff --git a/apps/desktop/src/i18n/zh-hant.ts b/apps/desktop/src/i18n/zh-hant.ts
index 31e3269f183..31fe5602f35 100644
--- a/apps/desktop/src/i18n/zh-hant.ts
+++ b/apps/desktop/src/i18n/zh-hant.ts
@@ -1103,11 +1103,11 @@ export const zhHant = defineLocale({
pasteSessionToken: '貼上工作階段 Token',
plainTextConfirmTitle: '以純文字儲存閘道 Token?',
plainTextConfirmDesc:
- '在此裝置上找不到作業系統的金鑰環服務,因此 Token 將以未加密的純文字儲存在應用程式的連線設定檔中,以該使用者身分執行的任何處理程序皆可讀取。請安裝或啟用 GNOME Keyring 或 KWallet 以進行加密儲存。',
+ '在此裝置上找不到作業系統的金鑰環服務,因此 Token 將以未加密的純文字儲存在應用程式的連線設定檔中,以該使用者身分執行的任何處理程序皆可讀取。請安裝或啟用系統鑰匙圈(Linux 上為 GNOME Keyring 或 KWallet)以進行加密儲存。',
plainTextConfirmAction: '以純文字儲存',
plainTextStoredTitle: 'Token 以純文字儲存',
plainTextStoredDesc:
- '安全儲存無法使用,因此已儲存的 Token 以未加密方式儲存在此裝置上應用程式的連線設定檔中。請安裝或啟用 GNOME Keyring 或 KWallet 以將其加密。',
+ '安全儲存無法使用,因此已儲存的 Token 以未加密方式儲存在此裝置上應用程式的連線設定檔中。請安裝或啟用系統鑰匙圈(Linux 上為 GNOME Keyring 或 KWallet)以將其加密。',
keychainEncryptionTitle: '使用系統鑰匙圈加密已儲存的機密',
keychainEncryptionDesc:
'預設關閉。開啟後,閘道 Token 與登入憑證將使用系統鑰匙圈(Keychain Access、GNOME Keyring 或 Windows DPAPI)加密——系統可能會要求授權或密碼。關閉時,它們以僅目前使用者可讀的一般檔案形式儲存。',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 743f31002ad..a52552616d0 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -1433,11 +1433,11 @@ export const zh = defineLocale({
pasteSessionToken: '粘贴会话 token',
plainTextConfirmTitle: '以明文存储网关 token?',
plainTextConfirmDesc:
- '在此设备上未找到操作系统的密钥环服务,因此 token 将以未加密的明文保存在应用的连接设置文件中,以该用户身份运行的任何进程都可读取。请安装或启用 GNOME Keyring 或 KWallet 以进行加密存储。',
+ '在此设备上未找到操作系统的密钥环服务,因此 token 将以未加密的明文保存在应用的连接设置文件中,以该用户身份运行的任何进程都可读取。请安装或启用系统钥匙串(Linux 上为 GNOME Keyring 或 KWallet)以进行加密存储。',
plainTextConfirmAction: '以明文保存',
plainTextStoredTitle: 'Token 以明文存储',
plainTextStoredDesc:
- '安全存储不可用,因此已保存的 token 以未加密方式存储在此设备上应用的连接设置文件中。请安装或启用 GNOME Keyring 或 KWallet 以对其加密。',
+ '安全存储不可用,因此已保存的 token 以未加密方式存储在此设备上应用的连接设置文件中。请安装或启用系统钥匙串(Linux 上为 GNOME Keyring 或 KWallet)以对其加密。',
keychainEncryptionTitle: '使用系统钥匙串加密已保存的机密',
keychainEncryptionDesc:
'默认关闭。开启后,网关 token 和登录凭据将使用系统钥匙串(Keychain Access、GNOME Keyring 或 Windows DPAPI)加密——系统可能会请求授权或密码。关闭时,它们以仅当前用户可读的普通文件形式存储。',