Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Merge batch 11-02 1102-s: #2568 (#2599)

0xken157f14a2817a52
diff --git a/cli/src/superTabs/inCore/teamPurge.spec.ts b/cli/src/superTabs/inCore/teamPurge.spec.ts
index 765ce4187..d421334bc 100644
--- a/cli/src/superTabs/inCore/teamPurge.spec.ts
+++ b/cli/src/superTabs/inCore/teamPurge.spec.ts
@@ -5,7 +5,7 @@ import { dirname, join, win32 } from 'node:path'
import { PM_HOMES } from '../teamDaemon.js'
import { describe, expect, it, vi } from 'vitest'
import { createSwarmAgents } from './agents.js'
-import { OWN_LEFT, SHARED_LEFT, SWEEP_LEFT, UNREADABLE_DETAIL, createConfidentialPurge, ownHomeFolder, purgeRecord, recordsOtherFolder, rewriteIfUnchanged, scrubClaudeSession, sweepForSession, type PurgeTarget } from './teamPurge.js'
+import { OWN_LEFT, SHARED_LEFT, SWEEP_LEFT, UNREADABLE_DETAIL, createConfidentialPurge, isPmCodexHome, ownHomeFolder, purgeRecord, recordsOtherFolder, rewriteIfUnchanged, scrubClaudeSession, sweepForSession, type PurgeTarget } from './teamPurge.js'
/** A folder that goes between the sweep's listing of its parent and its own read: removed just before that read. */
const vanish = vi.hoisted(() => ({ path: '' }))
@@ -526,6 +526,31 @@ describe('the purge of a confidential session the Swarm ended', () => {
expect(ownHomeFolder('/Users/team/.harness-pm-homes', null)).toBeNull()
})
+ // Windows drops a name's trailing spaces and dots: `.. ` is `..`, and this path's folder is then the whole Team home, which
+ // purge deletes. The rule pmEngineHome names a home by (teamDaemon.ts PM_START_ID), as isPmCodexHome holds it to (#2568).
+ it('takes only a start id pmEngineHome could have made: never `.. `, nor a name Windows would cut, nor a separator inside it', () => {
+ const win = 'C:\\Users\\team\\.harness-pm-homes', posix = '/Users/team/.harness-pm-homes'
+ for (const id of ['.. ', '. ', '.', '..', 'super-start.', 'super-start ', 'a b', 'a.b', '..\u00a0', 'caf\u00e9', 'x'.repeat(161)]) {
+ expect(ownHomeFolder(win, `${win}\\${id}\\codex`), `win ${id}`).toBeNull()
+ expect(ownHomeFolder(posix, `${posix}/${id}/codex`), `posix ${id}`).toBeNull()
+ }
+ for (const path of [`${win}\\a\\b\\codex`, `${win}/.. /codex`, `${win}\\.. /codex`, `${win}/..\\codex`]) expect(ownHomeFolder(win, path), path).toBeNull()
+ expect(ownHomeFolder(posix, `${posix}/a\\b/codex`)).toBeNull()
+ expect(ownHomeFolder(win, `${win}\\super-start_1\\codex`)).toBe(`${win}\\super-start_1`)
+ expect(ownHomeFolder(win, `${win}/super-start_1/codex`)).toBe(`${win}/super-start_1`)
+ expect(ownHomeFolder(posix, `${posix}/${'x'.repeat(160)}/codex`)).toBe(`${posix}/${'x'.repeat(160)}`)
+ })
+
+ it('a session\'s `.. ` home is left alone, the Team home with it, confidential or not', async () => {
+ const { home } = teamHome()
+ const s = service(home)
+ writeFileSync(join(home, 'keep.txt'), 'kept')
+ const purge = createConfidentialPurge({ confidential: () => false, home, record: purgeRecord(join(dir(), 'purges.json')), purge: s.purge,
+ session: () => ({ agentId: 'r', sessionId: 's', registeredAt: 1, engine: 'codex', cwd: CWD, codexHome: join(home, PM_HOMES, '.. ', 'codex') }) })
+ expect(await purge('r')).toEqual({ skipped: true })
+ expect(readFileSync(join(home, 'keep.txt'), 'utf8')).toBe('kept')
+ })
+
it('removes Team-written work\'s own Codex home when the agent ends, confidential or not, and nothing else (audit H2)', async () => {
const { home } = teamHome()
const s = service(home), own = join(home, PM_HOMES, 'super-start', 'codex'), other = join(home, 'elsewhere', 'codex')
@@ -626,6 +651,16 @@ describe('the purge of a confidential session the Swarm ended', () => {
expect(existsSync(join(home, '.harness-pm-homes', 'super-start-1'))).toBe(false)
})
+ it('of a Codex session whose home is not one of pmEngineHome\'s, leaves every Product Manager\'s home', async () => {
+ // One level under the PM homes folder, its parent is that folder: a purge of it took every other PM's home with it.
+ const home = dir(), other = join(home, '.harness-pm-homes', 'super-start-2', 'codex')
+ mkdirSync(other, { recursive: true })
+ const s = service(home, join(home, '.harness-pm-homes', 'codex'))
+ const ended = createConfidentialPurge({ confidential: () => true, home, session: s.session, purge: s.purge, record: s.record })
+ expect(await ended('pm')).toEqual({ ok: true })
+ expect(existsSync(other)).toBe(true)
+ })
+
it('leaves any other session alone; a refused review or delete stops it, the session kept in its record', async () => {
const home = dir()
const record = purgeRecord(join(home, 'super-tabs', 'team-purges.json'))
@@ -748,6 +783,26 @@ describe('the record of purges still to finish', () => {
})
})
+// Windows audit (task #2022): the check looked for `${homes}/`, and Windows' paths have `\`, so a purged Codex Product
+// Manager's own home stayed in the Team account for its next agent to read.
+describe('isPmCodexHome', () => {
+ it('is the home pmEngineHome makes, by Windows\' separators as well as this platform\'s', () => {
+ expect(isPmCodexHome('C:\\Users\\harnessteam', 'C:\\Users\\harnessteam\\.harness-pm-homes\\super-start-1\\codex', win32)).toBe(true)
+ expect(isPmCodexHome('/Users/harnessteam', '/Users/harnessteam/.harness-pm-homes/super-start-1/codex')).toBe(true)
+ })
+
+ it('is nothing else: not the PM homes folder or one level under it, a sibling folder, a way out, or another home', () => {
+ const home = 'C:\\Users\\harnessteam', homes = `${home}\\.harness-pm-homes`
+ for (const codexHome of [homes, `${homes}\\codex`, `${homes}\\super-start-1`, `${homes}\\super-start-1\\codex\\sessions`,
+ `${homes}\\super-start-1\\other`, `${home}\\.harness-pm-homes-old\\super-start-1\\codex`, `${homes}\\..\\x\\codex`,
+ // Windows drops a name's trailing spaces and dots: `.. ` is `..`, and purge deletes the parent, the whole Team home.
+ `${homes}\\.. \\codex`, `${homes}\\. \\codex`, `${homes}\\super-start-1.\\codex`, `${homes}\\a b\\codex`,
+ 'C:\\Users\\owner\\.harness-pm-homes\\super-start-1\\codex', 'D:\\.harness-pm-homes\\super-start-1\\codex', '']) {
+ expect(isPmCodexHome(home, codexHome, win32), codexHome).toBe(false)
+ }
+ })
+})
+
// Windows audit W3 (task #2096): `folderOf` wanted a leading '/', so a Windows worktree had no folder, and the sweep then held the
// account at every retry, with its memory unread. The folder's forms are what Claude Code 2.1.316 writes on Windows: `C:/...` as a
// config key (its `U3`), `C:\\...` elsewhere, and `C--...` as the project folder's name.
diff --git a/cli/src/superTabs/inCore/teamPurge.ts b/cli/src/superTabs/inCore/teamPurge.ts
index add532915..10f31087b 100644
--- a/cli/src/superTabs/inCore/teamPurge.ts
+++ b/cli/src/superTabs/inCore/teamPurge.ts
@@ -16,9 +16,9 @@
import { buddyTmpFolder, realOfFolder } from '../../lib/agentTmp.js'
import { createReadStream, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync, type Dirent } from 'node:fs'
import { readdir, readFile, rename, rm, stat, unlink, writeFile } from 'node:fs/promises'
-import nodePath, { basename, dirname, join, type PlatformPath } from 'node:path'
+import nodePath, { basename, dirname, isAbsolute, join, relative, sep, type PlatformPath } from 'node:path'
import { createInterface } from 'node:readline'
-import { PM_HOMES } from '../teamDaemon.js'
+import { PM_HOMES, PM_START_ID } from '../teamDaemon.js'
/** What a purge needs of a session, kept until it finishes. `pastes`: the paste cache files its history lines kept. */
export interface PurgeTarget {
@@ -99,6 +99,23 @@ export type ScrubTold = 'shared' | 'unread' | 'unreadTodos' | 'unreadBackups'
* folder in the backups (re-check of 8c0b019). The error itself is dropped, as its message names the path. */
const listed = (dir: string) => readdir(dir).catch((error: NodeJS.ErrnoException) => error.code === 'ENOENT' ? [] as string[] : null)
+/**
+ * Whether [codexHome] is a Product Manager's own Codex home in the Team user's [home], `<home>/.harness-pm-homes/<id>/codex`
+ * as superTabs/teamDaemon.ts pmEngineHome makes it, by [paths]' own rules: purge deletes its parent whole. A check for
+ * `${homes}/` never matched Windows' `\`, so a purged Codex PM's home stayed for the account's next agent to read, and it took
+ * a home one level under the PM homes folder, whose parent is every PM's homes (Windows audit, task #2022).
+ */
+export function isPmCodexHome(home: string, codexHome: string, paths: Pick<PlatformPath, 'join' | 'relative' | 'isAbsolute' | 'sep'> =
+ { join, relative, isAbsolute, sep }): boolean {
+ if (!codexHome) return false
+ const inside = paths.relative(paths.join(home, PM_HOMES), codexHome)
+ if (paths.isAbsolute(inside)) return false
+ const [id, last, ...more] = inside.split(paths.sep)
+ // pmEngineHome's own rule for the id: `.. ` passed a check for `..`, and Windows reads it as `..`, the whole Team home
+ // (security review 1 of #2568).
+ return !!id && PM_START_ID.test(id) && last === 'codex' && more.length === 0
+}
+
/** Claude Code's folder name for a project folder: every character but a letter or digit made a dash. */
const claudeSlug = (cwd: string) => cwd.replace(/[^A-Za-z0-9]/g, '-')
const SESSION = /^[A-Za-z0-9_-]{1,160}$/
@@ -444,7 +461,8 @@ export const UNREADABLE_DETAIL = "This machine's record of purges still to finis
export function ownHomeFolder(homes: string, codexHome: string | null | undefined): string | null {
if (!codexHome || !codexHome.startsWith(homes)) return null
const [first, creation, name, ...rest] = codexHome.slice(homes.length).split(/[\\/]/)
- if (first !== '' || !creation || creation === '.' || creation === '..' || name !== 'codex' || rest.length) return null
+ // pmEngineHome's own rule for the id: `.. ` passed a check for `..`, and Windows reads it as `..`, the whole Team home (#2568).
+ if (first !== '' || !creation || !PM_START_ID.test(creation) || name !== 'codex' || rest.length) return null
return codexHome.slice(0, homes.length + 1 + creation.length)
}
@@ -487,8 +505,7 @@ export function createConfidentialPurge(deps: {
const deleted = await deps.purge({ ...reference, mode: 'delete', reviewId: review.reviewId, choices: { sessionData: true, worktreeData: false } })
if (typeof deleted.error === 'string') return deleted
}
- const homes = join(deps.home, PM_HOMES)
- if (target.codexHome && target.codexHome.startsWith(`${homes}/`)) await rm(dirname(target.codexHome), { recursive: true, force: true })
+ if (target.codexHome && isPmCodexHome(deps.home, target.codexHome)) await rm(dirname(target.codexHome), { recursive: true, force: true })
if (target.engine === 'claude') {
const keep = (found: readonly string[]) => {
const pastes = [...new Set([...target!.pastes ?? [], ...found])]
diff --git a/cli/src/superTabs/teamDaemon.ts b/cli/src/superTabs/teamDaemon.ts
index c6d4c155f..4d6649681 100644
--- a/cli/src/superTabs/teamDaemon.ts
+++ b/cli/src/superTabs/teamDaemon.ts
@@ -26,11 +26,14 @@ export function isTeamDaemon(deps: { configExists?: () => boolean; config?: () =
/** Where a Team daemon runs each Codex Product Manager in an engine home of its own, deleted whole when the Swarm ends it. */
export const PM_HOMES = '.harness-pm-homes'
+/** A start's id as it may name its PM home: letters, digits, `_` and `-` only, so never `..`, nor a name Windows would cut a
+ * trailing space or dot off (inCore/teamPurge.ts isPmCodexHome). */
+export const PM_START_ID = /^[A-Za-z0-9_-]{1,160}$/
/** The engine home a Product Manager's start [creationId] runs in on a Team daemon: its own, for Codex (security re-check 2
* of #2089, the Lead's option A). Null for Claude Code, whose transcripts core reads only from the shared home (its files
* are scrubbed instead, inCore/teamApps.ts scrubClaudeSession), and anywhere but a Team daemon. */
export function pmEngineHome(engine: string, creationId: string, team: boolean, home: string): string | null {
- if (!team || engine !== 'codex' || !/^[A-Za-z0-9_-]{1,160}$/.test(creationId)) return null
+ if (!team || engine !== 'codex' || !PM_START_ID.test(creationId)) return null
return join(home, PM_HOMES, creationId, 'codex')
}
diff --git a/cli/src/team/windowsBoundary.spec.ts b/cli/src/team/windowsBoundary.spec.ts
new file mode 100644
index 000000000..a0742fce4
--- /dev/null
+++ b/cli/src/team/windowsBoundary.spec.ts
@@ -0,0 +1,137 @@
+/**
+ * The Windows boundary of the Harness Team account, as far as it can be checked without Windows (security pass of task #2022,
+ * docs/security/2026-11-02-team-account-windows.md). Nothing here creates a user, changes an ACL or opens a port.
+ *
+ * - What each account may do in the folders the elevated setup script makes, read from the security descriptors it writes
+ * and decoded bit by bit: the team account adds nothing to the sign-in handover folder and cannot remove it, and no other
+ * account reads the code or the relay's token.
+ * - The owner's local credential over TCP on Windows, pinned as it is today (finding W1, still open): closing it turns these red.
+ */
+import { mkdtempSync } from 'node:fs'
+import type { Socket } from 'node:net'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { describe, expect, it } from 'vitest'
+import { loadOrCreateHookCredential } from '../lib/hookAuth.js'
+import { LOCAL_CREDENTIAL_HEADER, localCredentialHeaders } from '../lib/localCredential.js'
+import { peerIsThisAccount } from '../lib/peerAccount.js'
+import { buildWindowsSetupScript, type WindowsSetupScriptInput } from './windowsScript.js'
+
+const OWNER_HOME = 'C:\\Users\\owner-placeholder'
+const NODE_DIR = `${OWNER_HOME}\\.harness\\runtime\\node-v22.23.2-win32-x64`
+const input: WindowsSetupScriptInput = {
+ user: 'harnessteam', realName: 'Harness Team', home: 'C:\\Users\\harnessteam', owner: 'owner-placeholder', ownerHome: OWNER_HOME,
+ ownerSid: 'S-1-5-21-1111111111-2222222222-3333333333-1001', stageDir: `${OWNER_HOME}\\AppData\\Local\\Temp\\harness-team-x1`,
+ nodeRuntimeDir: NODE_DIR, tmuxRuntimeDir: null, cliDir: `${OWNER_HOME}\\.harness\\cli\\0.4.97`, ownerNode: `${NODE_DIR}\\node.exe`,
+ ownerCli: `${OWNER_HOME}\\.harness\\cli\\0.4.97\\cli.js`, mintEnv: {}, signIn: 'missing',
+}
+const script = buildWindowsSetupScript(input)
+
+// File and folder rights, as an access mask holds them (winnt.h).
+const RIGHT = {
+ readOrList: 0x1, writeOrAddFile: 0x2, appendOrAddFolder: 0x4, writeEa: 0x10, deleteChild: 0x40, writeAttributes: 0x100,
+ delete: 0x10000, writeDac: 0x40000, writeOwner: 0x80000, genericAll: 0x10000000, genericWrite: 0x40000000,
+} as const
+/** Every right that changes a folder, a file in it, or who may: what "read only" must hold none of. */
+const CHANGES = RIGHT.writeOrAddFile | RIGHT.appendOrAddFolder | RIGHT.writeEa | RIGHT.deleteChild | RIGHT.writeAttributes
+ | RIGHT.delete | RIGHT.writeDac | RIGHT.writeOwner | RIGHT.genericAll | RIGHT.genericWrite
+const FULL = 0x1f01ff
+
+/** A mask as the script writes one: `FA`, or a number in hex. Any other name throws rather than read as no rights. */
+function maskOf(mask: string): number {
+ if (mask === 'FA') return FULL
+ if (/^0x[0-9a-f]{1,8}$/i.test(mask)) return Number(mask)
+ throw new Error(`a mask this decoder cannot read: ${mask}`)
+}
+
+interface Ace { sid: string; mask: number; onFolder: boolean; onChildren: boolean }
+
+/** The allow ACEs of an SDDL string, whether its DACL is protected, and each ACE's mask and where it applies. */
+function dacl(sddl: string): { protected: boolean; aces: Ace[] } {
+ const body = /D:([A-Z]*)((?:\([^)]*\))*)/.exec(sddl)
+ if (!body) throw new Error(`no DACL in ${sddl}`)
+ const aces = [...body[2]!.matchAll(/\(([^)]*)\)/g)].map((match) => {
+ const [type, flags, mask, , , sid] = match[1]!.split(';')
+ if (type !== 'A') throw new Error(`not an allow ACE: ${match[0]}`)
+ const inherits = /OI|CI/.test(flags!)
+ return { sid: sid!, mask: maskOf(mask!), onFolder: !flags!.includes('IO'), onChildren: inherits }
+ })
+ return { protected: body[1]!.includes('P'), aces }
+}
+
+/** The SDDL the script gives a folder, by the line that makes it. */
+function sddlOf(line: RegExp): string {
+ const found = line.exec(script)
+ if (!found) throw new Error(`the setup script has no ${line}`)
+ return found[1]!
+}
+
+const OWNER = '$OWNER_SID', TEAM = '$teamSid', SYSTEM = 'SY', ADMINS = 'BA'
+/** Each account named, so none other can come in unseen: Users, Authenticated Users, Everyone. */
+const ONLY = (aces: Ace[]) => [...new Set(aces.map((ace) => ace.sid))].sort()
+const rights = (aces: Ace[], sid: string, where: 'folder' | 'children'): number =>
+ aces.filter((ace) => ace.sid === sid && (where === 'folder' ? ace.onFolder : ace.onChildren)).reduce((all, ace) => all | ace.mask, 0)
+
+describe('the decoder these tests read the ACLs with', () => {
+ // Number('GW') is NaN, and NaN & anything is 0: a named mask read as no rights at all (security review 1 of #2568).
+ it('refuses a mask it cannot read, and counts generic write and generic all as changes', () => {
+ for (const named of ['GW', 'GA', 'FW', 'RC']) expect(() => dacl(`D:P(A;;${named};;;BU)`), named).toThrow()
+ for (const generic of ['0x40000000', '0x10000000']) expect(dacl(`D:P(A;;${generic};;;BU)`).aces[0]!.mask & CHANGES, generic).not.toBe(0)
+ })
+})
+
+describe('the folders the Windows setup script makes, by what each account may do there', () => {
+ it('the sign-in handover: the owner adds the code, the team account reads and deletes it, nobody else sees it', () => {
+ const { protected: closed, aces } = dacl(sddlOf(/Set-Folder \$HANDOFF_DIR "([^"]+)"/))
+ // Protected: the status folder's Users read is not inherited, so no other account reads a code in its 90 seconds.
+ expect(closed).toBe(true)
+ expect(ONLY(aces)).toEqual([OWNER, TEAM, ADMINS, SYSTEM].sort())
+ expect(rights(aces, OWNER, 'folder') & RIGHT.writeOrAddFile).toBe(RIGHT.writeOrAddFile)
+ // The team account adds no file or folder (no planted code, link or junction) and cannot remove, rename or re-ACL it.
+ expect(rights(aces, TEAM, 'folder') & CHANGES).toBe(0)
+ // On the code: read it, delete it (with write-attributes, which Node's unlink needs), never change what it says.
+ expect(rights(aces, TEAM, 'children') & (RIGHT.writeOrAddFile | RIGHT.appendOrAddFolder | RIGHT.writeDac | RIGHT.writeOwner)).toBe(0)
+ expect(rights(aces, TEAM, 'children') & (RIGHT.readOrList | RIGHT.delete)).toBe(RIGHT.readOrList | RIGHT.delete)
+ })
+
+ it('the status folder: the team account writes its status, but cannot delete what it did not make, nor change who may', () => {
+ const { protected: closed, aces } = dacl(sddlOf(/Set-Folder \$STATUS_DIR "([^"]+)"/))
+ expect(closed).toBe(true)
+ expect(ONLY(aces)).toEqual([TEAM, ADMINS, SYSTEM, 'BU'].sort())
+ // No delete-child: the handover folder setup made in it stays, whatever the team account does.
+ expect(rights(aces, TEAM, 'folder') & (RIGHT.deleteChild | RIGHT.writeDac | RIGHT.writeOwner)).toBe(0)
+ // Every account reads the status (the owner's `harness team status`), and changes nothing in it.
+ expect(rights(aces, 'BU', 'folder') & CHANGES).toBe(0)
+ expect(rights(aces, 'BU', 'children') & CHANGES).toBe(0)
+ })
+
+ it('the relay folder: the owner\'s, the team account reads the grant, nobody else is named', () => {
+ const { protected: closed, aces } = dacl(sddlOf(/SetSecurityDescriptorSddlForm\("(D:P[^"]+)", 'Access'\)/))
+ expect(closed).toBe(true)
+ expect(ONLY(aces)).toEqual([OWNER, TEAM, ADMINS, SYSTEM].sort())
+ expect(rights(aces, TEAM, 'folder') & CHANGES).toBe(0)
+ expect(rights(aces, TEAM, 'children') & CHANGES).toBe(0)
+ })
+
+ it('the shared folder and this run\'s stage: Administrators\' and SYSTEM\'s, read by the rest', () => {
+ for (const line of [/Set-Folder \$SHARED "([^"]+)"/, /\$RT = New-Stage "([^"]+)"/]) {
+ const { protected: closed, aces } = dacl(sddlOf(line))
+ expect(closed, String(line)).toBe(true)
+ for (const ace of aces.filter((a) => a.sid !== ADMINS && a.sid !== SYSTEM)) expect(ace.mask & CHANGES, `${line} ${ace.sid}`).toBe(0)
+ }
+ })
+})
+
+describe('W1, still open: the owner\'s local credential over TCP on Windows', () => {
+ it('a client puts the credential on a loopback TCP request, where macOS and Linux send none', () => {
+ const data = mkdtempSync(join(tmpdir(), 'team-win-boundary-'))
+ loadOrCreateHookCredential(data)
+ expect(localCredentialHeaders(data, 'darwin')).toEqual({})
+ expect(Object.keys(localCredentialHeaders(data, 'win32'))).toEqual([LOCAL_CREDENTIAL_HEADER])
+ })
+
+ it('the daemon counts it from any account: Windows answers yes without asking who is calling', async () => {
+ const stranger = { remoteAddress: '127.0.0.1', remotePort: 50_001, localAddress: '127.0.0.1', localPort: 18473 } as Socket
+ await expect(peerIsThisAccount(stranger, 'win32')).resolves.toBe(true)
+ })
+})
diff --git a/docs/plans/2026-11-02-team-account-windows-audit-plan.md b/docs/plans/2026-11-02-team-account-windows-audit-plan.md
new file mode 100644
index 000000000..e9053ee8a
--- /dev/null
+++ b/docs/plans/2026-11-02-team-account-windows-audit-plan.md
@@ -0,0 +1,88 @@
+# Team Account on Windows: Security Pass Implementation Plan
+
+> **For agentic workers:** steps use checkbox (`- [ ]`) syntax. Written by the writing-plans skill, as the project's
+> instructions ask.
+
+**Goal:** Do for Windows what task #2009 did for macOS: say, with evidence, whether an agent in the Harness Team account
+can reach the owner's files, credential or data, across the OS user, the closed profile, the shared folders, local ports
+and pipes, the relay and purge. Pin what holds with tests that run on a Mac, fix what is small and clear, and ask the PM
+for a fix for each other hole.
+
+**Architecture:** One rated report in `docs/security/`. One spec pins the Windows boundaries that can be checked without
+Windows: the ACLs the setup script writes, decoded from its SDDL, and the TCP credential path as it is today. One fix,
+test first: purge's check of a Codex Product Manager's home, which looked for `/` and so never matched a Windows path.
+
+**Tech Stack:** TypeScript, Vitest.
+
+**Spec:** Task #2022's brief (conversation `a9607b4bd17934653c9df04e`), and the macOS audit
+`docs/security/2026-11-02-team-account-boundary.md`.
+
+## Global Constraints
+
+- Read-only on real machines: no real account, permission or file of another session is changed; fixtures in this
+ task's own folders only. No Windows machine is used: what needs one is said as not verified.
+- Never run a test that signs this Mac out of the real CLI. Stop only processes this task started, by id.
+- Never print or post a secret.
+- Two independent security reviews before merge (Quinn 2 and Luna): the fix touches code that deletes data.
+
+## Review Focus
+
+- A purge path check that matches too much: a Codex home one level under the PM homes folder would make purge delete
+ every PM's home; a sibling folder whose name starts with `.harness-pm-homes` must not match.
+- A check that holds on POSIX and not on Windows: every new path test runs with `path.win32` as well as the platform's.
+- An SDDL test that reads the wrong ACE: masks are decoded by bit, and the folder's own ACE is told apart from the
+ inherit-only one.
+- A test that pins an open hole as if it held: the open ones are named "still open" and turn red when fixed.
+- A finding rated from code alone said as seen: each one says whether it was read in code, tested here, or seen.
+
+---
+
+### Task 1: Read every Windows path in scope
+
+**Files:** none changed.
+
+- [x] **Step 1:** Read setup, the task, removal and the team side (`cli/src/team/windowsScript.ts`, `windowsTeam.ts`,
+ `windowsLayout.ts`, and their callers in `command.ts`, `deps.ts`, `privacy.ts`, `relay.ts`, `admin.ts`).
+- [x] **Step 2:** Read the Windows local transports: `hook/notify.mjs` `hookRoute`, `lib/localCredential.ts`,
+ `lib/peerAccount.ts`, `hookServer.ts`, `lib/windows/pipeAuth.ts`.
+- [x] **Step 3:** Read purge for Windows paths: `superTabs/inCore/teamPurge.ts`, `superTabs/teamDaemon.ts` `pmEngineHome`.
+
+### Task 2: Purge deletes a Codex Product Manager's home on Windows
+
+**Files:**
+- Modify: `cli/src/superTabs/inCore/teamPurge.ts` (the check before `rm(dirname(target.codexHome))`)
+- Test: `cli/src/superTabs/inCore/teamPurge.spec.ts`
+
+**Interfaces:**
+- Produces: `isPmCodexHome(home: string, codexHome: string, paths?: Pick<PlatformPath, 'join' | 'relative' | 'isAbsolute' | 'sep'>): boolean`,
+ true only for `<home>\.harness-pm-homes\<id>\codex` by `paths`' own rules (the platform's by default).
+
+- [x] **Step 1: Write the failing tests:** with `win32`, the home `pmEngineHome` makes on Windows is one; with the
+ platform's path, the same; a home one level under the PM homes folder, a sibling folder's, `..` and another home are not.
+ And the purge of a session whose Codex home is one level under the PM homes folder leaves the other PMs' homes.
+- [x] **Step 2: Run them:** `npx vitest run src/superTabs/inCore/teamPurge.spec.ts`. Expected: FAIL.
+- [x] **Step 3: Implement** `isPmCodexHome` by `relative` from the PM homes folder: two parts, the second `codex`.
+ Use it in `createConfidentialPurge`.
+- [x] **Step 4: Run them again.** Expected: PASS. Red evidence: put the old `startsWith(\`${homes}/\`)` back in the
+ helper and run; the Windows assertion fails.
+
+### Task 3: Windows boundary spec
+
+**Files:**
+- Create: `cli/src/team/windowsBoundary.spec.ts`
+
+- [x] **Step 1: Write the spec:** decode the SDDL the setup script writes for the handover, status, relay, stage and
+ shared folders, and check by bit what each account may do; pin the TCP credential on Windows as it is (still open).
+- [x] **Step 2: Run it:** `npx vitest run src/team/windowsBoundary.spec.ts`. Expected: PASS.
+- [x] **Step 3: Red evidence:** give the team account add-file on the handover folder, or Users read on it, in
+ `windowsScript.ts`; the spec fails on that line. Put it back.
+
+### Task 4: Findings, fix requests, pull request
+
+**Files:**
+- Create: `docs/security/2026-11-02-team-account-windows.md`
+
+- [x] **Step 1:** Write each finding: rating, evidence by file and line, how it was found, what fixes it; then what holds.
+- [x] **Step 2:** Run the Team and purge specs and the typecheck.
+- [ ] **Step 3:** Open the pull request with its "Requested by" line, the checklist and red/green evidence.
+- [ ] **Step 4:** Send one fix request per open hole to the PM; add two review steps (Quinn 2, Luna) and message them.
diff --git a/docs/security/2026-11-02-team-account-boundary.md b/docs/security/2026-11-02-team-account-boundary.md
index be09650ea..5b01c0185 100644
--- a/docs/security/2026-11-02-team-account-boundary.md
+++ b/docs/security/2026-11-02-team-account-boundary.md
@@ -231,6 +231,6 @@ so in the agents' role text, and bind test services to a socket in a private fol
setup's mode means mode 000: they show only that 000 refuses. What guards the home there is the test that no line of the script
leaves a group or other bit, or changes the home a second time. As a real second account (`nobody`) they run only on CI's Linux,
where the spec fails if that account is missing. ACLs are not modeled.
-- **Windows was skimmed only:** `windowsTeam.ts` and `windowsScript.ts` were not audited. Its setup and rules differ.
+- **Windows was skimmed only:** `windowsTeam.ts` and `windowsScript.ts` were not audited here. Task #2022 did: [2026-11-02-team-account-windows.md](2026-11-02-team-account-windows.md).
- Linux's scripts were read and their modes tested; setup was not run on a Linux machine.
- The integration suite was not run: this change touches no backend code.
diff --git a/docs/security/2026-11-02-team-account-windows.md b/docs/security/2026-11-02-team-account-windows.md
new file mode 100644
index 000000000..65a225684
--- /dev/null
+++ b/docs/security/2026-11-02-team-account-windows.md
@@ -0,0 +1,182 @@
+# Harness Team account on Windows: can its agents reach the owner's files?
+
+Security pass of 2026-11-02 (task #2022), at `origin/main` 29795af79. It covers what the macOS audit
+([2026-11-02-team-account-boundary.md](2026-11-02-team-account-boundary.md), task #2009) left out: `cli/src/team/windowsTeam.ts`,
+`windowsScript.ts`, `windowsLayout.ts`, and what they rely on: the OS user, the closed profile, the shared folders, local ports and
+pipes, the relay and purge. **No Windows machine was used.** Everything below was read in code, or tested on a Mac against the
+text and values the code produces. Nothing on a real account, permission or file was changed.
+
+## Answer
+
+**The folders hold; the daemon's port does not.** Ports were covered only in part: the Team daemon's own port was not read. The ACLs setup writes keep the Team account out of the owner's profile.
+Other accounts can't read the sign-in code or the relay's token, and the daemon's pipe proves both ends. But on Windows the owner's
+local credential still goes over TCP to whoever holds the daemon's port, and the daemon accepts it from any account (W1).
+The Team account's daemon starts at boot, before the owner signs in. Purge was written for POSIX paths. It never deleted a
+Codex Product Manager's own home on Windows (W2, fixed in this pull request), and it can't finish a Claude Code one there (W3).
+
+| ID | Rating | Finding | Status |
+|---|---|---|---|
+| W1 | **High** | The owner's local credential goes to whoever holds the daemon's port, and opens the daemon from any account | Read in code, pinned by a test; fix requested |
+| W2 | **High** | Purge left a Codex Product Manager's whole home on Windows, and could take every PM's home on any platform | **Fixed here**, test first |
+| W3 | Medium | Purge can't scrub a Claude Code Product Manager on Windows: the account stays held, its memory stays | Read in code, fix requested |
+| W4 | Medium | The Team account can stall the owner's read of its status file | Read in code, fix requested |
+| W5 | Medium | The elevated scripts walk and delete folders the Team account can write | Read in code, fix requested |
+| W6 | Low | Setup closes the profile folder itself, not what inside it lets others in | Read in code, noted |
+| W7 | Low | The elevated setup prints what the Team account wrote to the administrator's console as it is | Read in code, fix requested |
+
+The macOS findings that don't depend on the platform apply here unchanged: H2 (an owner's agent builds a Team agent's branch), M3
+(a Team agent's message reaches the owner's agents) and M4 (the relay forwards any path). L1 and L3 are fixed on every platform.
+
+## Findings
+
+### W1. The owner's local credential goes to whoever holds the daemon's port (High)
+
+This is the macOS H1 again, but on Windows nothing of the #2016 fix applies:
+
+- **Hooks send it over TCP.** `cli/hook/notify.mjs:321` `hookRoute`: on Windows every engine hook posts to
+ `127.0.0.1:<port>` with the full `hook-credential`, not the hook-only token. Hooks fire at every session start and prompt,
+ and the request carries the owner's prompt too (as `notify.mjs`'s own comment on `hookRoute` says): the holder reads it.
+- **CLI clients add it to TCP requests.** `lib/localCredential.ts:35` `localCredentialHeaders` returns the credential on Windows
+ whatever the path (on macOS and Linux only when no socket can exist). Which of its callers speak TCP on Windows is under
+ "Not verified".
+- **The daemon accepts it from any account.** `lib/peerAccount.ts:112` `peerIsThisAccount` answers yes on Windows without
+ asking. `hookServer.ts:496-500` then lets the holder use the whole local API, the owner's shell included.
+- **No race is needed after a reboot.** The Team daemon's task starts at boot (`team/windowsScript.ts:649`, `BootTrigger`). The
+ owner's daemon starts at their sign-in (`harnessd/platform.ts:302`, `LogonTrigger`) or on a timer. The Team account can change
+ the code its task runs: `cli\<version>\cli.js` in its own profile. Windows lets another account bind a free loopback port. While
+ the first socket is open, Windows refuses a second account the same port, so the holder must get there first: at boot, or at a
+ daemon restart.
+- **Holding the port makes it worse.** Seeing the port taken, the owner's daemon moves to another one (`hookServer.ts:1292`;
+ on Windows its pipe path is always set, `lib/localSocket.ts:73`). Hooks keep posting to the installed port, to the holder.
+- What holds: Desktop never sends the credential over TCP on Windows (`desktop/lib/ws/local_daemon_transport.dart:167-173`).
+ The messages RPC uses only the pipe (`messages/rpc.ts:20-25`). The pipe proves both ends without sending the token
+ (`lib/windows/pipeAuth.ts`).
+
+**Proof:** `cli/src/team/windowsBoundary.spec.ts`, "W1, still open": on Windows a client puts the credential on a TCP request,
+and the daemon counts it from a caller it never looked up. Closing the hole turns these red. Not tried on Windows.
+
+**Fix:** on Windows, send hooks and every CLI request over the daemon's proven pipe, and never the credential over TCP. Until then,
+make the daemon refuse the credential over TCP from another account. Windows can say who owns a loopback connection
+(`GetExtendedTcpTable` gives the owning process, whose token names its account).
+
+### W2. Purge left a Codex Product Manager's home on Windows (High, fixed here)
+
+`superTabs/inCore/teamPurge.ts` deletes a purged Codex PM's own engine home only if its path starts with `<home>/.harness-pm-homes/`.
+`pmEngineHome` (`superTabs/teamDaemon.ts:35`) builds it with `join`, which gives `\` on Windows, so the check never matched.
+Purge answered `ok`, and the PM's Codex history, sessions and sign-in stayed in the Team account for its next agent to read. The
+sweep doesn't look there.
+
+The same check also matched a home one level under the PM homes folder. Purge deletes the home's parent, so that would have deleted
+every PM's home. It also took any id, and Windows drops a name's trailing spaces and dots: an id of `.. ` is `..`, and the parent
+deleted is the whole Team home (security review 1 of this pull request). Only the daemon writes the record, in the Team account's
+data folder, so this needs a bad record, or a Team agent that writes it.
+
+**Fixed:** `isPmCodexHome` accepts exactly `<home>\.harness-pm-homes\<id>\codex`, checked with the platform's own path rules,
+and the id by `pmEngineHome`'s own rule (`PM_START_ID`: letters, digits, `_` and `-`).
+`ownHomeFolder`, main's check for a Team-written agent's own home, follows the same id rule, so `.. ` is refused there too.
+Tests: `teamPurge.spec.ts`, "isPmCodexHome" (with `path.win32`), and "of a Codex session whose home is not one of
+pmEngineHome's". Both fail on `main`; the `.. ` case fails without the id rule. PR #2559 adds the same `/` check in a second place and needs the same helper.
+
+### W3. Purge can't scrub a Claude Code Product Manager on Windows (Medium)
+
+`teamPurge.ts:120` `folderOf` uses a session's folder only if it starts with `/`. A Windows worktree (`C:\...`) never does,
+so the scrub skips its transcript folder, its project memory, its history lines by folder, and its entries in `.claude.json` and
+the backups. Then the sweep finds the transcripts, which are named by session id, and answers `SCRUB_INCOMPLETE` at every retry.
+The account stays held until a person steps in, which is said (it fails closed). Files the sweep can't name, such as the
+project's `memory/` notes, are not checked. `sweepForSession` also looks for `"<folder>/`, a POSIX separator.
+
+**Fix:** derive the folder and its separators from the platform, as W2 does. That covers Claude Code's slug for `C:\` and how
+Claude Code writes a Windows path in its history and config. Test with `path.win32`. Check against a real Windows Claude Code home.
+
+### W4. The Team account can stall the owner's read of its status file (Medium)
+
+This is the Windows form of macOS M5. The Team account may write `C:\ProgramData\Harness\Team` (`windowsScript.ts:77`, `status`).
+The owner's daemon reads `status.json` there about once a minute, synchronously (`superTabs/service.ts:883`,
+`team/privacy.ts:164` `readStatusFile`), as do `harness team status` and setup.
+
+- An exclusive oplock that the Team account takes on its own file makes the owner's open wait until it lets go. On Windows a
+ `CreateFile` waits for the oplock to break. That would stop the owner's Swarm service, as the FIFO did on a Mac.
+- `O_NOFOLLOW` and `O_NONBLOCK` exist only on POSIX (Node documents Windows' flags), so the open follows a symbolic link. A
+ file link needs Developer Mode or the privilege. The size check after the open still bounds what is read.
+- A file opened without sharing gives `EBUSY`, which is read as no status. That is harmless.
+
+Not tried: no Windows machine.
+
+**Fix:** read the status off the daemon's main thread with a deadline, in a worker or a child process. Or ask the Team daemon
+for it over a connection with a timeout.
+
+### W5. The elevated scripts walk folders the Team account can write (Medium)
+
+`Remove-Tree` (`windowsScript.ts:104-114`) checks that a folder is not a link, then lists it and deletes by path. Removal runs it,
+as an administrator, on the Status folder (`:799`, which the Team account may write) and on what is left of its profile
+(`:784`, `:790`). A Team process alive at that moment could swap a checked folder for a junction, and the administrator would
+delete files elsewhere.
+
+Removal stops the Team account's processes once (`:739-744`). A process still running then holds the profile, and removal stops
+before deleting anything (`:761-764`). Only a process that starts between that check and the account's deletion (`:771`) could
+race this. That means a new sign-in of the account, such as a task it registered itself. Tasks the Team account registered are
+not removed with it. So a Team agent could register a repeating task long before any removal and aim at that window, rather than
+count on luck. Whether a standard account can register a task that runs while it is not signed in (an S4U task; setup gives it
+the batch logon right) is under "Not verified": rated Medium until it is (security review 1 of this pull request).
+
+On a repair, `Set-Folder` sets an inheritable ACL on the existing Status folder (`:128-130`), and Windows propagates it into the
+Team account's files there. Whether that propagation follows a link the account planted was not checked.
+
+**If such a task can be registered, this is High:** deleting as an administrator can be turned
+into taking the computer. **Fix:** first rename the folder inside the administrators-only parent, and take the Team account's
+access off it on the open handle, without propagation. Then delete by handle, refusing reparse points. Also remove the Team
+account's own scheduled tasks.
+
+### W6. Setup closes the profile folder itself, not what inside it lets others in (Low)
+
+Step 4 (`windowsScript.ts:488-498`) removes the explicit allow ACEs for Everyone, Users and Authenticated Users on the profile
+folder itself. It doesn't remove inherited ones, and it doesn't look inside. Every Windows account has "Bypass traverse checking",
+so a file or folder inside the profile with its own ACE for those groups opens by its full path, though the profile can't be
+listed. The privacy check tries eight fixed places (`windowsTeam.ts:51-64`), so it would miss one elsewhere. Default profiles have
+no such ACE. None was looked for on a real machine. Also:
+
+- `C:\Users\Public`, and folders an owner's tool makes at `C:\` or in `C:\ProgramData`, are readable by every account. On Windows
+ the owner's per-user temporary folder is inside the profile, so macOS M1 is narrower here. Not looked at.
+- The check fails for Administrators only (`windowsTeam.ts:104`). Setup takes the account out of that group alone
+ (`windowsScript.ts:466`). A repair would leave any other group that someone gave the account.
+
+**Fix:** have setup list, without changing them, explicit broad ACEs under the profile in a bounded walk, and say so in
+`harness team status`.
+
+### W7. The elevated setup prints what the Team account wrote (Low)
+
+The one-shot runs as the Team account append to a file in the stage, which that account may write (`windowsScript.ts:393-395`).
+The account may also list the stage. Setup prints those lines to the administrator's console as they are (`:534`, `:541`), so they
+can carry terminal escape codes. This is L1, in an elevated window. **Fix:** remove control and format characters before printing,
+as `privacy.ts` `statusText` does.
+
+## What holds
+
+| Area | What was found | Evidence |
+|---|---|---|
+| OS user | New standard user in Users, taken out of Administrators, visible; 40-character password from the system's generator, never on a command line or in output, handed to Task Scheduler and cleared. Batch logon given to its SID alone and taken back at removal | `windowsScript.ts:354-367, 446-473, 781`; `windowsScript.spec.ts` |
+| Not an administrator | The privacy check fails on Administrators in the token, deny-only included | `windowsTeam.ts:104`; `windowsTeam.spec.ts` |
+| Owner's profile | Tied to the owner by Windows' profile list, not by name; broad ACEs on the folder removed; sentinel made by handle (`CreateNew`), given to the owner, no ACE of its own; listing refused, checked every 5 minutes | `windowsScript.ts:423-429, 488-517`; `windowsTeam.ts:51-108` |
+| Shared folders | Each one is made with its ACL in one call, and protected. One that already exists must be a plain folder of Administrators or SYSTEM. The Team account adds nothing to the handover folder and can't remove it; it writes in Status but can't delete the handover folder in it | `windowsScript.ts:117-131, 543-566`; `windowsBoundary.spec.ts` |
+| Sign-in handover | Other accounts can't read it (protected, no Users ACE). The owner writes only to a plain folder and file. The Team account reads a plain small file once, and deletes anything else unread | `windowsTeam.ts:221-253`; `windowsBoundary.spec.ts`, `windowsTeam.spec.ts` |
+| Relay folder | Protected: owner, SYSTEM, Administrators full, Team account read, nobody else. Both sides check the owner's SID of the folder and the file. `icacls` gets an argument array | `windowsScript.ts:553-561`; `relay.ts:214-240`; `windowsBoundary.spec.ts` |
+| Daemon pipe | Both ends prove the token by HMAC; a squatter on a dead daemon's name learns nothing usable | `lib/windows/pipeAuth.ts` |
+| Terminal host pipe | Its own pipe per user and home, named with 16 random hex digits per start, made first (`FILE_FLAG_FIRST_PIPE_INSTANCE`), DACL `D:P(A;;GA;;;<user SID>)` (the user alone connects), remote clients refused; the daemon checks the host's hello proof of the token | `pty/src/transport/windows.rs:1-17, 172`; `lib/ptyHost/protocol.ts:135-160` |
+| Desktop, messages | Only over the pipe on Windows, never the credential over TCP | `local_daemon_transport.dart:167-173`; `messages/rpc.ts:20-25` |
+| The task | Runs as the Team account, least privilege. Every account may read it; the owner may also start it. Its XML holds backend addresses only, and its values are limited to what `cmd.exe` passes unchanged | `windowsScript.ts:46-58, 607-688`; `layout.ts` `carriedBackendEnv` |
+| Elevated scripts | Every value checked and single-quoted (every PowerShell quote). The administrator writes nothing in the Team profile; only Administrators and SYSTEM change the stage (the Team account lists and reads it, and writes its own output files there, W7); copies refuse links | `windowsScript.ts:31-44, 170-253, 369-383`; `windowsScript.spec.ts` |
+| Status text | Control and format characters removed before the owner sees them (L1) | `privacy.ts:180` |
+| Removal | Refuses an account or profile that is not ours. When the profile is held, it changes nothing and starts the task again. It forgets only team machines hosted by the owner's machine (L3) | `windowsScript.ts:716-776`; `command.ts:556-562` |
+
+## Not verified
+
+- **No Windows machine.** Nothing here ran on Windows: not the ACLs, the oplock (W4), the race (W5), the port (W1) or Claude
+ Code's Windows paths (W3). The SDDL tests check what setup asks Windows for, not what Windows did.
+- Whether another standard account can read a Team or owner process's command line on Windows (macOS M2). Windows normally
+ needs a right on the process that it doesn't give across accounts. Not checked.
+- Ports were covered only in part: the Team daemon's own loopback port (18493) was not read beyond what the macOS audit says.
+ The terminal host's pipe was read (under "What holds", security review 2 of this pull request); nothing about it ran on Windows.
+- Which callers of `localCredentialHeaders` speak TCP on Windows (W1): `cli.ts`, `remoteCommand.ts`, `superTabs/attach.ts`,
+ `devices/client.ts`, `agentClient/settings.ts`, `lib/daemonEndpoint.ts`, `lib/autonomous-device/addonCommand.ts`. Not traced.
+- Whether a standard account can register a scheduled task for itself that runs while it is not signed in (W5).
+- The integration suite was not run: this change touches no backend code.