Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Keep data roots guarded inside the workspace and ask without a policy

Fei2411e72eee015c2e
diff --git a/ds-bot/src/host/folders.js b/ds-bot/src/host/folders.js
index f6130805..39dae7d0 100644
--- a/ds-bot/src/host/folders.js
+++ b/ds-bot/src/host/folders.js
@@ -57,22 +57,27 @@ export function install(rt) {
// A Bot that could write where DSH or the team keeps its data could change its own
// permissions or the team, so neither those folders nor one that holds them is allowed.
+ // The workspace exception covers only a workspace lying inside the data root (the
+ // plugin's default does): one that holds a data root does not open it up.
async function guarded(path) {
const team = await realTeam()
for (const root of dataRoots()) {
const data = await real(root)
if (within(data, path)) return true
- if (within(path, data) && !(team !== undefined && within(path, team))) return true
+ if (within(path, data) && !(team !== undefined && within(path, team) && within(team, data))) return true
}
return false
}
// A file a Bot names to read into the team, such as a photo, may not come from DSH's or
- // the team's data; the team workspace, which can lie in it, is the exception.
+ // the team's data; the team workspace, which can lie in it, is the exception, for the
+ // same reason as in guarded().
async function inData(path) {
const team = await realTeam()
- if (team !== undefined && within(path, team)) return false
- for (const root of dataRoots()) if (within(path, await real(root))) return true
+ for (const root of dataRoots()) {
+ const data = await real(root)
+ if (within(path, data) && !(team !== undefined && within(path, team) && within(team, data))) return true
+ }
return false
}
@@ -142,10 +147,14 @@ export function install(rt) {
async function approveFolder(exec, { path, sessions = [], who }) {
const team = await realTeam()
const policy = ctx.get?.('sandboxPolicy')
- if (path === undefined || (team !== undefined && within(path, team)) || policy === undefined) return
- const agents = await Promise.all(sessions.map(id => rt.resolveAgent(id)))
- const modes = [policy.resolve(), ...agents.map(agent => policy.resolve({ session: agent.session }))].map(entry => entry.mode)
- if (!modes.includes('workspace-write')) return
+ if (path === undefined || (team !== undefined && within(path, team))) return
+ if (policy !== undefined) {
+ const agents = await Promise.all(sessions.map(id => rt.resolveAgent(id)))
+ const modes = [policy.resolve(), ...agents.map(agent => policy.resolve({ session: agent.session }))].map(entry => entry.mode)
+ if (!modes.includes('workspace-write')) return
+ }
+ // With no policy service a Session's bounds cannot be checked, so a folder outside
+ // the workspace asks like a bounded one would; when nobody can be asked it throws.
const approval = ctx.get?.('approval')
const agent = exec.agent
if (approval === undefined || agent?.session === undefined) throw new Error(`Working in ${path} needs the user's approval, and there is no way to ask for it here, so nothing changed. The user can make this change in the settings.`)
diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.js
index b4360a88..6cd8a691 100644
--- a/ds-bot/test/work-dir.test.js
+++ b/ds-bot/test/work-dir.test.js
@@ -6,7 +6,7 @@ import { test } from 'node:test'
import { apply } from '../index.js'
import { dshHomeOf } from '../src/host/folders.js'
import { escapeRegExp } from '../src/host/text.js'
-import { fakeContext } from './fake-ctx.js'
+import { fakeApproval, fakeContext } from './fake-ctx.js'
// A Main Bot and a Bot, with the Bot in the group Ops through its group Session 'gb'.
const TEAM = {
@@ -30,9 +30,10 @@ const TEAM = {
// starts in the team workspace unless it is made with a cwd. `services` are what
// ctx.get finds, such as the sandbox policy and approvals.
// `locked`: another dsh holds the team, so this one only shows it.
-async function start({ services = {}, workspaces = [], llm, team: saved = TEAM, locked = false } = {}) {
+async function start({ services = {}, workspaces = [], llm, team: saved = TEAM, locked = false, root: rootDir } = {}) {
// The native realpath, as fs/promises uses: on Windows the JS one keeps 8.3 short names.
- const root = realpathSync.native(mkdtempSync(join(tmpdir(), 'ds-bot-work-dir-')))
+ const root = rootDir ?? realpathSync.native(mkdtempSync(join(tmpdir(), 'ds-bot-work-dir-')))
+ mkdirSync(root, { recursive: true })
const dsh = join(root, 'dsh')
const home = join(dsh, 'bot')
const team = join(home, 'workspace')
@@ -635,6 +636,47 @@ test('the team workspace holds no DeepSeek Harness data, apart from the plugin\'
assert.equal(state().workspaceId, 'w-new')
})
+// #508: older profiles, imports and DS_BOT_USER_DSH_HOME can leave a workspace that
+// contains a data root; the workspace exception must not open that root's folders.
+test('a team workspace that holds the data still keeps Bots out of it', async (t) => {
+ const root = realpathSync.native(mkdtempSync(join(tmpdir(), 'ds-bot-work-dir-')))
+ const { dsh, home, project, state, call, tool, stop } = await start({
+ rootDir: root,
+ workspaces: [{ id: 'w9', path: root, title: 'root' }],
+ team: { ...TEAM, workspaceId: 'w9' },
+ })
+ t.after(stop)
+ mkdirSync(join(dsh, 'profiles'))
+ const error = async workDir => (await call('update-bot', { id: 'b', workDir })).error?.message
+ for (const guarded of [dsh, join(dsh, 'profiles'), home, join(home, 'memory')]) {
+ mkdirSync(guarded, { recursive: true })
+ assert.equal(await error(guarded), `${guarded} holds DeepSeek Harness data, so Bots cannot work there`)
+ }
+ // An ordinary folder in the same workspace is still fine.
+ assert.equal((await call('update-bot', { id: 'b', workDir: project })).value.workDir, project)
+ assert.equal(state().bots.b.workDir, project)
+ // Nor can a photo be read out of the data root into the team.
+ writeFileSync(join(dsh, 'profiles', 'pic.png'), Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))
+ const pic = join(dsh, 'profiles', 'pic.png')
+ assert.equal(await tool('update_bot', { avatar: pic }, 'b'), `Could not update the Bot: ${pic} is in DeepSeek Harness data, so it cannot be a Bot's photo. Pass an image from another folder.`)
+})
+
+// #508: with no sandbox policy service a folder outside the workspace asked nobody.
+test('a folder outside the workspace asks for approval, or throws when nobody can be asked', async (t) => {
+ const first = await start()
+ t.after(first.stop)
+ assert.equal(await first.tool('update_bot', { work_dir: first.project }, 'b'),
+ `Could not update the Bot: Working in ${first.project} needs the user's approval, and there is no way to ask for it here, so nothing changed. The user can make this change in the settings.`)
+ assert.equal(first.state().bots.b.workDir, undefined)
+
+ const approval = fakeApproval()
+ const second = await start({ services: { approval } })
+ t.after(second.stop)
+ assert.equal(await second.tool('update_bot', { work_dir: second.project }, 'b'), `Updated Writer. From your next step on, you work in ${second.project}.`)
+ assert.equal(approval.requests.length, 1)
+ assert.equal(approval.requests[0].reason, `Let Writer work in ${second.project}? Files there can then be changed.`)
+})
+
test('a copied team shows its default team workspace before the workspace is registered', async (t) => {
const copied = { ...TEAM }
delete copied.workspaceId