A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Fail a locked cookie import instead of reading nothing
Fei2411592010d499dd
diff --git a/app/src/browser-sources.mjs b/app/src/browser-sources.mjsindex 6a0964b3..947004ad 100644--- a/app/src/browser-sources.mjs+++ b/app/src/browser-sources.mjs@@ -374,14 +374,43 @@ function harvestFirefox(workDir, now = Date.now() / 1000) {const withTimeout = (p, ms, label) => Promise.race([p, sleepMs(ms).then(() => { throw new Error(`${label} timed out`) })])const sleepMs = (ms) => new Promise((r) => setTimeout(r, ms))+/**+ * Rows a Chromium clone can never have its browser decrypt: app-bound (v20) values only+ * decrypt in the profile's real user-data dir — launched on a copy, the browser gets a+ * temporary key error and drops them silently. Names and domains stay plain text; only+ * the value is locked. → { locked: skipped entries, readable } or null when unreadable.+ */+export function appBoundRows(dbPath) {+ let db+ try { db = new DatabaseSync(dbPath, { readOnly: true }) } catch { return null }+ try {+ const rows = db.prepare('SELECT name, host_key AS domain, hex(substr(encrypted_value, 1, 3)) AS prefix FROM cookies').all()+ const locked = []+ let readable = 0+ rows.forEach((row, index) => {+ if (row.prefix === '763230') {+ locked.push({ where: `entry ${index + 1}`, name: row.name, domain: row.domain, code: 'app-bound', reason: 'locked by app-bound encryption — only the browser itself can read it' })+ } else readable += 1+ })+ return { locked, readable }+ } finally { db.close() }+}+/*** Cookies from one source profile. → { cookies, skipped } in the parser's normalized shape.- * Throws {code:'locked'} when the source holds its store open (Windows).+ * Throws {code:'locked'} when the source holds its store open (Windows), and+ * {code:'app-bound'} when every row is app-bound encrypted — there is nothing to harvest.*/export async function harvestCookies(source, workDir) {await cloneCookieStore(source, workDir)if (source.engine === 'firefox') return harvestFirefox(workDir)- return { cookies: await harvestChromium(source, workDir), skipped: [] }+ const census = appBoundRows(join(workDir, basename(source.profilePath), 'Network', 'Cookies'))+ if (census && census.readable === 0 && census.locked.length > 0) {+ const error = new Error(`${census.locked.length} cookies locked by app-bound encryption`)+ error.code = 'app-bound'+ throw error+ }+ return { cookies: await harvestChromium(source, workDir), skipped: census?.locked ?? [] }}/**diff --git a/app/src/main.mjs b/app/src/main.mjsindex 628f1a88..01b23662 100644--- a/app/src/main.mjs+++ b/app/src/main.mjs@@ -190,7 +190,13 @@ async function start() {assertWindow(event)const source = (await listSources()).find((item) => item.id === sourceId)if (!source) throw new Error('DeepSeek Bot: an unknown browser profile')- const outcome = await importFromBrowser(source, { close: close === true })+ let outcome+ try {+ outcome = await importFromBrowser(source, { close: close === true })+ } catch (error) {+ if (error?.code === 'app-bound') return { error: 'app-bound' }+ throw error+ }if (outcome.running) return { running: true, label: source.label, kind: source.kind }const result = {format: 'live', entries: outcome.result.cookies.length + outcome.result.skipped.length,diff --git a/app/test/browser-sources.test.mjs b/app/test/browser-sources.test.mjsindex 2f68473b..97aa3c49 100644--- a/app/test/browser-sources.test.mjs+++ b/app/test/browser-sources.test.mjs@@ -5,8 +5,9 @@ import { existsSync } from 'node:fs'import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'import { tmpdir } from 'node:os'import { join } from 'node:path'+import { DatabaseSync } from 'node:sqlite'import test from 'node:test'-import { chromiumProfiles, cloneCookieStore, cloneWorkDir, firefoxProfiles, locksProfile } from '../src/browser-sources.mjs'+import { appBoundRows, chromiumProfiles, cloneCookieStore, cloneWorkDir, firefoxProfiles, harvestCookies, locksProfile } from '../src/browser-sources.mjs'async function tempRoot() {const dir = await mkdtemp(join(tmpdir(), 'dsb-sources-test-'))@@ -95,6 +96,46 @@ test('cloneCookieStore for Firefox copies the sqlite family', async () => {} finally { await work.remove(); await root.remove() }})+async function cookieDb(dir, rows) {+ const db = new DatabaseSync(join(dir, 'Cookies'))+ db.exec('CREATE TABLE cookies (name TEXT, host_key TEXT, path TEXT, encrypted_value BLOB)')+ const insert = db.prepare('INSERT INTO cookies (name, host_key, path, encrypted_value) VALUES (?, ?, ?, ?)')+ for (const [name, host, blob] of rows) insert.run(name, host, '/', blob)+ db.close()+}++test('appBoundRows lists v20 rows by name and domain, and counts the rest readable', async () => {+ const root = await tempRoot()+ try {+ const net = join(root.dir, 'Default', 'Network')+ await mkdir(net, { recursive: true })+ await cookieDb(net, [+ ['sid', '.example.com', Buffer.concat([Buffer.from('v20'), Buffer.alloc(29)])],+ ['old', '.example.org', Buffer.concat([Buffer.from('v10'), Buffer.alloc(20)])],+ ])+ const census = appBoundRows(join(net, 'Cookies'))+ assert.equal(census.readable, 1)+ assert.equal(census.locked.length, 1)+ assert.equal(census.locked[0].name, 'sid')+ assert.equal(census.locked[0].domain, '.example.com')+ assert.equal(census.locked[0].code, 'app-bound')+ assert.equal(appBoundRows(join(root.dir, 'nowhere')), null)+ } finally { await root.remove() }+})++test('harvestCookies refuses an all-v20 clone: launching the browser would read nothing', async () => {+ const root = await tempRoot()+ const work = await cloneWorkDir()+ try {+ const net = join(root.dir, 'Default', 'Network')+ await mkdir(net, { recursive: true })+ await writeFile(join(root.dir, 'Local State'), '{}')+ await cookieDb(net, [['sid', '.example.com', Buffer.concat([Buffer.from('v20'), Buffer.alloc(29)])]])+ const source = { engine: 'chromium', profilePath: join(root.dir, 'Default'), cookieDb: join(net, 'Cookies') }+ await assert.rejects(() => harvestCookies(source, work.dir), (error) => error.code === 'app-bound')+ } finally { await work.remove(); await root.remove() }+})+test('locksProfile matches a browser process to the user-data root it locks', () => {const source = { profilePath: 'C:\\Users\\u\\AppData\\Local\\Google\\Chrome\\User Data\\Default' }assert.equal(locksProfile({ commandLine: '"C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"' }, source), true)diff --git a/docs/plans/2026-10-08-browser-and-secrets.md b/docs/plans/2026-10-08-browser-and-secrets.mdindex b55d2f35..f35511d5 100644--- a/docs/plans/2026-10-08-browser-and-secrets.md+++ b/docs/plans/2026-10-08-browser-and-secrets.md@@ -67,7 +67,7 @@ Bot 要替用户在网上做事,就会碰到两类东西:网页,以及登- 历史消息里的链接还不能直接在 Bot 浏览器里打开(#114)。- 关掉 `auto` 搜索以后,`web_search` 可能报错,恢复方法见 #128。- 用 opencode 路由时,原生搜索缺少 `x-opencode-session`(#184)。-- 导入 cookie 只在桌面应用里有(写进 Bot 自己的存储分区):cookie 文件(Cookie-Editor JSON、cookies.txt、Playwright storageState)和本机 Chrome/Edge/Firefox 的 profile。Chromium 系是先克隆 profile、再让原浏览器自己解密,不是直接读文件。localStorage 等其他登录状态不导。+- 导入 cookie 只在桌面应用里有(写进 Bot 自己的存储分区):cookie 文件(Cookie-Editor JSON、cookies.txt、Playwright storageState)和本机 Chrome/Edge/Firefox 的 profile。Chromium 系是先克隆 profile、再让原浏览器自己解密,不是直接读文件。Windows 上 Chrome/Edge 的新 cookie 用 app-bound 加密(v20),只在原 user-data 目录里能解:克隆目录解不开,这些条目会标成跳过;如果整库都是 v20 会直接提示走文件导入。localStorage 等其他登录状态不导。- 密钥只防泄露到模型、记录和其他 Bot 的 shell。有权限的 Bot 在自己的 shell 里能用到值,所以给哪些 Bot 开放,要由用户判断。## 变更diff --git a/ds-bot/client.js b/ds-bot/client.jsindex be78a14a..12ad7fa9 100644--- a/ds-bot/client.js+++ b/ds-bot/client.js@@ -299,6 +299,7 @@ var ZH = {"Import failed": "导入失败","That file is too large to be a cookie export.": "这个文件太大了,不像是 cookie 导出文件。","That file could not be read.": "这个文件读不了。",+ "This browser encrypts its cookies so only it can read them. Export them to a file first, then import that file.": "这个浏览器把 cookie 加密了,只有它自己能读。先把 cookie 导出成文件,再导入那个文件。","{count}": "{count} 个",// Bot settings"Choose a PNG, JPEG, WebP, or GIF image": "请选择 PNG、JPEG、WebP 或 GIF 图片",@@ -16297,6 +16298,7 @@ function BrowserView({ bot, tabId, leaving, landed, actions, useBrowserPages })function importError(error) {if (error === "too-large") return t("That file is too large to be a cookie export.");if (error === "unreadable") return t("That file could not be read.");+ if (error === "app-bound") return t("This browser encrypts its cookies so only it can read them. Export them to a file first, then import that file.");return String(error);}function ImportMenu({ sources, busy, onFile, onSource, onClose }) {diff --git a/ds-bot/src/client/browser-pane.js b/ds-bot/src/client/browser-pane.jsindex 9d2f4590..ae51c602 100644--- a/ds-bot/src/client/browser-pane.js+++ b/ds-bot/src/client/browser-pane.js@@ -358,6 +358,7 @@ function BrowserView({ bot, tabId, leaving, landed, actions, useBrowserPages })function importError(error) {if (error === 'too-large') return t('That file is too large to be a cookie export.')if (error === 'unreadable') return t('That file could not be read.')+ if (error === 'app-bound') return t('This browser encrypts its cookies so only it can read them. Export them to a file first, then import that file.')return String(error)}diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.jsindex 03c5edc7..5556cdf1 100644--- a/ds-bot/src/client/i18n.js+++ b/ds-bot/src/client/i18n.js@@ -267,6 +267,7 @@ const ZH = {'Import failed': '导入失败','That file is too large to be a cookie export.': '这个文件太大了,不像是 cookie 导出文件。','That file could not be read.': '这个文件读不了。',+ 'This browser encrypts its cookies so only it can read them. Export them to a file first, then import that file.': '这个浏览器把 cookie 加密了,只有它自己能读。先把 cookie 导出成文件,再导入那个文件。','{count}': '{count} 个',// Bot settings