Skip to content

Commit 8af3931

Browse files
committed
fix: scrub embedded parameterized fill echoes
1 parent d8f0071 commit 8af3931

5 files changed

Lines changed: 257 additions & 86 deletions

File tree

‎docs/adr/0017-parameterized-recorded-inputs.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ The literal exists only on the live request path long enough to execute the inte
5252
1. The request scope registers it as an explicit diagnostics secret before platform work. This is in
5353
addition to key-name redaction, because an opaque value need not look secret.
5454
2. The platform interaction receives the literal.
55-
3. Before response/event/recording retention, the fill result's semantic `text` field and an exact
56-
post-fill `refLabel` become `${VAR}`. Stable selector/ref provenance is preserved byte-for-byte.
57-
Untrusted backend extras and nested settle output parameterize delimited occurrences of the
58-
supplied literal; post-fill selector-chain candidates are dropped only when a parsed `text`,
59-
`label`, or `value` term semantically contains it.
55+
3. Before response/event/recording retention, the fill result's semantic `text` field becomes
56+
`${VAR}` and every occurrence in a post-fill `refLabel` is parameterized. Stable selector/ref
57+
provenance is preserved byte-for-byte.
58+
Untrusted backend extras and nested settle output parameterize every occurrence of the supplied
59+
literal in both keys and values; post-fill selector-chain candidates are dropped only when a
60+
parsed `text`, `label`, or `value` term semantically contains it. Known response and settle
61+
schema fields are the explicit structural boundary and retain their names and provenance values.
6062
4. At `recordActionEntry`, the recorder reconstructs the fill's literal positional, writes only the
6163
placeholder into `SessionAction`, and parameterizes the semantic result field plus arbitrary
6264
backend/settle echoes again. ADR 0012 `target-v1` evidence keeps its structure; exact

‎src/daemon/__tests__/session-action-recorder.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ test('parameterized fills keep literals out of recording state with deterministi
146146
});
147147
});
148148

149-
test('a one-character parameterized fill preserves unrelated response and selector text', () => {
149+
test('a one-character parameterized fill preserves structural selector provenance', () => {
150150
const session = makeIosSession('default');
151151
recordActionEntry(session, {
152152
command: 'fill',
@@ -172,7 +172,7 @@ test('a one-character parameterized fill preserves unrelated response and select
172172
positionals: ['id="password"', '${LETTER}'],
173173
result: {
174174
text: '${LETTER}',
175-
message: 'Already safe',
175+
message: 'Alre${LETTER}dy s${LETTER}fe',
176176
selector: 'id="password"',
177177
selectorChain: ['id="password"', 'label="Account"'],
178178
},

‎src/daemon/handlers/__tests__/interaction-common.test.ts‎

Lines changed: 118 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1-
import { expect, test } from 'vitest';
1+
import { beforeEach, expect, test, vi } from 'vitest';
22
import { makeIosSession } from '../../../__tests__/test-utils/session-factories.ts';
33
import { makeSessionStore } from '../../../__tests__/test-utils/store-factory.ts';
4+
import { attachRefs, type RawSnapshotNode } from '../../../kernel/snapshot.ts';
5+
import type { CommandFlags } from '../../../core/dispatch.ts';
6+
import { handleInteractionCommands } from '../interaction.ts';
47
import { finalizeTouchInteraction } from '../interaction-common.ts';
58

9+
vi.mock('../../../core/dispatch.ts', async (importOriginal) => {
10+
const actual = await importOriginal<typeof import('../../../core/dispatch.ts')>();
11+
return {
12+
...actual,
13+
dispatchCommand: vi.fn(async () => ({})),
14+
};
15+
});
16+
17+
import { dispatchCommand } from '../../../core/dispatch.ts';
18+
const mockDispatch = vi.mocked(dispatchCommand);
19+
const contextFromFlags = (_flags: CommandFlags | undefined) => ({});
20+
21+
beforeEach(() => {
22+
mockDispatch.mockReset();
23+
mockDispatch.mockResolvedValue({});
24+
});
25+
626
test('parameterized fill scrubs backend and nested settle echoes at the response boundary', () => {
727
const secret = 'OpaqueValue1348';
828
const placeholder = '${PASSWORD}';
@@ -12,13 +32,22 @@ test('parameterized fill scrubs backend and nested settle echoes at the response
1232
sessionStore.set(session.name, session);
1333
const payload = {
1434
text: secret,
15-
message: `Backend filled ${secret}`,
35+
message: `prefix${secret}suffix`,
36+
refLabel: `prefix${secret}suffix`,
1637
selector: 'id="password"',
17-
selectorChain: ['id="password"', `value="${secret}" editable=true`],
38+
selectorChain: [
39+
'id="password"',
40+
`value="prefix${secret}suffix" editable=true`,
41+
`label="${secret}4"`,
42+
],
1843
backendEcho: {
1944
id: secret,
20-
status: `accepted ${secret}`,
45+
status: `accepted${secret}suffix`,
2146
nested: { kind: secret },
47+
[secret]: true,
48+
[`prefix${secret}suffix`]: {
49+
[`${secret}4`]: true,
50+
},
2251
},
2352
settle: {
2453
settled: true,
@@ -28,9 +57,14 @@ test('parameterized fill scrubs backend and nested settle echoes at the response
2857
timeoutMs: 100,
2958
diff: {
3059
summary: { additions: 1, removals: 0, unchanged: 0 },
31-
lines: [{ kind: 'added', text: `TextField value=${secret}` }],
60+
lines: [{ kind: 'added', text: `TextField value=prefix${secret}suffix` }],
61+
},
62+
hint: `Observed ${secret}4`,
63+
[`echo${secret}key`]: true,
64+
backendEcho: {
65+
id: secret,
66+
[`key${secret}`]: `value${secret}`,
3267
},
33-
hint: `Observed ${secret}`,
3468
},
3569
};
3670

@@ -50,19 +84,29 @@ test('parameterized fill scrubs backend and nested settle echoes at the response
5084
if (!response.ok) return;
5185
expect(response.data).toMatchObject({
5286
text: placeholder,
53-
message: `Backend filled ${placeholder}`,
87+
message: `prefix${placeholder}suffix`,
88+
refLabel: `prefix${placeholder}suffix`,
5489
selector: 'id="password"',
5590
selectorChain: ['id="password"'],
5691
backendEcho: {
5792
id: placeholder,
58-
status: `accepted ${placeholder}`,
93+
status: `accepted${placeholder}suffix`,
5994
nested: { kind: placeholder },
95+
[placeholder]: true,
96+
[`prefix${placeholder}suffix`]: {
97+
[`${placeholder}4`]: true,
98+
},
6099
},
61100
settle: {
62101
diff: {
63-
lines: [{ kind: 'added', text: `TextField value=${placeholder}` }],
102+
lines: [{ kind: 'added', text: `TextField value=prefix${placeholder}suffix` }],
103+
},
104+
hint: `Observed ${placeholder}4`,
105+
[`echo${placeholder}key`]: true,
106+
backendEcho: {
107+
id: placeholder,
108+
[`key${placeholder}`]: `value${placeholder}`,
64109
},
65-
hint: `Observed ${placeholder}`,
66110
},
67111
});
68112
expect(JSON.stringify(response.data)).not.toContain(secret);
@@ -71,3 +115,67 @@ test('parameterized fill scrubs backend and nested settle echoes at the response
71115
expect(recordedResult).toEqual(response.data);
72116
expect(JSON.stringify(recordedResult)).not.toContain(secret);
73117
});
118+
119+
test('parameterized fill scrubs concatenated backend values and object keys through the handler route', async () => {
120+
const secret = 'TOKEN123';
121+
const placeholder = '${PASSWORD}';
122+
const sessionStore = makeSessionStore();
123+
const sessionName = 'parameterized-fill-handler-route';
124+
const session = makeIosSession(sessionName, { appBundleId: 'com.example.app' });
125+
const nodes: RawSnapshotNode[] = [
126+
{
127+
index: 0,
128+
type: 'XCUIElementTypeTextField',
129+
identifier: 'password',
130+
label: 'Password',
131+
rect: { x: 20, y: 40, width: 200, height: 44 },
132+
enabled: true,
133+
hittable: true,
134+
},
135+
];
136+
session.recordSession = true;
137+
session.snapshot = {
138+
nodes: attachRefs(nodes),
139+
createdAt: Date.now(),
140+
backend: 'xctest',
141+
};
142+
sessionStore.set(sessionName, session);
143+
mockDispatch.mockImplementation(async (_device, command) =>
144+
command === 'fill'
145+
? {
146+
message: `prefix${secret}suffix`,
147+
[`prefix${secret}suffix`]: {
148+
[`${secret}4`]: `echo${secret}`,
149+
},
150+
}
151+
: {},
152+
);
153+
154+
const response = await handleInteractionCommands({
155+
req: {
156+
token: 't',
157+
session: sessionName,
158+
command: 'fill',
159+
positionals: ['@e1', secret],
160+
flags: { recordAs: 'PASSWORD' },
161+
},
162+
sessionName,
163+
sessionStore,
164+
contextFromFlags,
165+
});
166+
167+
expect(response, JSON.stringify(response)).toMatchObject({ ok: true });
168+
if (!response?.ok) return;
169+
expect(response.data).toMatchObject({
170+
message: 'Filled 8 chars',
171+
[`prefix${placeholder}suffix`]: {
172+
[`${placeholder}4`]: `echo${placeholder}`,
173+
},
174+
ref: 'e1',
175+
text: placeholder,
176+
});
177+
expect(JSON.stringify(response.data)).not.toContain(secret);
178+
expect(JSON.stringify(session.actions)).not.toContain(secret);
179+
expect(mockDispatch.mock.calls[0]?.[1]).toBe('fill');
180+
expect(mockDispatch.mock.calls[0]?.[2]).toContain(secret);
181+
});

0 commit comments

Comments
 (0)