Skip to content

Commit cf8e3c0

Browse files
committed
fix(desktop): redact the bearer token from readiness parse errors
The parser echoes the offending line or URL in its error message, and that message goes straight into the startup rejection, so a malformed readiness URL still leaked the token the earlier redaction covered on the output path.
1 parent 6a2f129 commit cf8e3c0

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

apps/desktop/src/host-supervisor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ export function createHostSupervisor(options: HostSupervisorOptions): HostSuperv
244244
settled = true
245245
cleanupStartup()
246246
const diagnostic = output === '' ? '' : `\nHost output:\n${output}`
247-
reject(new Error(`${error instanceof Error ? error.message : String(error)}${diagnostic}`))
247+
const message = redactHostToken(error instanceof Error ? error.message : String(error))
248+
reject(new Error(`${message}${diagnostic}`))
248249
}
249250
const acceptChunk = (chunk: string): void => {
250251
appendOutput(chunk)

apps/desktop/tests/host-supervisor.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,17 @@ describe('desktop Host supervisor', () => {
226226
expect(logged.join('')).toContain('#token=[redacted]')
227227
})
228228

229+
it('keeps the bearer token out of a rejected malformed readiness URL', async () => {
230+
const child = new FakeHostChild()
231+
const supervisor = createHostSupervisor({ spawnHost: () => child })
232+
const starting = supervisor.start()
233+
234+
child.stdout.emit('Pythinker server: https://127.0.0.1:4567/#token=s3cret\n')
235+
236+
await expect(starting).rejects.toThrow(/must be loopback HTTP/su)
237+
await expect(starting).rejects.not.toThrow(/s3cret/su)
238+
})
239+
229240
it('keeps the bearer token out of the pre-readiness exit diagnostic', async () => {
230241
const child = new FakeHostChild()
231242
const supervisor = createHostSupervisor({ spawnHost: () => child })

0 commit comments

Comments
 (0)