Skip to content

Commit 68acc36

Browse files
committed
fix(fill): refuse a fill-only flag of the wrong type at the request seam
- recordAs and textStdin mark fill text as sensitive, but the request boundary only checks that flags is an object. A direct daemon request with textStdin: "true" was read as unmarked, so the value came back in data.text; recordAs: 42 failed later as an UNKNOWN TypeError. Both are now refused as INVALID_ARGS before any device work. - Assert the --no-record response text is exactly [REDACTED].
1 parent 19d3ffd commit 68acc36

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎src/daemon/__tests__/request-router-fill-text-stdin.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ test('an armed --text-stdin --no-record fill returns no part of the value and re
9191
expect(result.ok).toBe(true);
9292
expect(typed).toEqual([SECRET]);
9393
expect(JSON.stringify(result)).not.toContain(SECRET);
94+
if (result.ok) expect(result.data?.text).toBe('[REDACTED]');
9495
expect(sessionStore.get('web')?.actions).toEqual([]);
9596
});
9697

@@ -107,6 +108,27 @@ test('an armed --text-stdin fill without --record-as or --no-record is refused b
107108
expect(JSON.stringify(result)).not.toContain(SECRET);
108109
});
109110

111+
test.each([
112+
['recordAs', { textStdin: undefined, recordAs: 42 }, '--record-as'],
113+
['textStdin', { textStdin: 'true' }, '--text-stdin'],
114+
])(
115+
'a fill whose %s marker has the wrong type is refused before typing',
116+
async (_name, flags, flagName) => {
117+
const { response, typed } = fillWithStdinText(
118+
makeSession('web', { device: WEB_DESKTOP_DEVICE }),
119+
flags,
120+
);
121+
122+
const result = await response;
123+
expect(result.ok).toBe(false);
124+
if (result.ok) return;
125+
expect(result.error.code).toBe('INVALID_ARGS');
126+
expect(result.error.message).toContain(flagName);
127+
expect(typed).toEqual([]);
128+
expect(JSON.stringify(result)).not.toContain(SECRET);
129+
},
130+
);
131+
110132
test('a backend error that echoes the --text-stdin value does not return it', async () => {
111133
const { response, typed } = fillWithStdinText(
112134
makeSession('web', { device: WEB_DESKTOP_DEVICE }),

‎src/daemon/request-router.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,18 +467,31 @@ function mutuallyExclusiveRecordFlagsResponse(): DaemonResponse {
467467
}
468468

469469
const FILL_ONLY_FLAGS = [
470-
['recordAs', '--record-as'],
471-
['textStdin', '--text-stdin'],
470+
['recordAs', '--record-as', 'string'],
471+
['textStdin', '--text-stdin', 'boolean'],
472472
] as const;
473473

474474
function recordingFlagsResponse(req: DaemonRequest): DaemonResponse | undefined {
475475
if (req.flags?.record && req.flags?.noRecord) return mutuallyExclusiveRecordFlagsResponse();
476-
if (req.command === 'fill') return undefined;
476+
if (req.command === 'fill') return malformedFillOnlyFlagResponse(req);
477477
const fillOnly = FILL_ONLY_FLAGS.find(([key]) => req.flags?.[key] !== undefined);
478478
if (!fillOnly) return undefined;
479479
return errorResponse('INVALID_ARGS', `${fillOnly[1]} is supported only by fill.`);
480480
}
481481

482+
/**
483+
* Both fill-only flags mark the text as sensitive, and the request boundary only checks that
484+
* `flags` is an object. A marker of the wrong type is refused here instead of read as unmarked.
485+
*/
486+
function malformedFillOnlyFlagResponse(req: DaemonRequest): DaemonResponse | undefined {
487+
const malformed = FILL_ONLY_FLAGS.find(([key, , type]) => {
488+
const value = req.flags?.[key];
489+
return value !== undefined && typeof value !== type;
490+
});
491+
if (!malformed) return undefined;
492+
return errorResponse('INVALID_ARGS', `${malformed[1]} must be a ${malformed[2]}.`);
493+
}
494+
482495
/**
483496
* `--actions` reads custom actions through the private-AX snapshot path, which
484497
* a raw capture deliberately does not take (ADR 0004: raw preserves the tree

0 commit comments

Comments
 (0)