Skip to content

Commit cd1977e

Browse files
committed
Merge main (59ee395) into dev/3282 before opening the pull request
#3283 changed core/src/host/capabilities.js, its test and the ds-bot patches; none of the six paths this branch touches. The merge keeps both commits whole and adds no edit: plugins/workflow/src/service.js plugins/workflow/client.js plugins/workflow/index.js plugins/workflow/test/spawn-failure-message.test.js docs/subsystems/workflow.md changelog.d/3282.fixed.md
2 parents 0f2d6b3 + 59ee395 commit cd1977e

6 files changed

Lines changed: 216 additions & 13 deletions

File tree

‎changelog.d/3281.fixed.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A capability's stored failure reason no longer repeats a credential typed into a command line saved in the capability's own `command`, or a credential value that begins with `-`: a `command` containing a space or a tab is read as a command line and its tokens go through the same rules as `args` — the token after a credential-looking flag, the `--flag=value` form and a `NAME=value` token are masked with `[hidden]` — and the token after a credential-looking flag is its value even when it begins with `-`, so `--api-key --verbose` stores `--api-key [hidden]` and a second `--api-key` is masked as a value too. A `command` that is one bare token without whitespace stays unmasked, because it cannot be told from a program name, the same limit as a bare `args` token; the stored reason is still one line of at most 300 characters with the mask applied before the cut, longest value first and a value under six characters left alone, so a failed server's own error line can no longer print that credential into the Bot's system prompt every turn ([#3281](https://github.com/ThinkFlowLab/FlyBot/issues/3281)).

‎core/src/host/capabilities.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ const withoutUserinfo = text => text.replace(/([a-z][a-z0-9+.-]*:\/\/)[^/\s@]+@/
5757
// read as an assignment. A bare token is never a literal: `node` or `server.js` cannot be told from a
5858
// program name, but a literal that is also a header or environment value is masked wherever the
5959
// body repeats it, the command position included.
60+
// #3281: a `command` holding a whole command line is split on whitespace and read the same way, while
61+
// a `command` that is a single bare token stays unmasked, the same limit as a bare `args` token. After
62+
// a credential-looking flag the next token is the value even when it begins with `-`, so
63+
// `--api-key --verbose` stores `--api-key [hidden]` and a second `--api-key` is masked as a value;
64+
// that over-mask is the accepted cost.
6065
const CREDENTIAL_NAME = /(key|token|secret|auth|password|passwd|credential|signature|cookie|session|bearer|hmac)|(?<![a-z0-9])(pat|sig|pass)(?![a-z0-9])/i
6166
const FLAG = /^--?([\w-]+)$/
6267
const INLINE_FLAG = /^--?([^=]+)=(.*)$/
@@ -67,7 +72,11 @@ const withoutCredentialValues = (text, config) => {
6772
if (typeof value === 'string' && value.length >= 6 && CREDENTIAL_NAME.test(name)) values.push(value)
6873
}
6974
for (const [name, value] of Object.entries({ ...config?.headers, ...config?.env })) collect(name, value)
70-
const argv = [config?.command, ...(Array.isArray(config?.args) ? config.args : [])]
75+
const command = config?.command
76+
const commandTokens = typeof command === 'string' && /[ \t]/.test(command)
77+
? command.split(/[ \t]+/).filter(Boolean)
78+
: [command]
79+
const argv = [...commandTokens, ...(Array.isArray(config?.args) ? config.args : [])]
7180
for (let index = 0; index < argv.length; index += 1) {
7281
const token = argv[index]
7382
if (typeof token !== 'string') continue
@@ -77,7 +86,7 @@ const withoutCredentialValues = (text, config) => {
7786
if (assignment) { collect(assignment[1], assignment[2]); continue }
7887
const flag = FLAG.exec(token)
7988
const next = argv[index + 1]
80-
if (!flag || !CREDENTIAL_NAME.test(flag[1]) || typeof next !== 'string' || next.startsWith('-')) continue
89+
if (!flag || !CREDENTIAL_NAME.test(flag[1]) || typeof next !== 'string') continue
8190
collect(flag[1], next)
8291
index += 1
8392
}

‎core/test/capabilities.test.js‎

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,16 @@ test('a sig, hmac or pass header name masks its value while assign, compass and
717717
// #3278: the two things #3275 fixed stay fixed — a value under six characters is left alone rather
718718
// than eating the words around it, and the mask still runs before the 300-character cut, so a literal
719719
// inside the kept part is gone and only the tail past the cut is dropped.
720+
// #3281 test-quality item: the under-six value is pinned behind a credential-looking flag and is
721+
// exactly five characters, so deleting `value.length >= 6` in `capabilities.js` turns this test red
722+
// instead of passing because the flag name itself never matched a credential.
720723
test('an argv literal under six characters stays and an argv literal is masked before the three-hundred cut', async t => {
721724
const state = team()
722725
state.capabilities = {
723726
items: {
724727
long: {
725728
name: 'long', kind: 'mcp', description: 'Local server', transport: 'stdio', command: 'node',
726-
args: ['server.js', '--pin', 'abcde', '--api-key', 'sk-live-abcdef123456'],
729+
args: ['server.js', '--api-key', 'abcde', '--api-key', 'sk-live-abcdef123456'],
727730
env: {}, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1,
728731
},
729732
},
@@ -732,13 +735,13 @@ test('an argv literal under six characters stays and an argv literal is masked b
732735
t.after(() => env.dispose())
733736
const { ctx, rt, mounts, skills } = env
734737
await rt.changeCapabilityAttachment('attach', { name: 'long' }, 'worker')
735-
const quoted = `server exited: --pin abcde ${'x'.repeat(170)} --api-key sk-live-abcdef123456 ${'z'.repeat(200)}`
738+
const quoted = `server exited: --api-key abcde ${'x'.repeat(170)} --api-key sk-live-abcdef123456 ${'z'.repeat(200)}`
736739
ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) })
737740
await rt.scheduleCapabilitiesReconcile()
738741
const status = rt.capabilityStatusesView().worker.long
739742
assert.equal(status.state, 'error')
740743
assert.equal(status.error.length, 300, 'the stored reason is still cut at 300 characters')
741-
assert.equal(status.error.startsWith('server exited: --pin abcde '), true, 'a five-character value is left alone')
744+
assert.equal(status.error.startsWith('server exited: --api-key abcde '), true, 'a five-character value behind a credential flag is left alone')
742745
assert.equal(status.error.includes('--api-key [hidden]'), true, 'the mask ran before the cut')
743746
assert.equal(status.error.includes('sk-live-abcdef123456'), false)
744747
})
@@ -833,3 +836,92 @@ test('an http capability saved before this fix shows no header literal on any su
833836
assert.equal(surfaces.listed.includes(masked), true)
834837
assert.equal(surfaces.prompt.includes(masked), true)
835838
})
839+
840+
// #3281: a stdio entry can be saved from a pasted line, so `command` itself may hold a whole command
841+
// line (`node server.js --api-key …`). When it contains whitespace it is split into tokens and read
842+
// with the same rules as `args`, so the literal after a credential-looking flag is masked in the
843+
// stored reason. A command that is a single bare token stays unmasked: it cannot be told from a
844+
// program name, the same documented limit as a bare `args` token.
845+
test('an error that quotes a stdio command line stored in `command` masks the credential literal', async t => {
846+
const state = team()
847+
state.capabilities = {
848+
items: {
849+
inline: {
850+
name: 'inline', kind: 'mcp', description: 'Local server', transport: 'stdio',
851+
command: 'node server.js --api-key sk-live-abcdef123456 --password=hunter2-secret -e SERVICE_TOKEN=tok-abcdef123',
852+
args: [], env: {}, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1,
853+
},
854+
},
855+
}
856+
const env = await setup({ state })
857+
t.after(() => env.dispose())
858+
const { ctx, rt, mounts, skills } = env
859+
await rt.changeCapabilityAttachment('attach', { name: 'inline' }, 'worker')
860+
const quoted = 'spawn node server.js --api-key sk-live-abcdef123456 --password=hunter2-secret -e SERVICE_TOKEN=tok-abcdef123 ENOENT'
861+
ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) })
862+
await rt.scheduleCapabilitiesReconcile()
863+
const status = rt.capabilityStatusesView().worker.inline
864+
assert.equal(status.state, 'error')
865+
assert.equal(
866+
status.error,
867+
'spawn node server.js --api-key [hidden] --password=[hidden] -e SERVICE_TOKEN=[hidden] ENOENT',
868+
'the inline command line is read with the same flag, inline and assignment rules as args',
869+
)
870+
const stored = JSON.stringify(rt.capabilityStatusesView())
871+
assert.equal(stored.includes('sk-live-abcdef123456'), false)
872+
assert.equal(stored.includes('hunter2-secret'), false)
873+
assert.equal(stored.includes('tok-abcdef123'), false)
874+
})
875+
876+
// #3281: a generated credential can begin with `-`, and the token after a credential-looking flag is
877+
// that flag's value even then. The accepted cost is that `--api-key --verbose` stores `--api-key
878+
// [hidden]`; it is recorded in `docs/subsystems/core-host.md`, the fragment and the pull request body.
879+
test('a dash-prefixed credential value after a credential flag is masked', async t => {
880+
const state = team()
881+
state.capabilities = {
882+
items: {
883+
dash: {
884+
name: 'dash', kind: 'mcp', description: 'Local server', transport: 'stdio', command: 'node',
885+
args: ['server.js', '--api-key', '-s3cr3t-abcdef', '--verbose'],
886+
env: {}, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1,
887+
},
888+
},
889+
}
890+
const env = await setup({ state })
891+
t.after(() => env.dispose())
892+
const { ctx, rt, mounts, skills } = env
893+
await rt.changeCapabilityAttachment('attach', { name: 'dash' }, 'worker')
894+
const quoted = 'spawn node ENOENT: node server.js --api-key -s3cr3t-abcdef --verbose'
895+
ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) })
896+
await rt.scheduleCapabilitiesReconcile()
897+
const status = rt.capabilityStatusesView().worker.dash
898+
assert.equal(status.state, 'error')
899+
assert.equal(status.error, 'spawn node ENOENT: node server.js --api-key [hidden] --verbose', 'a value beginning with - is still the flag value')
900+
assert.equal(JSON.stringify(rt.capabilityStatusesView()).includes('s3cr3t-abcdef'), false)
901+
})
902+
903+
// #3281 accepted cost: a following flag is taken as the value and masked, so `--api-key --verbose`
904+
// reads `--api-key [hidden]`. The test pins the cost exactly; the doc, the fragment and the pull
905+
// request body say the same sentence.
906+
test('a flag directly after a credential flag is masked as its value', async t => {
907+
const state = team()
908+
state.capabilities = {
909+
items: {
910+
bare: {
911+
name: 'bare', kind: 'mcp', description: 'Local server', transport: 'stdio', command: 'node',
912+
args: ['server.js', '--api-key', '--verbose'],
913+
env: {}, approved: true, createdBy: 'worker', createdAt: 1, updatedAt: 1,
914+
},
915+
},
916+
}
917+
const env = await setup({ state })
918+
t.after(() => env.dispose())
919+
const { ctx, rt, mounts, skills } = env
920+
await rt.changeCapabilityAttachment('attach', { name: 'bare' }, 'worker')
921+
const quoted = 'server exited: node server.js --api-key --verbose'
922+
ctx.emit('agent/created', { agent: testAgent('worker', mounts, skills, { awaitMount: async () => { throw new Error(quoted) } }) })
923+
await rt.scheduleCapabilitiesReconcile()
924+
const status = rt.capabilityStatusesView().worker.bare
925+
assert.equal(status.state, 'error')
926+
assert.equal(status.error, 'server exited: node server.js --api-key [hidden]', 'the accepted cost: a following flag is masked')
927+
})

0 commit comments

Comments
 (0)