Skip to content

The agent that grows with you

fix(webapp): say the bot screen needs HTTPS instead of a raw digest error

David Dudok de Wit5c922cb947b0
diff --git a/apps/desktop/src/plugins/hermes-bots/i18n-messages.ts b/apps/desktop/src/plugins/hermes-bots/i18n-messages.ts
index 5be72bdd20e..bf253d0d877 100644
--- a/apps/desktop/src/plugins/hermes-bots/i18n-messages.ts
+++ b/apps/desktop/src/plugins/hermes-bots/i18n-messages.ts
@@ -386,6 +386,7 @@ export type BotsMessages = {
otherControls: string
agentControls: string
controlTaken: string
+ needsHttps: string
}
/** Bot-scoped scheduled jobs. Generic scheduling chrome (weekday names,
diff --git a/apps/desktop/src/plugins/hermes-bots/i18n.ts b/apps/desktop/src/plugins/hermes-bots/i18n.ts
index af1e008414b..2d54f9bc56b 100644
--- a/apps/desktop/src/plugins/hermes-bots/i18n.ts
+++ b/apps/desktop/src/plugins/hermes-bots/i18n.ts
@@ -410,7 +410,8 @@ const en: BotsMessages = {
youControl: 'You are in control',
otherControls: 'Another viewer is in control',
agentControls: 'Bot is in control',
- controlTaken: 'Another viewer took control. Watching only.'
+ controlTaken: 'Another viewer took control. Watching only.',
+ needsHttps: 'Bot screens need a secure connection. Open the Webapp over HTTPS, or through an SSH tunnel to 127.0.0.1, to view this one.'
},
cron: {
untitled: 'Untitled job',
@@ -855,7 +856,8 @@ const ja: BotsMessages = {
youControl: 'あなたが操作中',
otherControls: '別のビューアが操作中',
agentControls: 'ボットが操作中',
- controlTaken: '別のビューアが操作を引き継ぎました。閲覧のみ。'
+ controlTaken: '別のビューアが操作を引き継ぎました。閲覧のみ。',
+ needsHttps: 'ボットの画面には安全な接続が必要です。表示するには、Webapp を HTTPS か 127.0.0.1 への SSH トンネル経由で開いてください。'
},
cron: {
untitled: '無題のジョブ',
@@ -1283,7 +1285,8 @@ const zh: BotsMessages = {
youControl: '你正在控制',
otherControls: '另一位查看者正在控制',
agentControls: '机器人正在控制',
- controlTaken: '另一位查看者已接管控制。仅可观看。'
+ controlTaken: '另一位查看者已接管控制。仅可观看。',
+ needsHttps: '机器人屏幕需要安全连接。请通过 HTTPS 或到 127.0.0.1 的 SSH 隧道打开 Webapp 后查看。'
},
cron: {
untitled: '未命名任务',
@@ -1711,7 +1714,8 @@ const zhHant: BotsMessages = {
youControl: '你正在控制',
otherControls: '另一位檢視者正在控制',
agentControls: '機器人正在控制',
- controlTaken: '另一位檢視者已接手控制。僅可觀看。'
+ controlTaken: '另一位檢視者已接手控制。僅可觀看。',
+ needsHttps: '機器人螢幕需要安全連線。請透過 HTTPS 或到 127.0.0.1 的 SSH 通道開啟 Webapp 後檢視。'
},
cron: {
untitled: '未命名工作',
diff --git a/apps/desktop/src/plugins/hermes-bots/screen-pane.tsx b/apps/desktop/src/plugins/hermes-bots/screen-pane.tsx
index e51fa79732a..b156e0a544d 100644
--- a/apps/desktop/src/plugins/hermes-bots/screen-pane.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/screen-pane.tsx
@@ -78,6 +78,14 @@ async function loadRfb(): Promise<
) => RfbLike
}
+/** The viewer hashes its lease id with crypto.subtle and noVNC needs a secure context: over plain
+ * HTTP from another machine there is neither, so the pane says why instead of a stream. */
+function ScreenNeedsHttps({ label }: { label: string }) {
+ return globalThis.crypto?.subtle ? null : (
+ <div className="absolute inset-0 grid place-items-center p-6 text-center text-xs text-white/70">{label}</div>
+ )
+}
+
export function BotScreenPane({ bot }: { bot: RosterRow }) {
const t = useBots()
const screen = useValue($screenState)
@@ -183,6 +191,16 @@ export function BotScreenPane({ bot }: { bot: RosterRow }) {
}
detach()
+
+ // The viewer hashes its lease id with crypto.subtle, and noVNC needs a secure context too.
+ // A Webapp opened over plain HTTP from another machine has neither: never ask the bot for a
+ // viewer there (the pane says why) instead of failing on a missing digest afterwards.
+ if (!globalThis.crypto?.subtle) {
+ setConn('error')
+
+ return
+ }
+
const generation = attachGeneration.current
setConn('attaching')
setError(null)
@@ -563,6 +581,7 @@ export function BotScreenPane({ bot }: { bot: RosterRow }) {
{conn === 'error' && error ? (
<div className="absolute inset-x-0 bottom-0 bg-red-950/80 px-3 py-1.5 text-xs text-red-200">{error}</div>
) : null}
+ <ScreenNeedsHttps label={t.screen.needsHttps} />
</div>
</div>
)
diff --git a/apps/desktop/src/plugins/hermes-bots/screen-viewer-identity.test.tsx b/apps/desktop/src/plugins/hermes-bots/screen-viewer-identity.test.tsx
index 61787b59374..dbf68efb273 100644
--- a/apps/desktop/src/plugins/hermes-bots/screen-viewer-identity.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/screen-viewer-identity.test.tsx
@@ -43,7 +43,8 @@ vi.mock('./i18n', () => ({
handBackForceHint: 'Force',
takeOver: 'Take over',
reconnect: 'Reconnect',
- streamLost: 'Stream lost'
+ streamLost: 'Stream lost',
+ needsHttps: 'Needs HTTPS'
}
})
}))
@@ -175,3 +176,18 @@ it('does not offer Take over while no server-minted viewer id exists, even once
await waitFor(() => expect(view.getByText('Take over').closest('button')?.disabled).toBe(false))
view.unmount()
})
+
+it('says the screen needs HTTPS where an insecure origin has no crypto.subtle, before asking for a viewer', async () => {
+ Object.defineProperty(globalThis.crypto, 'subtle', { configurable: true, value: undefined })
+
+ try {
+ const view = render(<BotScreenPane bot={bot} />)
+ await waitFor(() => expect(vi.mocked(displayRequest)).toHaveBeenCalledWith(bot, 'display.status'))
+ await act(async () => {})
+ expect(view.getByText('Needs HTTPS')).toBeTruthy()
+ expect(vi.mocked(displayRequest)).not.toHaveBeenCalledWith(bot, 'display.observe', expect.anything())
+ view.unmount()
+ } finally {
+ Reflect.deleteProperty(globalThis.crypto, 'subtle')
+ }
+})