@ai-ecoverse/slicc-browsers 1.28.4 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/cookie-plant.mjs +4273 -0
- package/fixture-server.mjs +10 -0
- package/guard-runner.mjs +56 -7
- package/guard-vectors.json +5501 -1140
- package/package.json +4 -3
- package/schema/guard-vectors.schema.json +42 -2
- package/sign-in-hold.mjs +1 -1
package/cookie-plant.mjs
ADDED
|
@@ -0,0 +1,4273 @@
|
|
|
1
|
+
import { outcome, waitFor } from './guard-driver.mjs';
|
|
2
|
+
import { createObserverTarget } from './observer-target.mjs';
|
|
3
|
+
|
|
4
|
+
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
|
|
6
|
+
const bytesOf = (text) => new TextEncoder().encode(text);
|
|
7
|
+
const b64 = (bytes) => {
|
|
8
|
+
let s = '';
|
|
9
|
+
for (const byte of bytes) s += String.fromCharCode(byte);
|
|
10
|
+
return btoa(s);
|
|
11
|
+
};
|
|
12
|
+
const b64text = (text) => b64(bytesOf(text));
|
|
13
|
+
const fromB64 = (text) =>
|
|
14
|
+
new TextDecoder().decode(Uint8Array.from(atob(text), (char) => char.charCodeAt(0)));
|
|
15
|
+
|
|
16
|
+
function cookieNames(tag) {
|
|
17
|
+
const id = String(tag ?? '')
|
|
18
|
+
.replace(/[^a-zA-Z0-9]/g, '')
|
|
19
|
+
.slice(-20);
|
|
20
|
+
const suffix = id || 'x';
|
|
21
|
+
return {
|
|
22
|
+
plant: `cplant${suffix}`,
|
|
23
|
+
ordinary: `oord${suffix}`,
|
|
24
|
+
adobe: `oadobe${suffix}`,
|
|
25
|
+
delete: `sid${suffix}`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function answered(out) {
|
|
30
|
+
if (!out) return false;
|
|
31
|
+
if (out.ok) return true;
|
|
32
|
+
const err = out.error;
|
|
33
|
+
if (err && typeof err.code === 'number') return true;
|
|
34
|
+
const message = String(err?.message ?? err ?? '');
|
|
35
|
+
if (/^slicc: refused:/.test(message)) return true;
|
|
36
|
+
if (/Invalid (parameters|Params)|Invalid request id|continueResponse at Request/i.test(message))
|
|
37
|
+
return true;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function refused(out) {
|
|
42
|
+
if (!out || out.ok) return false;
|
|
43
|
+
return /^slicc: refused:/.test(String(out.error?.message ?? out.error ?? ''));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function sessionCut(out) {
|
|
47
|
+
return refused(out);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function note(notes, label, evidence) {
|
|
51
|
+
notes.push(`${label}: ${JSON.stringify(evidence)}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function pageSnapshot(client, pageSession) {
|
|
55
|
+
if (!pageSession) return { ready: false };
|
|
56
|
+
const ready = await capped(
|
|
57
|
+
outcome(
|
|
58
|
+
client.send(
|
|
59
|
+
'Runtime.evaluate',
|
|
60
|
+
{ expression: 'document.readyState', returnByValue: true },
|
|
61
|
+
pageSession
|
|
62
|
+
)
|
|
63
|
+
),
|
|
64
|
+
800,
|
|
65
|
+
'pageSnapshot'
|
|
66
|
+
);
|
|
67
|
+
const href = await capped(
|
|
68
|
+
outcome(
|
|
69
|
+
client.send(
|
|
70
|
+
'Runtime.evaluate',
|
|
71
|
+
{ expression: 'location.href', returnByValue: true },
|
|
72
|
+
pageSession
|
|
73
|
+
)
|
|
74
|
+
),
|
|
75
|
+
800,
|
|
76
|
+
'pageSnapshot'
|
|
77
|
+
);
|
|
78
|
+
return {
|
|
79
|
+
ready: ready.ok,
|
|
80
|
+
readyState: ready.result?.result?.value ?? null,
|
|
81
|
+
href: href.ok ? (href.result?.result?.value ?? null) : null,
|
|
82
|
+
readyError: ready.ok ? undefined : String(ready.error?.message ?? ready.error),
|
|
83
|
+
hrefError: href.ok ? undefined : String(href.error?.message ?? href.error),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function serverHitsFor(fixtureLog, url, since) {
|
|
88
|
+
if (typeof fixtureLog !== 'function') return null;
|
|
89
|
+
let entries;
|
|
90
|
+
try {
|
|
91
|
+
entries = await fixtureLog();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
return { error: String(error?.message ?? error) };
|
|
94
|
+
}
|
|
95
|
+
if (!Array.isArray(entries)) return { error: 'fixture log not an array' };
|
|
96
|
+
const matched = entries.filter(
|
|
97
|
+
(entry) =>
|
|
98
|
+
Number(entry?.time ?? 0) >= since &&
|
|
99
|
+
(entry?.url === url || String(entry?.url ?? '').startsWith(url))
|
|
100
|
+
);
|
|
101
|
+
const byPath = {};
|
|
102
|
+
for (const entry of entries) {
|
|
103
|
+
if (Number(entry?.time ?? 0) < since) continue;
|
|
104
|
+
let path = entry?.url ?? '';
|
|
105
|
+
try {
|
|
106
|
+
path = new URL(entry.url).pathname;
|
|
107
|
+
} catch {}
|
|
108
|
+
byPath[path] = (byPath[path] ?? 0) + 1;
|
|
109
|
+
}
|
|
110
|
+
return { hits: matched.length, urls: matched.map((e) => e.url), byPath };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function diagnoseIncomplete({
|
|
114
|
+
notes,
|
|
115
|
+
label,
|
|
116
|
+
incomplete,
|
|
117
|
+
url,
|
|
118
|
+
client,
|
|
119
|
+
pageSession,
|
|
120
|
+
from,
|
|
121
|
+
methods,
|
|
122
|
+
pauseMs,
|
|
123
|
+
startedAt,
|
|
124
|
+
legStartedAt,
|
|
125
|
+
fixtureLog,
|
|
126
|
+
ensure,
|
|
127
|
+
trigger,
|
|
128
|
+
firstIncomplete,
|
|
129
|
+
handle,
|
|
130
|
+
}) {
|
|
131
|
+
const elapsedMs = Date.now() - startedAt;
|
|
132
|
+
const legElapsedMs = Date.now() - legStartedAt;
|
|
133
|
+
const page = await pageSnapshot(client, pageSession);
|
|
134
|
+
const since = client.events.slice(from);
|
|
135
|
+
const pauses = pauseEvents(since, 0, url, methods);
|
|
136
|
+
const anyPaused = since.filter((event) => methods.includes(event.method)).length;
|
|
137
|
+
const server = await serverHitsFor(fixtureLog, url, startedAt);
|
|
138
|
+
const timing = timingOf(handle);
|
|
139
|
+
const evidence = {
|
|
140
|
+
incomplete,
|
|
141
|
+
path: label,
|
|
142
|
+
url,
|
|
143
|
+
elapsedMs,
|
|
144
|
+
legElapsedMs,
|
|
145
|
+
pauseMs,
|
|
146
|
+
ensure: ensure ?? null,
|
|
147
|
+
triggerOk: trigger?.ok ?? null,
|
|
148
|
+
triggerError: trigger?.ok ? undefined : String(trigger?.error?.message ?? trigger?.error ?? ''),
|
|
149
|
+
page,
|
|
150
|
+
pauseHits: pauses.length,
|
|
151
|
+
anyPaused,
|
|
152
|
+
server,
|
|
153
|
+
...timing,
|
|
154
|
+
};
|
|
155
|
+
note(notes, `cookie-plant.${label}`, evidence);
|
|
156
|
+
if (firstIncomplete && !firstIncomplete.noted) {
|
|
157
|
+
firstIncomplete.noted = true;
|
|
158
|
+
note(notes, 'cookie-plant.firstIncomplete', evidence);
|
|
159
|
+
}
|
|
160
|
+
return evidence;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function hostOf(origin) {
|
|
164
|
+
try {
|
|
165
|
+
return new URL(origin).hostname.toLowerCase();
|
|
166
|
+
} catch {
|
|
167
|
+
return '';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function cookieHeader(name, value, domain, extra = '', domainAttr = null) {
|
|
172
|
+
const parts = [`${name}=${value}`];
|
|
173
|
+
if (domainAttr) parts.push(domainAttr);
|
|
174
|
+
else if (domain) parts.push(`Domain=${domain}`);
|
|
175
|
+
parts.push('Path=/');
|
|
176
|
+
if (extra) parts.push(extra);
|
|
177
|
+
return parts.join('; ');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const hstsPreloaded = (host) => {
|
|
181
|
+
const name = String(host ?? '')
|
|
182
|
+
.toLowerCase()
|
|
183
|
+
.replace(/\.$/, '');
|
|
184
|
+
return (
|
|
185
|
+
name === 'adobe.com' ||
|
|
186
|
+
name.endsWith('.adobe.com') ||
|
|
187
|
+
name === 'adobelogin.com' ||
|
|
188
|
+
name.endsWith('.adobelogin.com')
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
function fixtureOriginFor(templateUrl, host, { insecurePreloaded = false } = {}) {
|
|
193
|
+
try {
|
|
194
|
+
const parsed = new URL(templateUrl);
|
|
195
|
+
const name = host ?? parsed.hostname;
|
|
196
|
+
const port = parsed.port ? `:${parsed.port}` : '';
|
|
197
|
+
const scheme =
|
|
198
|
+
!insecurePreloaded && hstsPreloaded(name) ? 'https:' : (parsed?.protocol ?? 'http:');
|
|
199
|
+
return `${scheme}//${name}${port}`;
|
|
200
|
+
} catch {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function siteHost(host) {
|
|
206
|
+
const parts = String(host ?? '')
|
|
207
|
+
.toLowerCase()
|
|
208
|
+
.split('.')
|
|
209
|
+
.filter(Boolean);
|
|
210
|
+
return parts.length >= 2 ? parts.slice(-2).join('.') : String(host ?? '').toLowerCase();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function binaryHeaders(pairs) {
|
|
214
|
+
const chunks = [];
|
|
215
|
+
for (const { name, value } of pairs) {
|
|
216
|
+
chunks.push(`${name}: ${value}`);
|
|
217
|
+
}
|
|
218
|
+
return b64text(`${chunks.join('\0')}\0`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function rawHttpResponse({ code, phrase, headers, body = '' }) {
|
|
222
|
+
const lines = [`HTTP/1.1 ${code} ${phrase}`];
|
|
223
|
+
for (const { name, value } of headers) lines.push(`${name}: ${value}`);
|
|
224
|
+
lines.push('', body);
|
|
225
|
+
return b64text(lines.join('\r\n'));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function until(check, ms, step = 25) {
|
|
229
|
+
const deadline = Date.now() + ms;
|
|
230
|
+
for (;;) {
|
|
231
|
+
const value = await check();
|
|
232
|
+
if (value) return value;
|
|
233
|
+
if (Date.now() > deadline) return null;
|
|
234
|
+
await pause(step);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function openPage(reader, url, notes, internalSessions, browserContextId = null) {
|
|
239
|
+
const created = await outcome(
|
|
240
|
+
createObserverTarget(
|
|
241
|
+
reader,
|
|
242
|
+
{ url, ...(browserContextId ? { browserContextId } : {}) },
|
|
243
|
+
notes
|
|
244
|
+
).then(async (result) => {
|
|
245
|
+
const { sessionId } = await reader.send('Target.attachToTarget', {
|
|
246
|
+
targetId: result.targetId,
|
|
247
|
+
flatten: true,
|
|
248
|
+
});
|
|
249
|
+
await reader.send('Page.enable', {}, sessionId);
|
|
250
|
+
await reader.send('Runtime.enable', {}, sessionId);
|
|
251
|
+
await reader.send('Network.enable', {}, sessionId);
|
|
252
|
+
return { targetId: result.targetId, sessionId };
|
|
253
|
+
})
|
|
254
|
+
);
|
|
255
|
+
if (!created.ok) return created;
|
|
256
|
+
internalSessions.add(created.result.sessionId);
|
|
257
|
+
const ready = await waitFor(async () => {
|
|
258
|
+
const read = await outcome(
|
|
259
|
+
reader.send(
|
|
260
|
+
'Runtime.evaluate',
|
|
261
|
+
{ expression: 'document.readyState', returnByValue: true },
|
|
262
|
+
created.result.sessionId
|
|
263
|
+
)
|
|
264
|
+
);
|
|
265
|
+
return read.ok && ['interactive', 'complete'].includes(read.result?.result?.value);
|
|
266
|
+
}, 4000);
|
|
267
|
+
note(notes, 'cookie-plant.open', {
|
|
268
|
+
targetId: created.result.targetId,
|
|
269
|
+
url,
|
|
270
|
+
ready: Boolean(ready),
|
|
271
|
+
});
|
|
272
|
+
if (!ready)
|
|
273
|
+
return {
|
|
274
|
+
ok: true,
|
|
275
|
+
result: { incomplete: 'opener page did not become ready', ...created.result },
|
|
276
|
+
};
|
|
277
|
+
return created;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function detectTransport(client, sessionId, notes) {
|
|
281
|
+
const fetchEnable = await capped(
|
|
282
|
+
outcome(
|
|
283
|
+
client.send(
|
|
284
|
+
'Fetch.enable',
|
|
285
|
+
{
|
|
286
|
+
patterns: [
|
|
287
|
+
{ urlPattern: '*', requestStage: 'Request' },
|
|
288
|
+
{ urlPattern: '*', requestStage: 'Response' },
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
sessionId
|
|
292
|
+
)
|
|
293
|
+
),
|
|
294
|
+
800,
|
|
295
|
+
'detectTransport'
|
|
296
|
+
);
|
|
297
|
+
if (fetchEnable.ok) {
|
|
298
|
+
note(notes, 'cookie-plant.transport', { kind: 'fetch' });
|
|
299
|
+
return { kind: 'fetch', fetch: true, legacy: false, fetchEnable };
|
|
300
|
+
}
|
|
301
|
+
if (refused(fetchEnable) || /timeout/i.test(String(fetchEnable.error?.message ?? ''))) {
|
|
302
|
+
note(notes, 'cookie-plant.transport', {
|
|
303
|
+
kind: 'fetch',
|
|
304
|
+
enable: refused(fetchEnable) ? 'refused' : 'unanswered',
|
|
305
|
+
});
|
|
306
|
+
return { kind: 'fetch', fetch: true, legacy: false, fetchEnable };
|
|
307
|
+
}
|
|
308
|
+
const legacyEnable = await capped(
|
|
309
|
+
outcome(
|
|
310
|
+
client.send('Network.setRequestInterception', { patterns: [{ urlPattern: '*' }] }, sessionId)
|
|
311
|
+
),
|
|
312
|
+
800,
|
|
313
|
+
'detectTransport'
|
|
314
|
+
);
|
|
315
|
+
if (legacyEnable.ok) {
|
|
316
|
+
note(notes, 'cookie-plant.transport', { kind: 'legacy' });
|
|
317
|
+
return { kind: 'legacy', fetch: false, legacy: true, fetchEnable: null };
|
|
318
|
+
}
|
|
319
|
+
note(notes, 'cookie-plant.transport', {
|
|
320
|
+
kind: null,
|
|
321
|
+
fetchError: String(fetchEnable.error?.message ?? fetchEnable.error),
|
|
322
|
+
legacyError: String(legacyEnable.error?.message ?? legacyEnable.error),
|
|
323
|
+
});
|
|
324
|
+
return { kind: null, fetch: false, legacy: false, fetchEnable: null };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async function enableLegacy(client, sessionId) {
|
|
328
|
+
return outcome(
|
|
329
|
+
client.send('Network.setRequestInterception', { patterns: [{ urlPattern: '*' }] }, sessionId)
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
async function disableInterception(client, sessionId, transport) {
|
|
334
|
+
if (transport.fetch) await outcome(client.send('Fetch.disable', {}, sessionId));
|
|
335
|
+
if (transport.legacy)
|
|
336
|
+
await outcome(client.send('Network.setRequestInterception', { patterns: [] }, sessionId));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function pauseEvents(events, from, url, methods) {
|
|
340
|
+
return events.slice(from).filter((event) => {
|
|
341
|
+
if (!methods.includes(event.method)) return false;
|
|
342
|
+
const requestUrl = event.params?.request?.url ?? event.params?.request?.urlFragment;
|
|
343
|
+
return requestUrl === url || String(requestUrl ?? '').startsWith(url);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async function waitPause(client, from, url, methods, budget) {
|
|
348
|
+
return until(() => {
|
|
349
|
+
const hits = pauseEvents(client.events, from, url, methods);
|
|
350
|
+
return hits.at(-1) ?? null;
|
|
351
|
+
}, budget);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
async function tabHrefFromReader(reader, pageTarget) {
|
|
355
|
+
if (!reader || !pageTarget) return null;
|
|
356
|
+
const info = await capped(
|
|
357
|
+
outcome(reader.send('Target.getTargetInfo', { targetId: pageTarget })),
|
|
358
|
+
800,
|
|
359
|
+
'tabHref'
|
|
360
|
+
);
|
|
361
|
+
if (!info.ok) return null;
|
|
362
|
+
const value = info.result?.targetInfo?.url;
|
|
363
|
+
return typeof value === 'string' ? value : null;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async function readTabHref({ reader, pageTarget }) {
|
|
367
|
+
return tabHrefFromReader(reader, pageTarget);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function pathRequestMatch(reqUrl, url) {
|
|
371
|
+
if (!reqUrl || !url) return false;
|
|
372
|
+
if (reqUrl === url || reqUrl.startsWith(`${url}&`) || reqUrl.startsWith(`${url}#`)) return true;
|
|
373
|
+
try {
|
|
374
|
+
const want = new URL(url);
|
|
375
|
+
const got = new URL(reqUrl);
|
|
376
|
+
if (want.origin !== got.origin || want.pathname !== got.pathname) return false;
|
|
377
|
+
for (const [key, value] of want.searchParams) {
|
|
378
|
+
if (got.searchParams.get(key) !== value) return false;
|
|
379
|
+
}
|
|
380
|
+
return want.searchParams.toString().length > 0 || got.searchParams.toString().length === 0;
|
|
381
|
+
} catch {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function readerNetworkBlocked(reader, sessionId, url, from = 0) {
|
|
387
|
+
if (!reader?.events || !url || !sessionId) return false;
|
|
388
|
+
const events = reader.events.slice(Math.max(0, from));
|
|
389
|
+
const requests = new Map();
|
|
390
|
+
for (const event of events) {
|
|
391
|
+
if (event.sessionId !== sessionId) continue;
|
|
392
|
+
if (event.method === 'Network.requestWillBeSent') {
|
|
393
|
+
const id = event.params?.requestId;
|
|
394
|
+
if (!id) continue;
|
|
395
|
+
const reqUrl = String(event.params?.request?.url ?? '');
|
|
396
|
+
if (pathRequestMatch(reqUrl, url)) requests.set(id, reqUrl);
|
|
397
|
+
}
|
|
398
|
+
if (event.method === 'Network.loadingFailed') {
|
|
399
|
+
const id = event.params?.requestId;
|
|
400
|
+
if (!id || !requests.has(id)) continue;
|
|
401
|
+
const err = String(event.params?.errorText ?? event.params?.blockedReason ?? '');
|
|
402
|
+
if (/ERR_BLOCKED_BY_CLIENT|BlockedByClient/i.test(err)) return true;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
async function quietFixture(fixtureLog, ms) {
|
|
409
|
+
const quiet = Math.max(25, Number(ms) || 100);
|
|
410
|
+
if (typeof fixtureLog !== 'function') {
|
|
411
|
+
await pause(quiet);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const deadline = Date.now() + quiet * 8;
|
|
415
|
+
let last = -1;
|
|
416
|
+
while (Date.now() < deadline) {
|
|
417
|
+
let length = 0;
|
|
418
|
+
try {
|
|
419
|
+
const entries = await fixtureLog();
|
|
420
|
+
length = Array.isArray(entries) ? entries.length : 0;
|
|
421
|
+
} catch {
|
|
422
|
+
length = Math.max(last, 0);
|
|
423
|
+
}
|
|
424
|
+
if (last >= 0 && length === last) return;
|
|
425
|
+
last = length;
|
|
426
|
+
await pause(quiet);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function leftHome(href, homeUrl) {
|
|
431
|
+
if (!href || !homeUrl) return false;
|
|
432
|
+
if (href === homeUrl) return false;
|
|
433
|
+
try {
|
|
434
|
+
const home = new URL(homeUrl);
|
|
435
|
+
const now = new URL(href);
|
|
436
|
+
if (now.href === home.href) return false;
|
|
437
|
+
if (now.origin === home.origin && now.pathname === home.pathname) return false;
|
|
438
|
+
} catch {
|
|
439
|
+
return href !== homeUrl;
|
|
440
|
+
}
|
|
441
|
+
return true;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async function continueItselfEvidence({ fixtureLog, url, since, tag, proofTag, cookie, handle }) {
|
|
445
|
+
requireAttemptHandle(handle, 'continueItselfEvidence');
|
|
446
|
+
if (!fixtureLog || !url || !cookie || !handle.readerSession) return null;
|
|
447
|
+
const hits = await fixtureHitsFor(fixtureLog, url, since, tag, proofTag);
|
|
448
|
+
if (typeof hits !== 'number' || hits < 1) return null;
|
|
449
|
+
const jar = await capped(readJarWithCanary(handle, cookie), 1500, 'readJar');
|
|
450
|
+
const planted = plantedOf(
|
|
451
|
+
jar?.error?.message?.includes('timeout') ? { incomplete: 'cookie jar unreadable' } : jar
|
|
452
|
+
);
|
|
453
|
+
return { fixtureHits: hits, planted };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async function pollHandleEvidence({
|
|
457
|
+
handle,
|
|
458
|
+
fixtureLog,
|
|
459
|
+
url,
|
|
460
|
+
since,
|
|
461
|
+
tag,
|
|
462
|
+
proofTag,
|
|
463
|
+
cookie,
|
|
464
|
+
settled,
|
|
465
|
+
probedRefusal,
|
|
466
|
+
}) {
|
|
467
|
+
if (!handle) return { probedRefusal, postTriggerRefusal: null, bios: null };
|
|
468
|
+
const bios = await continueItselfEvidence({
|
|
469
|
+
fixtureLog,
|
|
470
|
+
url,
|
|
471
|
+
since,
|
|
472
|
+
tag,
|
|
473
|
+
proofTag,
|
|
474
|
+
cookie,
|
|
475
|
+
handle,
|
|
476
|
+
});
|
|
477
|
+
if (bios) return { probedRefusal, postTriggerRefusal: null, bios };
|
|
478
|
+
if (settled == null || probedRefusal)
|
|
479
|
+
return { probedRefusal, postTriggerRefusal: null, bios: null };
|
|
480
|
+
const postTriggerRefusal = await probePostTriggerRefusal(handle);
|
|
481
|
+
return { probedRefusal: true, postTriggerRefusal, bios: null };
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
async function waitPauseOrBlocked({
|
|
485
|
+
client,
|
|
486
|
+
reader,
|
|
487
|
+
pageTarget,
|
|
488
|
+
pageSession,
|
|
489
|
+
homeUrl,
|
|
490
|
+
from,
|
|
491
|
+
url,
|
|
492
|
+
methods,
|
|
493
|
+
pauseMs,
|
|
494
|
+
triggerPromise,
|
|
495
|
+
blockedMarkers,
|
|
496
|
+
fixtureLog,
|
|
497
|
+
handle,
|
|
498
|
+
tag = null,
|
|
499
|
+
proofTag = null,
|
|
500
|
+
triggerSentAt = null,
|
|
501
|
+
cookie = null,
|
|
502
|
+
}) {
|
|
503
|
+
let settled = null;
|
|
504
|
+
let href = null;
|
|
505
|
+
let postTriggerRefusal = null;
|
|
506
|
+
let probedRefusal = false;
|
|
507
|
+
let fixtureHits = null;
|
|
508
|
+
let planted = null;
|
|
509
|
+
const quietMs = Math.min(150, Math.max(50, Math.floor(pauseMs / 16)));
|
|
510
|
+
const since = triggerSentAt ?? Date.now();
|
|
511
|
+
const triggerDone = Promise.resolve(triggerPromise).then(
|
|
512
|
+
(value) => {
|
|
513
|
+
settled = value;
|
|
514
|
+
return value;
|
|
515
|
+
},
|
|
516
|
+
(error) => {
|
|
517
|
+
settled = { ok: false, error: { message: String(error?.message ?? error) } };
|
|
518
|
+
return settled;
|
|
519
|
+
}
|
|
520
|
+
);
|
|
521
|
+
const deadline = Date.now() + pauseMs;
|
|
522
|
+
const pack = (paused, early) => ({
|
|
523
|
+
paused,
|
|
524
|
+
settled,
|
|
525
|
+
href,
|
|
526
|
+
postTriggerRefusal,
|
|
527
|
+
early,
|
|
528
|
+
fixtureHits,
|
|
529
|
+
planted,
|
|
530
|
+
});
|
|
531
|
+
const finish = async (paused, early, opts = {}) => {
|
|
532
|
+
href = (await readTabHref({ reader, pageTarget })) ?? href;
|
|
533
|
+
if (!probedRefusal && handle && !paused && !opts.skipRefusalProbe) {
|
|
534
|
+
postTriggerRefusal = await probePostTriggerRefusal(handle);
|
|
535
|
+
probedRefusal = true;
|
|
536
|
+
}
|
|
537
|
+
if ((early || paused) && !opts.skipQuiet) await quietFixture(fixtureLog, quietMs);
|
|
538
|
+
return pack(paused, early);
|
|
539
|
+
};
|
|
540
|
+
while (Date.now() < deadline) {
|
|
541
|
+
const paused = pauseEvents(client.events, from, url, methods).at(-1) ?? null;
|
|
542
|
+
if (paused) return finish(paused, false);
|
|
543
|
+
if (settled != null && triggerRefusal(settled) === true) {
|
|
544
|
+
await Promise.race([triggerDone, pause(50)]);
|
|
545
|
+
return finish(null, true);
|
|
546
|
+
}
|
|
547
|
+
href = await readTabHref({ reader, pageTarget });
|
|
548
|
+
if (blockedMarkerHit(href, blockedMarkers)) {
|
|
549
|
+
await Promise.race([triggerDone, pause(50)]);
|
|
550
|
+
return finish(null, true);
|
|
551
|
+
}
|
|
552
|
+
if (readerNetworkBlocked(reader, handle?.readerSession, url, handle?.readerEventFrom ?? 0)) {
|
|
553
|
+
await Promise.race([triggerDone, pause(50)]);
|
|
554
|
+
return finish(null, true);
|
|
555
|
+
}
|
|
556
|
+
const polled = await pollHandleEvidence({
|
|
557
|
+
handle,
|
|
558
|
+
fixtureLog,
|
|
559
|
+
url,
|
|
560
|
+
since,
|
|
561
|
+
tag,
|
|
562
|
+
proofTag,
|
|
563
|
+
cookie,
|
|
564
|
+
settled,
|
|
565
|
+
probedRefusal,
|
|
566
|
+
});
|
|
567
|
+
probedRefusal = polled.probedRefusal;
|
|
568
|
+
if (polled.bios) {
|
|
569
|
+
fixtureHits = polled.bios.fixtureHits;
|
|
570
|
+
planted = polled.bios.planted;
|
|
571
|
+
return finish(null, true, { skipRefusalProbe: true, skipQuiet: true });
|
|
572
|
+
}
|
|
573
|
+
if (polled.postTriggerRefusal) {
|
|
574
|
+
postTriggerRefusal = polled.postTriggerRefusal;
|
|
575
|
+
if (refused(postTriggerRefusal)) return finish(null, true);
|
|
576
|
+
}
|
|
577
|
+
if (settled != null && leftHome(href, homeUrl)) return finish(null, true);
|
|
578
|
+
await Promise.race([triggerDone.then(() => null), pause(25)]);
|
|
579
|
+
}
|
|
580
|
+
settled = settled ?? (await settleTrigger(triggerDone, Math.min(pauseMs, 500)));
|
|
581
|
+
return finish(null, false);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
async function evidenceAfterTrigger({
|
|
585
|
+
handle,
|
|
586
|
+
cookie,
|
|
587
|
+
fixtureLog,
|
|
588
|
+
url,
|
|
589
|
+
tag,
|
|
590
|
+
proofTag,
|
|
591
|
+
startedAt,
|
|
592
|
+
hrefHint,
|
|
593
|
+
}) {
|
|
594
|
+
requireAttemptHandle(handle, 'evidenceAfterTrigger');
|
|
595
|
+
const readerHref =
|
|
596
|
+
hrefHint != null ? hrefHint : await tabHrefFromReader(handle.reader, handle.pageTarget);
|
|
597
|
+
const page = { href: readerHref, ready: readerHref != null };
|
|
598
|
+
const afterTriggerAt = Date.now();
|
|
599
|
+
if (afterTriggerAt < startedAt) {
|
|
600
|
+
return {
|
|
601
|
+
page,
|
|
602
|
+
fixtureHits: await fixtureHitsFor(fixtureLog, url, startedAt, tag, proofTag),
|
|
603
|
+
planted: 'incomplete',
|
|
604
|
+
afterTriggerAt,
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
const cached = handle.blockedEvidence;
|
|
608
|
+
const reusable =
|
|
609
|
+
cached &&
|
|
610
|
+
cached.afterTriggerAt >= startedAt &&
|
|
611
|
+
cached.cookieName === cookie?.name &&
|
|
612
|
+
cached.cookieDomain === cookie?.domain &&
|
|
613
|
+
cached.href === (page.href ?? hrefHint);
|
|
614
|
+
if (reusable) {
|
|
615
|
+
return {
|
|
616
|
+
page: { href: cached.href, ready: true },
|
|
617
|
+
fixtureHits: cached.fixtureHits,
|
|
618
|
+
planted: cached.planted,
|
|
619
|
+
afterTriggerAt: cached.afterTriggerAt,
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
const fixtureHits = await fixtureHitsFor(fixtureLog, url, startedAt, tag, proofTag);
|
|
623
|
+
const jar = await capped(readJarWithCanary(handle, cookie), 1500, 'readJar');
|
|
624
|
+
const planted = plantedOf(
|
|
625
|
+
jar?.error?.message?.includes('timeout') ? { incomplete: 'cookie jar unreadable' } : jar
|
|
626
|
+
);
|
|
627
|
+
handle.blockedEvidence = {
|
|
628
|
+
afterTriggerAt,
|
|
629
|
+
cookieName: cookie?.name,
|
|
630
|
+
cookieDomain: cookie?.domain,
|
|
631
|
+
href: page.href ?? hrefHint ?? null,
|
|
632
|
+
fixtureHits,
|
|
633
|
+
planted,
|
|
634
|
+
};
|
|
635
|
+
return { page, fixtureHits, planted, afterTriggerAt };
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function storageContextParams(browserContextId) {
|
|
639
|
+
return browserContextId ? { browserContextId } : {};
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function contextKey(browserContextId) {
|
|
643
|
+
return browserContextId || null;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function jarContextIncomplete(handle) {
|
|
647
|
+
if (!handle?.browserContexts) return null;
|
|
648
|
+
if (handle.browserContextId == null || handle.browserContextId === '')
|
|
649
|
+
return { incomplete: 'unknown context' };
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
async function resolveTabContextId(reader, targetId, fallback = null) {
|
|
654
|
+
if (!targetId) return fallback ?? null;
|
|
655
|
+
const info = await outcome(reader.send('Target.getTargetInfo', { targetId }));
|
|
656
|
+
return info.result?.targetInfo?.browserContextId || fallback || null;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function canarySpec({ tag, homeUrl }) {
|
|
660
|
+
const host = hostOf(homeUrl);
|
|
661
|
+
const id = String(tag ?? '')
|
|
662
|
+
.replace(/[^a-zA-Z0-9]/g, '')
|
|
663
|
+
.slice(-16);
|
|
664
|
+
let origin = `http://${host}/`;
|
|
665
|
+
try {
|
|
666
|
+
origin = `${new URL(homeUrl).origin}/`;
|
|
667
|
+
} catch {
|
|
668
|
+
origin = `http://${host}/`;
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
name: `cplantcanary${id || 'x'}`,
|
|
672
|
+
value: `canary-${tag}`,
|
|
673
|
+
domain: host,
|
|
674
|
+
path: '/',
|
|
675
|
+
url: origin,
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function requireAttemptHandle(handle, where) {
|
|
680
|
+
if (handle == null || typeof handle !== 'object')
|
|
681
|
+
throw new Error(`cookie-plant.${where}: attempt handle required`);
|
|
682
|
+
if (!Object.prototype.hasOwnProperty.call(handle, 'browserContextId'))
|
|
683
|
+
throw new Error(`cookie-plant.${where}: handle.browserContextId required`);
|
|
684
|
+
if (!handle.reader) throw new Error(`cookie-plant.${where}: handle.reader required`);
|
|
685
|
+
return handle;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
async function plantCanary(handle) {
|
|
689
|
+
requireAttemptHandle(handle, 'plantCanary');
|
|
690
|
+
const unknown = jarContextIncomplete(handle);
|
|
691
|
+
if (unknown) return unknown;
|
|
692
|
+
const canary = handle.canary;
|
|
693
|
+
if (!canary) throw new Error('cookie-plant.plantCanary: handle.canary required');
|
|
694
|
+
const path = canary.path ?? '/';
|
|
695
|
+
await outcome(
|
|
696
|
+
handle.reader.send('Storage.setCookies', {
|
|
697
|
+
...storageContextParams(handle.browserContextId),
|
|
698
|
+
cookies: [
|
|
699
|
+
canary.url
|
|
700
|
+
? { name: canary.name, value: canary.value, url: canary.url, path }
|
|
701
|
+
: { name: canary.name, value: canary.value, domain: canary.domain, path },
|
|
702
|
+
],
|
|
703
|
+
})
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
async function clearCookie(handle, { name, url, domain }) {
|
|
708
|
+
requireAttemptHandle(handle, 'clearCookie');
|
|
709
|
+
const unknown = jarContextIncomplete(handle);
|
|
710
|
+
if (unknown) return unknown;
|
|
711
|
+
const { reader, readerSession: sessionId, browserContextId } = handle;
|
|
712
|
+
await outcome(
|
|
713
|
+
reader.send(
|
|
714
|
+
'Network.deleteCookies',
|
|
715
|
+
{
|
|
716
|
+
name,
|
|
717
|
+
...(url ? { url } : {}),
|
|
718
|
+
...(domain ? { domain } : {}),
|
|
719
|
+
},
|
|
720
|
+
sessionId
|
|
721
|
+
)
|
|
722
|
+
);
|
|
723
|
+
await outcome(
|
|
724
|
+
reader.send('Storage.getCookies', storageContextParams(browserContextId)).then(async (all) => {
|
|
725
|
+
const cookies = (all?.cookies ?? []).filter(
|
|
726
|
+
(cookie) =>
|
|
727
|
+
cookie.name === name &&
|
|
728
|
+
(!domain ||
|
|
729
|
+
cookie.domain.replace(/^\./, '') === domain.replace(/^\./, '') ||
|
|
730
|
+
cookie.domain === domain)
|
|
731
|
+
);
|
|
732
|
+
if (!cookies.length) return;
|
|
733
|
+
await reader.send('Storage.setCookies', {
|
|
734
|
+
...storageContextParams(browserContextId),
|
|
735
|
+
cookies: (all.cookies ?? []).filter((cookie) => !cookies.includes(cookie)),
|
|
736
|
+
});
|
|
737
|
+
})
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
function jarCookieMatch(cookie, { name, domain, value, path }) {
|
|
742
|
+
if (cookie.name !== name) return false;
|
|
743
|
+
const wantDomain = String(domain ?? '')
|
|
744
|
+
.replace(/^\./, '')
|
|
745
|
+
.toLowerCase();
|
|
746
|
+
const got = String(cookie.domain ?? '')
|
|
747
|
+
.replace(/^\./, '')
|
|
748
|
+
.toLowerCase();
|
|
749
|
+
if (got !== wantDomain && !wantDomain.endsWith(`.${got}`) && !got.endsWith(`.${wantDomain}`))
|
|
750
|
+
return false;
|
|
751
|
+
if ((cookie.path ?? '/') !== (path ?? '/')) return false;
|
|
752
|
+
if (value !== undefined && cookie.value !== value) return false;
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function jarUrlHints(cookie, canary = null) {
|
|
757
|
+
const urls = [];
|
|
758
|
+
const pushHost = (host) => {
|
|
759
|
+
const name = String(host ?? '')
|
|
760
|
+
.replace(/^\./, '')
|
|
761
|
+
.toLowerCase();
|
|
762
|
+
if (!name) return;
|
|
763
|
+
urls.push(`https://${name}/`, `http://${name}/`);
|
|
764
|
+
};
|
|
765
|
+
if (cookie?.url) {
|
|
766
|
+
try {
|
|
767
|
+
urls.push(new URL(cookie.url).origin + '/');
|
|
768
|
+
} catch {
|
|
769
|
+
pushHost(cookie.domain);
|
|
770
|
+
}
|
|
771
|
+
} else pushHost(cookie?.domain);
|
|
772
|
+
if (canary?.url) {
|
|
773
|
+
try {
|
|
774
|
+
urls.push(new URL(canary.url).origin + '/');
|
|
775
|
+
} catch {
|
|
776
|
+
pushHost(canary.domain);
|
|
777
|
+
}
|
|
778
|
+
} else pushHost(canary?.domain);
|
|
779
|
+
return [...new Set(urls.filter(Boolean))];
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
async function readJarView(handle, urlHints = []) {
|
|
783
|
+
requireAttemptHandle(handle, 'readJarView');
|
|
784
|
+
const unknown = jarContextIncomplete(handle);
|
|
785
|
+
if (unknown) return unknown;
|
|
786
|
+
const { reader, readerSession: sessionId, browserContextId } = handle;
|
|
787
|
+
const storage = await outcome(
|
|
788
|
+
reader.send('Storage.getCookies', storageContextParams(browserContextId))
|
|
789
|
+
);
|
|
790
|
+
if (storage.ok && Array.isArray(storage.result?.cookies))
|
|
791
|
+
return { via: 'Storage.getCookies', cookies: storage.result.cookies };
|
|
792
|
+
const all = await outcome(reader.send('Network.getAllCookies', {}, sessionId));
|
|
793
|
+
if (all.ok && Array.isArray(all.result?.cookies))
|
|
794
|
+
return { via: 'Network.getAllCookies', cookies: all.result.cookies };
|
|
795
|
+
const urls = urlHints.length ? urlHints : ['https://example.invalid/', 'http://example.invalid/'];
|
|
796
|
+
const byUrl = await outcome(reader.send('Network.getCookies', { urls }, sessionId));
|
|
797
|
+
if (byUrl.ok && Array.isArray(byUrl.result?.cookies))
|
|
798
|
+
return { via: 'Network.getCookies', cookies: byUrl.result.cookies };
|
|
799
|
+
return { incomplete: 'cookie jar unreadable' };
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
async function readJar(handle, { name, domain, value, path }, { urlHints = [] } = {}) {
|
|
803
|
+
requireAttemptHandle(handle, 'readJar');
|
|
804
|
+
const view = await readJarView(handle, urlHints);
|
|
805
|
+
if (view.incomplete) return view;
|
|
806
|
+
const hit = view.cookies.find((cookie) => jarCookieMatch(cookie, { name, domain, value, path }));
|
|
807
|
+
if (hit) return { via: view.via, cookie: hit, cookies: view.cookies };
|
|
808
|
+
return { via: view.via, missing: true, cookies: view.cookies };
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
async function readJarWithCanary(handle, cookie) {
|
|
812
|
+
requireAttemptHandle(handle, 'readJarWithCanary');
|
|
813
|
+
const canary = handle.canary;
|
|
814
|
+
if (!canary) throw new Error('cookie-plant.readJarWithCanary: handle.canary required');
|
|
815
|
+
const urlHints = jarUrlHints(cookie, canary);
|
|
816
|
+
const jar = await readJar(handle, cookie, { urlHints });
|
|
817
|
+
if (jar?.incomplete) return jar;
|
|
818
|
+
const canaryHit = (jar.cookies ?? []).some((entry) =>
|
|
819
|
+
jarCookieMatch(entry, {
|
|
820
|
+
name: canary.name,
|
|
821
|
+
domain: canary.domain,
|
|
822
|
+
value: canary.value,
|
|
823
|
+
path: canary.path ?? '/',
|
|
824
|
+
})
|
|
825
|
+
);
|
|
826
|
+
if (!canaryHit)
|
|
827
|
+
return { incomplete: 'jar view canary absent', via: jar?.via, canaryMissing: true };
|
|
828
|
+
return { ...jar, canaryOk: true };
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function plantedOf(jar) {
|
|
832
|
+
if (!jar || jar.incomplete) return 'incomplete';
|
|
833
|
+
if (jar.missing) return false;
|
|
834
|
+
return true;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
async function triggerFetch(client, sessionId, url) {
|
|
838
|
+
return outcome(
|
|
839
|
+
client.send(
|
|
840
|
+
'Runtime.evaluate',
|
|
841
|
+
{
|
|
842
|
+
expression: `fetch(${JSON.stringify(url)},{credentials:'include'}).then(r=>r.status+' '+r.url,e=>'error:'+e)`,
|
|
843
|
+
awaitPromise: true,
|
|
844
|
+
returnByValue: true,
|
|
845
|
+
},
|
|
846
|
+
sessionId
|
|
847
|
+
)
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
async function triggerNavigate(client, sessionId, url) {
|
|
852
|
+
return outcome(
|
|
853
|
+
client.send(
|
|
854
|
+
'Runtime.evaluate',
|
|
855
|
+
{
|
|
856
|
+
expression: `location.assign(${JSON.stringify(url)})`,
|
|
857
|
+
returnByValue: true,
|
|
858
|
+
},
|
|
859
|
+
sessionId
|
|
860
|
+
)
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
async function capped(promise, ms, label = 'cdp') {
|
|
865
|
+
let timer;
|
|
866
|
+
try {
|
|
867
|
+
return await Promise.race([
|
|
868
|
+
promise,
|
|
869
|
+
new Promise((resolve) => {
|
|
870
|
+
timer = setTimeout(
|
|
871
|
+
() => resolve({ ok: false, error: { message: `${label} timeout` } }),
|
|
872
|
+
ms
|
|
873
|
+
);
|
|
874
|
+
}),
|
|
875
|
+
]);
|
|
876
|
+
} finally {
|
|
877
|
+
clearTimeout(timer);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
async function settleTrigger(promise, budget) {
|
|
882
|
+
return capped(
|
|
883
|
+
promise.then(
|
|
884
|
+
(value) => value,
|
|
885
|
+
(error) => ({ ok: false, error: { message: String(error?.message ?? error) } })
|
|
886
|
+
),
|
|
887
|
+
budget,
|
|
888
|
+
'trigger settle'
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
async function releasePause(client, paused) {
|
|
893
|
+
if (!paused) return { ok: true };
|
|
894
|
+
if (paused.method === 'Fetch.requestPaused' && paused.params?.requestId) {
|
|
895
|
+
return capped(
|
|
896
|
+
outcome(
|
|
897
|
+
client.send(
|
|
898
|
+
'Fetch.failRequest',
|
|
899
|
+
{ requestId: paused.params.requestId, errorReason: 'Aborted' },
|
|
900
|
+
paused.sessionId
|
|
901
|
+
)
|
|
902
|
+
),
|
|
903
|
+
800,
|
|
904
|
+
'releasePause'
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
if (paused.method === 'Network.requestIntercepted' && paused.params?.interceptionId) {
|
|
908
|
+
return capped(
|
|
909
|
+
outcome(
|
|
910
|
+
client.send(
|
|
911
|
+
'Network.continueInterceptedRequest',
|
|
912
|
+
{ interceptionId: paused.params.interceptionId, errorReason: 'Aborted' },
|
|
913
|
+
paused.sessionId
|
|
914
|
+
)
|
|
915
|
+
),
|
|
916
|
+
800,
|
|
917
|
+
'releasePause'
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
return { ok: true };
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
async function drainPauses(client, from = 0) {
|
|
924
|
+
const seen = new Set();
|
|
925
|
+
for (const event of client.events.slice(from)) {
|
|
926
|
+
if (event.method === 'Fetch.requestPaused' && event.params?.requestId) {
|
|
927
|
+
const key = `fetch:${event.params.requestId}`;
|
|
928
|
+
if (seen.has(key)) continue;
|
|
929
|
+
seen.add(key);
|
|
930
|
+
await releasePause(client, event);
|
|
931
|
+
}
|
|
932
|
+
if (event.method === 'Network.requestIntercepted' && event.params?.interceptionId) {
|
|
933
|
+
const key = `legacy:${event.params.interceptionId}`;
|
|
934
|
+
if (seen.has(key)) continue;
|
|
935
|
+
seen.add(key);
|
|
936
|
+
await releasePause(client, event);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
async function withPathBudget(promise, ms, label) {
|
|
942
|
+
let timer;
|
|
943
|
+
try {
|
|
944
|
+
return await Promise.race([
|
|
945
|
+
promise,
|
|
946
|
+
new Promise((_, reject) => {
|
|
947
|
+
timer = setTimeout(() => reject(new Error(`path timeout: ${label}`)), ms);
|
|
948
|
+
}),
|
|
949
|
+
]);
|
|
950
|
+
} finally {
|
|
951
|
+
clearTimeout(timer);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
function pathCeiling(budget) {
|
|
956
|
+
const ms = Number(budget);
|
|
957
|
+
if (!Number.isFinite(ms) || ms <= 0) return 400;
|
|
958
|
+
return Math.min(Math.max(ms * 2, 200), 6000);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function cleanupCeiling(budget = 5000) {
|
|
962
|
+
const ms = Number(budget);
|
|
963
|
+
if (!Number.isFinite(ms) || ms <= 0) return 200;
|
|
964
|
+
return Math.min(Math.max(ms, 200), 2000);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
async function enableFetch(client, pageSession) {
|
|
968
|
+
return capped(
|
|
969
|
+
outcome(
|
|
970
|
+
client.send(
|
|
971
|
+
'Fetch.enable',
|
|
972
|
+
{
|
|
973
|
+
patterns: [
|
|
974
|
+
{ urlPattern: '*', requestStage: 'Request' },
|
|
975
|
+
{ urlPattern: '*', requestStage: 'Response' },
|
|
976
|
+
],
|
|
977
|
+
},
|
|
978
|
+
pageSession
|
|
979
|
+
)
|
|
980
|
+
),
|
|
981
|
+
800,
|
|
982
|
+
'enableFetch'
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
async function ensureInterception(client, pageSession, transport, fetchEnable = null) {
|
|
987
|
+
if (!pageSession || !transport?.kind) return { ok: true };
|
|
988
|
+
if (transport.fetch) {
|
|
989
|
+
if (fetchEnable && (fetchEnable.ok === true || refused(fetchEnable))) return fetchEnable;
|
|
990
|
+
if (fetchEnable && /timeout/i.test(String(fetchEnable.error?.message ?? '')))
|
|
991
|
+
return fetchEnable;
|
|
992
|
+
return enableFetch(client, pageSession);
|
|
993
|
+
}
|
|
994
|
+
if (transport.legacy) return capped(enableLegacy(client, pageSession), 800, 'enableLegacy');
|
|
995
|
+
return { ok: true };
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
async function reattachClient(handle) {
|
|
999
|
+
const { client, reader, pageTarget, homeUrl, transport, internalSessions, notes } = handle;
|
|
1000
|
+
if (!pageTarget) return { ok: false, error: { message: 'missing page target for reattach' } };
|
|
1001
|
+
if (reader && handle.readerSession && homeUrl) {
|
|
1002
|
+
await capped(
|
|
1003
|
+
outcome(reader.send('Page.navigate', { url: homeUrl }, handle.readerSession)),
|
|
1004
|
+
800,
|
|
1005
|
+
'recover-navigate'
|
|
1006
|
+
);
|
|
1007
|
+
await pageReady(reader, handle.readerSession, 1000);
|
|
1008
|
+
}
|
|
1009
|
+
if (handle.pageSession)
|
|
1010
|
+
await capped(
|
|
1011
|
+
outcome(client.send('Target.detachFromTarget', { sessionId: handle.pageSession })),
|
|
1012
|
+
800,
|
|
1013
|
+
'recover-detach'
|
|
1014
|
+
);
|
|
1015
|
+
const attached = await attachClientPage(client, pageTarget, internalSessions);
|
|
1016
|
+
if (!attached.pageSession)
|
|
1017
|
+
return { ok: false, error: { message: attached.incomplete ?? 'reattach failed' } };
|
|
1018
|
+
handle.pageSession = attached.pageSession;
|
|
1019
|
+
let enabled = { ok: true };
|
|
1020
|
+
if (transport?.fetch) enabled = await enableFetch(client, handle.pageSession);
|
|
1021
|
+
else if (transport?.legacy)
|
|
1022
|
+
enabled = await capped(enableLegacy(client, handle.pageSession), 800, 'recover-legacy');
|
|
1023
|
+
note(notes, 'cookie-plant.recover', {
|
|
1024
|
+
pageSession: handle.pageSession,
|
|
1025
|
+
enabled: enabled.ok,
|
|
1026
|
+
cut: sessionCut(enabled),
|
|
1027
|
+
});
|
|
1028
|
+
if (sessionCut(enabled)) return enabled;
|
|
1029
|
+
return enabled.ok ? { ok: true, pageSession: handle.pageSession } : enabled;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
async function ensureLiveSession(handle) {
|
|
1033
|
+
if (!handle?.pageSession) return { ok: false, error: { message: 'missing page session' } };
|
|
1034
|
+
const probe = await capped(
|
|
1035
|
+
outcome(
|
|
1036
|
+
handle.client.send(
|
|
1037
|
+
'Runtime.evaluate',
|
|
1038
|
+
{ expression: '1', returnByValue: true },
|
|
1039
|
+
handle.pageSession
|
|
1040
|
+
)
|
|
1041
|
+
),
|
|
1042
|
+
800,
|
|
1043
|
+
'session-probe'
|
|
1044
|
+
);
|
|
1045
|
+
if (probe.ok) return { ok: true, pageSession: handle.pageSession };
|
|
1046
|
+
return reattachClient(handle);
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
async function ensureInterceptionLive(handle) {
|
|
1050
|
+
const live = await ensureLiveSession(handle);
|
|
1051
|
+
if (!live.ok) return live;
|
|
1052
|
+
const ensure = await ensureInterception(
|
|
1053
|
+
handle.client,
|
|
1054
|
+
handle.pageSession,
|
|
1055
|
+
handle.transport,
|
|
1056
|
+
handle.fetchEnable
|
|
1057
|
+
);
|
|
1058
|
+
if (ensure.ok) return ensure;
|
|
1059
|
+
if (
|
|
1060
|
+
!sessionCut(ensure) &&
|
|
1061
|
+
!/session with given id not found/i.test(String(ensure.error?.message))
|
|
1062
|
+
)
|
|
1063
|
+
return ensure;
|
|
1064
|
+
const recovered = await reattachClient(handle);
|
|
1065
|
+
if (!recovered.ok) return ensure;
|
|
1066
|
+
return ensureInterception(
|
|
1067
|
+
handle.client,
|
|
1068
|
+
handle.pageSession,
|
|
1069
|
+
handle.transport,
|
|
1070
|
+
handle.fetchEnable
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
async function cleanupPath({ handle, paused, from, triggerPromise, budget }) {
|
|
1075
|
+
const { client } = handle;
|
|
1076
|
+
await releasePause(client, paused);
|
|
1077
|
+
await drainPauses(client, from);
|
|
1078
|
+
await settleTrigger(triggerPromise, Math.min(budget, 500));
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function attemptRecord(out, planted) {
|
|
1082
|
+
if (!answered(out))
|
|
1083
|
+
return {
|
|
1084
|
+
answered: 'incomplete',
|
|
1085
|
+
refused: 'incomplete',
|
|
1086
|
+
planted: 'incomplete',
|
|
1087
|
+
};
|
|
1088
|
+
const plantedOut = planted === true ? true : planted === false ? false : 'incomplete';
|
|
1089
|
+
return {
|
|
1090
|
+
answered: true,
|
|
1091
|
+
refused: refused(out),
|
|
1092
|
+
planted: plantedOut,
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
function incompletePlantedAttempt(notes, label, evidence) {
|
|
1097
|
+
note(notes, `cookie-plant.${label}`, {
|
|
1098
|
+
...evidence,
|
|
1099
|
+
incomplete: evidence?.incomplete ?? 'protected plant evidence incomplete',
|
|
1100
|
+
});
|
|
1101
|
+
return {
|
|
1102
|
+
answered: 'incomplete',
|
|
1103
|
+
refused: 'incomplete',
|
|
1104
|
+
planted: 'incomplete',
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
async function fulfillPaused(client, paused, params) {
|
|
1109
|
+
const requestId = paused.params.requestId;
|
|
1110
|
+
const interceptionId = paused.params.interceptionId;
|
|
1111
|
+
if (paused.method === 'Fetch.requestPaused') {
|
|
1112
|
+
return outcome(
|
|
1113
|
+
client.send(
|
|
1114
|
+
'Fetch.fulfillRequest',
|
|
1115
|
+
{ requestId, responseCode: 200, ...params },
|
|
1116
|
+
paused.sessionId
|
|
1117
|
+
)
|
|
1118
|
+
);
|
|
1119
|
+
}
|
|
1120
|
+
if (paused.method === 'Network.requestIntercepted') {
|
|
1121
|
+
const raw =
|
|
1122
|
+
params.rawResponse ??
|
|
1123
|
+
rawHttpResponse({
|
|
1124
|
+
code: params.responseCode ?? 200,
|
|
1125
|
+
phrase: 'OK',
|
|
1126
|
+
headers: Array.isArray(params.responseHeaders)
|
|
1127
|
+
? params.responseHeaders
|
|
1128
|
+
: Object.entries(params.responseHeaders ?? {}).map(([name, value]) => ({ name, value })),
|
|
1129
|
+
body: params.body ? fromB64(params.body) : 'planted',
|
|
1130
|
+
});
|
|
1131
|
+
return outcome(
|
|
1132
|
+
client.send(
|
|
1133
|
+
'Network.continueInterceptedRequest',
|
|
1134
|
+
{ interceptionId, rawResponse: raw },
|
|
1135
|
+
paused.sessionId
|
|
1136
|
+
)
|
|
1137
|
+
);
|
|
1138
|
+
}
|
|
1139
|
+
return { ok: false, error: { message: `unsupported pause ${paused.method}` } };
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
async function pageReady(client, pageSession, ms = 4000) {
|
|
1143
|
+
return waitFor(
|
|
1144
|
+
async () => {
|
|
1145
|
+
const read = await outcome(
|
|
1146
|
+
client.send(
|
|
1147
|
+
'Runtime.evaluate',
|
|
1148
|
+
{ expression: 'document.readyState', returnByValue: true },
|
|
1149
|
+
pageSession
|
|
1150
|
+
)
|
|
1151
|
+
);
|
|
1152
|
+
return read.ok && ['interactive', 'complete'].includes(read.result?.result?.value);
|
|
1153
|
+
},
|
|
1154
|
+
ms,
|
|
1155
|
+
25,
|
|
1156
|
+
true
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
async function restorePage(client, pageSession, homeUrl, transport, reader, readerSession) {
|
|
1161
|
+
if (!homeUrl) return { ok: true };
|
|
1162
|
+
const wasFetch = Boolean(transport?.fetch);
|
|
1163
|
+
const wasLegacy = Boolean(transport?.legacy);
|
|
1164
|
+
try {
|
|
1165
|
+
if (pageSession)
|
|
1166
|
+
await capped(
|
|
1167
|
+
disableInterception(client, pageSession, { fetch: true, legacy: true }),
|
|
1168
|
+
800,
|
|
1169
|
+
'disable'
|
|
1170
|
+
);
|
|
1171
|
+
if (reader && readerSession)
|
|
1172
|
+
await capped(
|
|
1173
|
+
disableInterception(reader, readerSession, { fetch: true, legacy: true }),
|
|
1174
|
+
800,
|
|
1175
|
+
'disable'
|
|
1176
|
+
);
|
|
1177
|
+
const navClient = reader ?? client;
|
|
1178
|
+
const navSession = readerSession ?? pageSession;
|
|
1179
|
+
if (!navSession) return { ok: true };
|
|
1180
|
+
await capped(
|
|
1181
|
+
outcome(navClient.send('Page.navigate', { url: homeUrl }, navSession)),
|
|
1182
|
+
800,
|
|
1183
|
+
'navigate'
|
|
1184
|
+
);
|
|
1185
|
+
await pageReady(navClient, navSession, 1000);
|
|
1186
|
+
} finally {
|
|
1187
|
+
if (pageSession && wasFetch) await enableFetch(client, pageSession);
|
|
1188
|
+
else if (pageSession && wasLegacy)
|
|
1189
|
+
await capped(enableLegacy(client, pageSession), 800, 'reenable');
|
|
1190
|
+
}
|
|
1191
|
+
return { ok: true };
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
async function finishPlant({ out, cookie, notes, label, handle }) {
|
|
1195
|
+
requireAttemptHandle(handle, 'finishPlant');
|
|
1196
|
+
const unknown = jarContextIncomplete(handle);
|
|
1197
|
+
if (unknown) {
|
|
1198
|
+
note(notes, `cookie-plant.${label}`, { ...unknown, ...timingOf(handle) });
|
|
1199
|
+
return attemptRecord(out, 'incomplete');
|
|
1200
|
+
}
|
|
1201
|
+
const jar = await capped(readJarWithCanary(handle, cookie), 1500, 'readJar');
|
|
1202
|
+
const planted = plantedOf(
|
|
1203
|
+
jar?.error?.message?.includes('timeout') ? { incomplete: 'cookie jar unreadable' } : jar
|
|
1204
|
+
);
|
|
1205
|
+
const evidence = {
|
|
1206
|
+
answered: answered(out),
|
|
1207
|
+
refused: refused(out),
|
|
1208
|
+
planted,
|
|
1209
|
+
via: jar?.via,
|
|
1210
|
+
jarIncomplete: jar?.incomplete,
|
|
1211
|
+
...timingOf(handle),
|
|
1212
|
+
};
|
|
1213
|
+
note(notes, `cookie-plant.${label}`, evidence);
|
|
1214
|
+
return attemptRecord(out, planted);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
function blockedMarkerHit(href, markers) {
|
|
1218
|
+
if (typeof href !== 'string' || !href) return false;
|
|
1219
|
+
const list = Array.isArray(markers) ? markers : [];
|
|
1220
|
+
return list.some((marker) => {
|
|
1221
|
+
const m = String(marker ?? '');
|
|
1222
|
+
return m && (href === m || href.startsWith(m));
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
function triggerText(outcome) {
|
|
1227
|
+
if (!outcome || typeof outcome !== 'object') return null;
|
|
1228
|
+
if (outcome.unresolved === true) return null;
|
|
1229
|
+
const value = outcome.result?.result?.value ?? outcome.result?.value;
|
|
1230
|
+
if (typeof value === 'string' && value) return value;
|
|
1231
|
+
if (outcome.ok === false && outcome.error)
|
|
1232
|
+
return String(outcome.error?.message ?? outcome.error ?? '');
|
|
1233
|
+
return null;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
function triggerRefusal(outcome) {
|
|
1237
|
+
if (outcome == null) return 'incomplete';
|
|
1238
|
+
if (outcome === 'incomplete') return 'incomplete';
|
|
1239
|
+
if (typeof outcome === 'object' && outcome.unresolved === true) return 'incomplete';
|
|
1240
|
+
const text = triggerText(outcome);
|
|
1241
|
+
if (text == null) return false;
|
|
1242
|
+
return /slicc:\s*refused:|net::ERR_BLOCKED_BY_CLIENT|ERR_BLOCKED_BY_CLIENT|BlockedByClient|error:BlockedByClient/i.test(
|
|
1243
|
+
text
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function scoreRawOrDoorBranch({
|
|
1248
|
+
evidence,
|
|
1249
|
+
notes,
|
|
1250
|
+
label,
|
|
1251
|
+
planted,
|
|
1252
|
+
rawDoor,
|
|
1253
|
+
doorAbsent,
|
|
1254
|
+
plantSurfaceRefused,
|
|
1255
|
+
handle = null,
|
|
1256
|
+
}) {
|
|
1257
|
+
if (
|
|
1258
|
+
rawDoor &&
|
|
1259
|
+
handle &&
|
|
1260
|
+
Object.hasOwn(rawDoor, 'browserContextId') &&
|
|
1261
|
+
contextKey(rawDoor.browserContextId) !== contextKey(handle.browserContextId)
|
|
1262
|
+
) {
|
|
1263
|
+
note(notes, `cookie-plant.${label}`, {
|
|
1264
|
+
...evidence,
|
|
1265
|
+
incomplete: 'raw/guarded browserContext mismatch',
|
|
1266
|
+
rawBrowserContextId: rawDoor.browserContextId ?? null,
|
|
1267
|
+
browserContextId: handle.browserContextId ?? null,
|
|
1268
|
+
});
|
|
1269
|
+
return {
|
|
1270
|
+
answered: 'incomplete',
|
|
1271
|
+
refused: 'incomplete',
|
|
1272
|
+
planted: planted === true ? true : 'incomplete',
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
if (rawDoor && !doorAbsentOf(rawDoor) && (rawDoor.incomplete || rawDoor.observed !== true)) {
|
|
1276
|
+
note(notes, `cookie-plant.${label}`, {
|
|
1277
|
+
...evidence,
|
|
1278
|
+
incomplete: 'raw leg incomplete',
|
|
1279
|
+
});
|
|
1280
|
+
return {
|
|
1281
|
+
answered: 'incomplete',
|
|
1282
|
+
refused: 'incomplete',
|
|
1283
|
+
planted: planted === true ? true : 'incomplete',
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
if (plantSurfaceRefused) {
|
|
1287
|
+
if (planted === true) {
|
|
1288
|
+
note(notes, `cookie-plant.${label}`, {
|
|
1289
|
+
...evidence,
|
|
1290
|
+
answered: true,
|
|
1291
|
+
refused: true,
|
|
1292
|
+
note: 'Fetch.enable refused: interception plant surface refused',
|
|
1293
|
+
});
|
|
1294
|
+
return { answered: true, refused: true, planted: true };
|
|
1295
|
+
}
|
|
1296
|
+
if (planted === false) {
|
|
1297
|
+
note(notes, `cookie-plant.${label}`, {
|
|
1298
|
+
...evidence,
|
|
1299
|
+
answered: true,
|
|
1300
|
+
refused: true,
|
|
1301
|
+
note: 'Fetch.enable refused: interception plant surface refused',
|
|
1302
|
+
});
|
|
1303
|
+
return { answered: true, refused: true, planted: false };
|
|
1304
|
+
}
|
|
1305
|
+
return incompletePlantedAttempt(notes, label, {
|
|
1306
|
+
...evidence,
|
|
1307
|
+
note: 'Fetch.enable refused: interception plant surface refused',
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
if (!doorAbsent) return null;
|
|
1311
|
+
note(notes, `cookie-plant.${label}`, {
|
|
1312
|
+
...evidence,
|
|
1313
|
+
note: 'door not present on this browser',
|
|
1314
|
+
});
|
|
1315
|
+
if (planted === true) return { answered: true, refused: false, planted: true };
|
|
1316
|
+
if (planted === false) return { answered: true, refused: false, planted: false };
|
|
1317
|
+
return incompletePlantedAttempt(notes, label, evidence);
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function protectedPlantSignals({
|
|
1321
|
+
pauseCount,
|
|
1322
|
+
fixtureHits,
|
|
1323
|
+
planted,
|
|
1324
|
+
pageHref,
|
|
1325
|
+
triggerOutcome,
|
|
1326
|
+
blockedMarkers,
|
|
1327
|
+
postTriggerRefusal,
|
|
1328
|
+
triggerIssued,
|
|
1329
|
+
fetchEnableOk,
|
|
1330
|
+
doorAbsent,
|
|
1331
|
+
rawDoor,
|
|
1332
|
+
readerBlocked,
|
|
1333
|
+
}) {
|
|
1334
|
+
const href = pageHref == null ? null : String(pageHref);
|
|
1335
|
+
const onMarker = blockedMarkerHit(href, blockedMarkers);
|
|
1336
|
+
const refusal = triggerRefusal(triggerOutcome);
|
|
1337
|
+
const sessionBlocked = Boolean(triggerIssued && postTriggerRefusal === true);
|
|
1338
|
+
const blockSeen = Boolean(onMarker === true || readerBlocked === true);
|
|
1339
|
+
const issuedAndBlocked =
|
|
1340
|
+
refusal === 'incomplete'
|
|
1341
|
+
? 'incomplete'
|
|
1342
|
+
: Boolean(blockSeen || refusal === true || sessionBlocked);
|
|
1343
|
+
const loadBlocked =
|
|
1344
|
+
fixtureHits === 'incomplete' || issuedAndBlocked === 'incomplete'
|
|
1345
|
+
? 'incomplete'
|
|
1346
|
+
: issuedAndBlocked === true && fixtureHits === 0;
|
|
1347
|
+
const rawPremise =
|
|
1348
|
+
Boolean(rawDoor) &&
|
|
1349
|
+
!doorAbsent &&
|
|
1350
|
+
rawDoor.observed === true &&
|
|
1351
|
+
rawDoor.answered === true &&
|
|
1352
|
+
rawDoor.planted === true;
|
|
1353
|
+
const shapeD =
|
|
1354
|
+
Boolean(triggerIssued) &&
|
|
1355
|
+
pauseCount === 0 &&
|
|
1356
|
+
fixtureHits === 0 &&
|
|
1357
|
+
planted === false &&
|
|
1358
|
+
rawPremise &&
|
|
1359
|
+
blockSeen &&
|
|
1360
|
+
fetchEnableOk === true;
|
|
1361
|
+
return {
|
|
1362
|
+
href,
|
|
1363
|
+
onMarker,
|
|
1364
|
+
refusal,
|
|
1365
|
+
sessionBlocked,
|
|
1366
|
+
blockSeen,
|
|
1367
|
+
issuedAndBlocked,
|
|
1368
|
+
loadBlocked,
|
|
1369
|
+
shapeD,
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
function scoreProtectedPlant({
|
|
1374
|
+
pauseCount,
|
|
1375
|
+
fixtureHits,
|
|
1376
|
+
planted,
|
|
1377
|
+
pageHref,
|
|
1378
|
+
notes,
|
|
1379
|
+
label,
|
|
1380
|
+
triggerOutcome,
|
|
1381
|
+
blockedMarkers,
|
|
1382
|
+
postTriggerRefusal = false,
|
|
1383
|
+
triggerIssued = false,
|
|
1384
|
+
handle,
|
|
1385
|
+
fetchEnableOk = null,
|
|
1386
|
+
doorAbsent = false,
|
|
1387
|
+
rawDoor = null,
|
|
1388
|
+
plantSurfaceRefused = false,
|
|
1389
|
+
readerBlocked = false,
|
|
1390
|
+
}) {
|
|
1391
|
+
const signals = protectedPlantSignals({
|
|
1392
|
+
pauseCount,
|
|
1393
|
+
fixtureHits,
|
|
1394
|
+
planted,
|
|
1395
|
+
pageHref,
|
|
1396
|
+
triggerOutcome,
|
|
1397
|
+
blockedMarkers,
|
|
1398
|
+
postTriggerRefusal,
|
|
1399
|
+
triggerIssued,
|
|
1400
|
+
fetchEnableOk,
|
|
1401
|
+
doorAbsent,
|
|
1402
|
+
rawDoor,
|
|
1403
|
+
readerBlocked,
|
|
1404
|
+
});
|
|
1405
|
+
const {
|
|
1406
|
+
href,
|
|
1407
|
+
onMarker,
|
|
1408
|
+
refusal,
|
|
1409
|
+
sessionBlocked,
|
|
1410
|
+
blockSeen,
|
|
1411
|
+
issuedAndBlocked,
|
|
1412
|
+
loadBlocked,
|
|
1413
|
+
shapeD,
|
|
1414
|
+
} = signals;
|
|
1415
|
+
const evidence = {
|
|
1416
|
+
pauseCount,
|
|
1417
|
+
fixtureHits,
|
|
1418
|
+
planted,
|
|
1419
|
+
pageHref: href,
|
|
1420
|
+
onMarker,
|
|
1421
|
+
readerBlocked: Boolean(readerBlocked),
|
|
1422
|
+
triggerRefused: refusal,
|
|
1423
|
+
postTriggerRefusal: sessionBlocked,
|
|
1424
|
+
triggerIssued: Boolean(triggerIssued),
|
|
1425
|
+
issuedAndBlocked,
|
|
1426
|
+
loadBlocked,
|
|
1427
|
+
shapeD,
|
|
1428
|
+
fetchEnableOk,
|
|
1429
|
+
doorAbsent: Boolean(doorAbsent),
|
|
1430
|
+
plantSurfaceRefused: Boolean(plantSurfaceRefused),
|
|
1431
|
+
...(rawDoor
|
|
1432
|
+
? {
|
|
1433
|
+
rawAnswered: rawDoor.answered,
|
|
1434
|
+
rawPlanted: rawDoor.planted,
|
|
1435
|
+
rawTimedOut: rawDoor.timedOut,
|
|
1436
|
+
rawObserved: rawDoor.observed === true,
|
|
1437
|
+
rawIncomplete: Boolean(rawDoor.incomplete),
|
|
1438
|
+
}
|
|
1439
|
+
: {}),
|
|
1440
|
+
...timingOf(handle),
|
|
1441
|
+
};
|
|
1442
|
+
const early = scoreRawOrDoorBranch({
|
|
1443
|
+
evidence,
|
|
1444
|
+
notes,
|
|
1445
|
+
label,
|
|
1446
|
+
planted,
|
|
1447
|
+
rawDoor,
|
|
1448
|
+
doorAbsent,
|
|
1449
|
+
plantSurfaceRefused,
|
|
1450
|
+
handle,
|
|
1451
|
+
});
|
|
1452
|
+
if (early) return early;
|
|
1453
|
+
if (planted === true) {
|
|
1454
|
+
const refused = pauseCount > 0 || sessionBlocked || blockSeen;
|
|
1455
|
+
note(notes, `cookie-plant.${label}`, { ...evidence, answered: true, refused });
|
|
1456
|
+
return { answered: true, refused, planted: true };
|
|
1457
|
+
}
|
|
1458
|
+
if (
|
|
1459
|
+
(planted !== true && planted !== false) ||
|
|
1460
|
+
pauseCount === 'incomplete' ||
|
|
1461
|
+
fixtureHits === 'incomplete' ||
|
|
1462
|
+
loadBlocked === 'incomplete' ||
|
|
1463
|
+
issuedAndBlocked === 'incomplete'
|
|
1464
|
+
) {
|
|
1465
|
+
return incompletePlantedAttempt(notes, label, evidence);
|
|
1466
|
+
}
|
|
1467
|
+
if (shapeD) {
|
|
1468
|
+
note(notes, `cookie-plant.${label}`, {
|
|
1469
|
+
...evidence,
|
|
1470
|
+
answered: true,
|
|
1471
|
+
refused: true,
|
|
1472
|
+
note: 'guard blocks the request itself',
|
|
1473
|
+
});
|
|
1474
|
+
return { answered: true, refused: true, planted: false };
|
|
1475
|
+
}
|
|
1476
|
+
if (pauseCount === 0 && loadBlocked === true && planted === false) {
|
|
1477
|
+
if (fetchEnableOk === false) {
|
|
1478
|
+
return incompletePlantedAttempt(notes, label, {
|
|
1479
|
+
...evidence,
|
|
1480
|
+
incomplete: 'Fetch.enable unanswered for bios-shape',
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
note(notes, `cookie-plant.${label}`, { ...evidence, answered: true, refused: true });
|
|
1484
|
+
return { answered: true, refused: true, planted: false };
|
|
1485
|
+
}
|
|
1486
|
+
if (
|
|
1487
|
+
pauseCount === 0 &&
|
|
1488
|
+
typeof fixtureHits === 'number' &&
|
|
1489
|
+
fixtureHits >= 1 &&
|
|
1490
|
+
planted === false
|
|
1491
|
+
) {
|
|
1492
|
+
if (fetchEnableOk !== true) {
|
|
1493
|
+
return incompletePlantedAttempt(notes, label, {
|
|
1494
|
+
...evidence,
|
|
1495
|
+
incomplete: 'Fetch.enable unanswered for continue-itself',
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
note(notes, `cookie-plant.${label}`, {
|
|
1499
|
+
...evidence,
|
|
1500
|
+
answered: true,
|
|
1501
|
+
refused: true,
|
|
1502
|
+
note: 'continue-itself: guard continued the protected request',
|
|
1503
|
+
});
|
|
1504
|
+
return { answered: true, refused: true, planted: false };
|
|
1505
|
+
}
|
|
1506
|
+
return incompletePlantedAttempt(notes, label, evidence);
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
async function fixtureHitsFor(fixtureLog, url, since, tag, proofTag) {
|
|
1510
|
+
if (typeof fixtureLog !== 'function') return 'incomplete';
|
|
1511
|
+
let entries;
|
|
1512
|
+
try {
|
|
1513
|
+
entries = await fixtureLog();
|
|
1514
|
+
} catch {
|
|
1515
|
+
return 'incomplete';
|
|
1516
|
+
}
|
|
1517
|
+
if (!Array.isArray(entries)) return 'incomplete';
|
|
1518
|
+
if (entries.length === 0) return 'incomplete';
|
|
1519
|
+
const proof = proofTag ? String(proofTag) : '';
|
|
1520
|
+
if (proof) {
|
|
1521
|
+
const seen = entries.some((entry) => String(entry?.url ?? '').includes(proof));
|
|
1522
|
+
if (!seen) return 'incomplete';
|
|
1523
|
+
}
|
|
1524
|
+
const afterSince = entries.filter((entry) => Number(entry?.time ?? 0) >= since);
|
|
1525
|
+
const needle = tag ? String(tag) : '';
|
|
1526
|
+
const matched = afterSince.filter((entry) => {
|
|
1527
|
+
const hit = String(entry?.url ?? '');
|
|
1528
|
+
if (!(hit === url || hit.startsWith(url) || (url && hit.startsWith(String(url).split('?')[0]))))
|
|
1529
|
+
return false;
|
|
1530
|
+
if (!needle) return true;
|
|
1531
|
+
return hit.includes(needle);
|
|
1532
|
+
});
|
|
1533
|
+
return matched.length;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
async function recordSessionCut({ handle, cookie, notes, label, out }) {
|
|
1537
|
+
requireAttemptHandle(handle, 'recordSessionCut');
|
|
1538
|
+
return finishPlant({
|
|
1539
|
+
handle,
|
|
1540
|
+
out: out ?? {
|
|
1541
|
+
ok: false,
|
|
1542
|
+
error: { message: 'slicc: refused: session cut on protected execution context' },
|
|
1543
|
+
},
|
|
1544
|
+
cookie,
|
|
1545
|
+
notes,
|
|
1546
|
+
label,
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
async function probePostTriggerRefusal(handle) {
|
|
1551
|
+
const { client, pageTarget, pageSession, internalSessions } = handle;
|
|
1552
|
+
if (pageSession) {
|
|
1553
|
+
const enabled = await capped(
|
|
1554
|
+
outcome(client.send('Page.enable', {}, pageSession)),
|
|
1555
|
+
800,
|
|
1556
|
+
'post-Page.enable'
|
|
1557
|
+
);
|
|
1558
|
+
if (refused(enabled)) return enabled;
|
|
1559
|
+
const fetchEnabled = await capped(
|
|
1560
|
+
outcome(
|
|
1561
|
+
client.send(
|
|
1562
|
+
'Fetch.enable',
|
|
1563
|
+
{
|
|
1564
|
+
patterns: [
|
|
1565
|
+
{ urlPattern: '*', requestStage: 'Request' },
|
|
1566
|
+
{ urlPattern: '*', requestStage: 'Response' },
|
|
1567
|
+
],
|
|
1568
|
+
},
|
|
1569
|
+
pageSession
|
|
1570
|
+
)
|
|
1571
|
+
),
|
|
1572
|
+
800,
|
|
1573
|
+
'post-Fetch.enable'
|
|
1574
|
+
);
|
|
1575
|
+
if (refused(fetchEnabled)) return fetchEnabled;
|
|
1576
|
+
}
|
|
1577
|
+
if (!pageTarget) return null;
|
|
1578
|
+
const attached = await capped(
|
|
1579
|
+
outcome(client.send('Target.attachToTarget', { targetId: pageTarget, flatten: true })),
|
|
1580
|
+
800,
|
|
1581
|
+
'post-attach'
|
|
1582
|
+
);
|
|
1583
|
+
if (refused(attached)) return attached;
|
|
1584
|
+
const sessionId = attached.result?.sessionId;
|
|
1585
|
+
if (!sessionId) return null;
|
|
1586
|
+
internalSessions?.add(sessionId);
|
|
1587
|
+
const enabled = await capped(
|
|
1588
|
+
outcome(client.send('Page.enable', {}, sessionId)),
|
|
1589
|
+
800,
|
|
1590
|
+
'post-attach-Page.enable'
|
|
1591
|
+
);
|
|
1592
|
+
return refused(enabled) ? enabled : null;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
async function runPlantBody({
|
|
1596
|
+
handle,
|
|
1597
|
+
url,
|
|
1598
|
+
cookie,
|
|
1599
|
+
build,
|
|
1600
|
+
budget,
|
|
1601
|
+
notes,
|
|
1602
|
+
label,
|
|
1603
|
+
stage,
|
|
1604
|
+
topLevel,
|
|
1605
|
+
fixtureLog,
|
|
1606
|
+
legAt,
|
|
1607
|
+
firstIncomplete,
|
|
1608
|
+
from,
|
|
1609
|
+
pauseMs,
|
|
1610
|
+
startedAt,
|
|
1611
|
+
state,
|
|
1612
|
+
}) {
|
|
1613
|
+
const { client, transport } = handle;
|
|
1614
|
+
await capped(clearCookie(handle, cookie), 800, 'clearCookie');
|
|
1615
|
+
const ensure = await ensureInterceptionLive(handle);
|
|
1616
|
+
const pageSession = handle.pageSession;
|
|
1617
|
+
if (sessionCut(ensure)) return recordSessionCut({ handle, cookie, notes, label });
|
|
1618
|
+
if (!ensure.ok) {
|
|
1619
|
+
await diagnoseIncomplete({
|
|
1620
|
+
notes,
|
|
1621
|
+
label,
|
|
1622
|
+
incomplete: String(ensure.error?.message ?? 'ensure failed'),
|
|
1623
|
+
url,
|
|
1624
|
+
client,
|
|
1625
|
+
pageSession,
|
|
1626
|
+
from,
|
|
1627
|
+
methods:
|
|
1628
|
+
transport.kind === 'legacy' ? ['Network.requestIntercepted'] : ['Fetch.requestPaused'],
|
|
1629
|
+
pauseMs,
|
|
1630
|
+
startedAt,
|
|
1631
|
+
legStartedAt: legAt,
|
|
1632
|
+
fixtureLog,
|
|
1633
|
+
ensure,
|
|
1634
|
+
trigger: null,
|
|
1635
|
+
firstIncomplete,
|
|
1636
|
+
});
|
|
1637
|
+
return attemptRecord(
|
|
1638
|
+
{ ok: false, error: ensure.error ?? { message: 'ensure failed' } },
|
|
1639
|
+
'incomplete'
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
const methods =
|
|
1643
|
+
transport.kind === 'legacy' ? ['Network.requestIntercepted'] : ['Fetch.requestPaused'];
|
|
1644
|
+
state.triggerPromise = topLevel
|
|
1645
|
+
? triggerNavigate(client, pageSession, url)
|
|
1646
|
+
: triggerFetch(client, pageSession, url);
|
|
1647
|
+
state.paused = await waitPause(client, from, url, methods, pauseMs);
|
|
1648
|
+
if (!state.paused) {
|
|
1649
|
+
const trigger = await settleTrigger(state.triggerPromise, Math.min(budget, 500));
|
|
1650
|
+
state.triggerPromise = Promise.resolve(trigger);
|
|
1651
|
+
await diagnoseIncomplete({
|
|
1652
|
+
notes,
|
|
1653
|
+
label,
|
|
1654
|
+
incomplete: 'no pause',
|
|
1655
|
+
url,
|
|
1656
|
+
client,
|
|
1657
|
+
pageSession,
|
|
1658
|
+
from,
|
|
1659
|
+
methods,
|
|
1660
|
+
pauseMs,
|
|
1661
|
+
startedAt,
|
|
1662
|
+
legStartedAt: legAt,
|
|
1663
|
+
fixtureLog,
|
|
1664
|
+
ensure,
|
|
1665
|
+
trigger,
|
|
1666
|
+
firstIncomplete,
|
|
1667
|
+
});
|
|
1668
|
+
return attemptRecord({ ok: false, error: { message: 'timeout: no pause' } }, 'incomplete');
|
|
1669
|
+
}
|
|
1670
|
+
if (
|
|
1671
|
+
transport.kind === 'fetch' &&
|
|
1672
|
+
stage === 'Response' &&
|
|
1673
|
+
state.paused.params?.responseStatusCode === undefined &&
|
|
1674
|
+
state.paused.params?.responseErrorReason === undefined
|
|
1675
|
+
) {
|
|
1676
|
+
const responseFrom = client.events.length;
|
|
1677
|
+
await capped(
|
|
1678
|
+
outcome(
|
|
1679
|
+
client.send(
|
|
1680
|
+
'Fetch.continueRequest',
|
|
1681
|
+
{ requestId: state.paused.params.requestId },
|
|
1682
|
+
state.paused.sessionId
|
|
1683
|
+
)
|
|
1684
|
+
),
|
|
1685
|
+
800,
|
|
1686
|
+
'continueRequest'
|
|
1687
|
+
);
|
|
1688
|
+
const again = await waitPause(client, responseFrom, url, methods, pauseMs);
|
|
1689
|
+
if (!again) {
|
|
1690
|
+
const trigger = await settleTrigger(state.triggerPromise, Math.min(budget, 500));
|
|
1691
|
+
state.triggerPromise = Promise.resolve(trigger);
|
|
1692
|
+
await diagnoseIncomplete({
|
|
1693
|
+
notes,
|
|
1694
|
+
label,
|
|
1695
|
+
incomplete: 'no response pause',
|
|
1696
|
+
url,
|
|
1697
|
+
client,
|
|
1698
|
+
pageSession,
|
|
1699
|
+
from: responseFrom,
|
|
1700
|
+
methods,
|
|
1701
|
+
pauseMs,
|
|
1702
|
+
startedAt,
|
|
1703
|
+
legStartedAt: legAt,
|
|
1704
|
+
fixtureLog,
|
|
1705
|
+
ensure,
|
|
1706
|
+
trigger,
|
|
1707
|
+
firstIncomplete,
|
|
1708
|
+
});
|
|
1709
|
+
return attemptRecord(
|
|
1710
|
+
{ ok: false, error: { message: 'timeout: no response pause' } },
|
|
1711
|
+
'incomplete'
|
|
1712
|
+
);
|
|
1713
|
+
}
|
|
1714
|
+
state.paused = again;
|
|
1715
|
+
}
|
|
1716
|
+
const out = await capped(build(state.paused).send(client, state.paused), 1500, 'plant-send');
|
|
1717
|
+
if (sessionCut(out)) return recordSessionCut({ handle, cookie, notes, label });
|
|
1718
|
+
return finishPlant({ out, cookie, notes, label, handle });
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
function fetchEnableOkOf(handle) {
|
|
1722
|
+
if (handle.fetchEnable == null) return null;
|
|
1723
|
+
if (handle.fetchEnable.ok === true) return true;
|
|
1724
|
+
if (refused(handle.fetchEnable)) return null;
|
|
1725
|
+
return false;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
function markScored(handle, scored) {
|
|
1729
|
+
if (scored.planted === 'incomplete') handle.evidenceIncomplete = true;
|
|
1730
|
+
return scored;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
async function scoreDoorAbsentPause({
|
|
1734
|
+
handle,
|
|
1735
|
+
client,
|
|
1736
|
+
reader,
|
|
1737
|
+
readerSession,
|
|
1738
|
+
cookie,
|
|
1739
|
+
notes,
|
|
1740
|
+
label,
|
|
1741
|
+
from,
|
|
1742
|
+
url,
|
|
1743
|
+
methods,
|
|
1744
|
+
waited,
|
|
1745
|
+
out,
|
|
1746
|
+
state,
|
|
1747
|
+
blockedMarkers,
|
|
1748
|
+
fetchEnableOk,
|
|
1749
|
+
rawDoor,
|
|
1750
|
+
fixtureLog,
|
|
1751
|
+
tag,
|
|
1752
|
+
proofTag,
|
|
1753
|
+
startedAt,
|
|
1754
|
+
}) {
|
|
1755
|
+
const jar = await capped(readJarWithCanary(handle, cookie), 1500, 'readJar');
|
|
1756
|
+
const planted = plantedOf(
|
|
1757
|
+
jar?.error?.message?.includes('timeout') ? { incomplete: 'cookie jar unreadable' } : jar
|
|
1758
|
+
);
|
|
1759
|
+
const fixtureHits = await fixtureHitsFor(fixtureLog, url, startedAt, tag, proofTag);
|
|
1760
|
+
return markScored(
|
|
1761
|
+
handle,
|
|
1762
|
+
scoreProtectedPlant({
|
|
1763
|
+
pauseCount: pauseEvents(client.events, from, url, methods).length,
|
|
1764
|
+
fixtureHits,
|
|
1765
|
+
planted,
|
|
1766
|
+
pageHref: waited.href ?? null,
|
|
1767
|
+
notes,
|
|
1768
|
+
label,
|
|
1769
|
+
triggerOutcome: out,
|
|
1770
|
+
blockedMarkers,
|
|
1771
|
+
handle,
|
|
1772
|
+
postTriggerRefusal: state.postTriggerRefusal || refused(out),
|
|
1773
|
+
triggerIssued: true,
|
|
1774
|
+
fetchEnableOk,
|
|
1775
|
+
doorAbsent: true,
|
|
1776
|
+
rawDoor,
|
|
1777
|
+
})
|
|
1778
|
+
);
|
|
1779
|
+
}
|
|
1780
|
+
|
|
1781
|
+
async function scorePausedGuardedPlant(args) {
|
|
1782
|
+
const {
|
|
1783
|
+
handle,
|
|
1784
|
+
client,
|
|
1785
|
+
reader,
|
|
1786
|
+
readerSession,
|
|
1787
|
+
cookie,
|
|
1788
|
+
build,
|
|
1789
|
+
budget,
|
|
1790
|
+
notes,
|
|
1791
|
+
label,
|
|
1792
|
+
from,
|
|
1793
|
+
url,
|
|
1794
|
+
methods,
|
|
1795
|
+
waited,
|
|
1796
|
+
state,
|
|
1797
|
+
blockedMarkers,
|
|
1798
|
+
fetchEnableOk,
|
|
1799
|
+
doorAbsent,
|
|
1800
|
+
rawDoor,
|
|
1801
|
+
fixtureLog,
|
|
1802
|
+
tag,
|
|
1803
|
+
proofTag,
|
|
1804
|
+
startedAt,
|
|
1805
|
+
} = args;
|
|
1806
|
+
const plantCap = doorAbsent ? Math.min(budget, 1500) : 1500;
|
|
1807
|
+
const out = await capped(build(state.paused).send(client, state.paused), plantCap, 'plant-send');
|
|
1808
|
+
if (sessionCut(out)) {
|
|
1809
|
+
const jar = await capped(readJarWithCanary(handle, cookie), 1500, 'readJar');
|
|
1810
|
+
const planted = plantedOf(
|
|
1811
|
+
jar?.error?.message?.includes('timeout') ? { incomplete: 'cookie jar unreadable' } : jar
|
|
1812
|
+
);
|
|
1813
|
+
const fixtureHits = await fixtureHitsFor(fixtureLog, url, startedAt, tag, proofTag);
|
|
1814
|
+
return markScored(
|
|
1815
|
+
handle,
|
|
1816
|
+
scoreProtectedPlant({
|
|
1817
|
+
pauseCount: pauseEvents(client.events, from, url, methods).length,
|
|
1818
|
+
fixtureHits,
|
|
1819
|
+
planted,
|
|
1820
|
+
pageHref: waited.href ?? null,
|
|
1821
|
+
notes,
|
|
1822
|
+
label,
|
|
1823
|
+
triggerOutcome: out,
|
|
1824
|
+
blockedMarkers,
|
|
1825
|
+
handle,
|
|
1826
|
+
postTriggerRefusal: true,
|
|
1827
|
+
triggerIssued: true,
|
|
1828
|
+
fetchEnableOk,
|
|
1829
|
+
doorAbsent,
|
|
1830
|
+
rawDoor,
|
|
1831
|
+
})
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
if (doorAbsent)
|
|
1835
|
+
return scoreDoorAbsentPause({
|
|
1836
|
+
handle,
|
|
1837
|
+
client,
|
|
1838
|
+
reader,
|
|
1839
|
+
readerSession,
|
|
1840
|
+
cookie,
|
|
1841
|
+
notes,
|
|
1842
|
+
label,
|
|
1843
|
+
from,
|
|
1844
|
+
url,
|
|
1845
|
+
methods,
|
|
1846
|
+
waited,
|
|
1847
|
+
out,
|
|
1848
|
+
state,
|
|
1849
|
+
blockedMarkers,
|
|
1850
|
+
fetchEnableOk,
|
|
1851
|
+
rawDoor,
|
|
1852
|
+
fixtureLog,
|
|
1853
|
+
tag,
|
|
1854
|
+
proofTag,
|
|
1855
|
+
startedAt,
|
|
1856
|
+
});
|
|
1857
|
+
const jar = await capped(readJarWithCanary(handle, cookie), 1500, 'readJar');
|
|
1858
|
+
const planted = plantedOf(
|
|
1859
|
+
jar?.error?.message?.includes('timeout') ? { incomplete: 'cookie jar unreadable' } : jar
|
|
1860
|
+
);
|
|
1861
|
+
if (planted === true) {
|
|
1862
|
+
return markScored(
|
|
1863
|
+
handle,
|
|
1864
|
+
scoreProtectedPlant({
|
|
1865
|
+
pauseCount: pauseEvents(client.events, from, url, methods).length,
|
|
1866
|
+
fixtureHits: await fixtureHitsFor(fixtureLog, url, startedAt, tag, proofTag),
|
|
1867
|
+
planted: true,
|
|
1868
|
+
pageHref: waited.href ?? null,
|
|
1869
|
+
notes,
|
|
1870
|
+
label,
|
|
1871
|
+
triggerOutcome: out,
|
|
1872
|
+
blockedMarkers,
|
|
1873
|
+
handle,
|
|
1874
|
+
postTriggerRefusal: state.postTriggerRefusal || refused(out),
|
|
1875
|
+
triggerIssued: true,
|
|
1876
|
+
fetchEnableOk,
|
|
1877
|
+
doorAbsent,
|
|
1878
|
+
rawDoor,
|
|
1879
|
+
})
|
|
1880
|
+
);
|
|
1881
|
+
}
|
|
1882
|
+
const settled =
|
|
1883
|
+
waited.settled ?? (await settleTrigger(state.triggerPromise, Math.min(budget, 500)));
|
|
1884
|
+
const evidence = await evidenceAfterTrigger({
|
|
1885
|
+
handle,
|
|
1886
|
+
cookie,
|
|
1887
|
+
fixtureLog,
|
|
1888
|
+
url,
|
|
1889
|
+
tag,
|
|
1890
|
+
proofTag,
|
|
1891
|
+
startedAt,
|
|
1892
|
+
hrefHint: waited.href,
|
|
1893
|
+
});
|
|
1894
|
+
return markScored(
|
|
1895
|
+
handle,
|
|
1896
|
+
scoreProtectedPlant({
|
|
1897
|
+
pauseCount: pauseEvents(client.events, from, url, methods).length,
|
|
1898
|
+
fixtureHits: evidence.fixtureHits,
|
|
1899
|
+
planted: evidence.planted === true ? true : planted,
|
|
1900
|
+
pageHref: evidence.page.href ?? waited.href,
|
|
1901
|
+
notes,
|
|
1902
|
+
label,
|
|
1903
|
+
triggerOutcome: settled,
|
|
1904
|
+
blockedMarkers,
|
|
1905
|
+
handle,
|
|
1906
|
+
postTriggerRefusal: state.postTriggerRefusal || refused(out),
|
|
1907
|
+
triggerIssued: true,
|
|
1908
|
+
fetchEnableOk,
|
|
1909
|
+
doorAbsent,
|
|
1910
|
+
rawDoor,
|
|
1911
|
+
})
|
|
1912
|
+
);
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
async function scoreUnpausedGuardedPlant(args) {
|
|
1916
|
+
const {
|
|
1917
|
+
handle,
|
|
1918
|
+
client,
|
|
1919
|
+
cookie,
|
|
1920
|
+
budget,
|
|
1921
|
+
notes,
|
|
1922
|
+
label,
|
|
1923
|
+
from,
|
|
1924
|
+
url,
|
|
1925
|
+
methods,
|
|
1926
|
+
waited,
|
|
1927
|
+
state,
|
|
1928
|
+
blockedMarkers,
|
|
1929
|
+
fetchEnableOk,
|
|
1930
|
+
doorAbsent,
|
|
1931
|
+
rawDoor,
|
|
1932
|
+
fixtureLog,
|
|
1933
|
+
tag,
|
|
1934
|
+
proofTag,
|
|
1935
|
+
startedAt,
|
|
1936
|
+
} = args;
|
|
1937
|
+
const settled =
|
|
1938
|
+
waited.settled ?? (await settleTrigger(state.triggerPromise, Math.min(budget, 500)));
|
|
1939
|
+
const hung =
|
|
1940
|
+
settled &&
|
|
1941
|
+
settled.ok === false &&
|
|
1942
|
+
/trigger settle timeout/i.test(String(settled.error?.message ?? ''));
|
|
1943
|
+
if (hung) handle.evidenceIncomplete = true;
|
|
1944
|
+
const evidence =
|
|
1945
|
+
waited.fixtureHits != null && waited.planted != null
|
|
1946
|
+
? {
|
|
1947
|
+
page: { href: waited.href ?? null, ready: true },
|
|
1948
|
+
fixtureHits: waited.fixtureHits,
|
|
1949
|
+
planted: waited.planted,
|
|
1950
|
+
afterTriggerAt: Date.now(),
|
|
1951
|
+
}
|
|
1952
|
+
: await evidenceAfterTrigger({
|
|
1953
|
+
handle,
|
|
1954
|
+
cookie,
|
|
1955
|
+
fixtureLog,
|
|
1956
|
+
url,
|
|
1957
|
+
tag,
|
|
1958
|
+
proofTag,
|
|
1959
|
+
startedAt,
|
|
1960
|
+
hrefHint: waited.href,
|
|
1961
|
+
});
|
|
1962
|
+
if (evidence.planted === 'incomplete') handle.evidenceIncomplete = true;
|
|
1963
|
+
const pageHref = await readTabHref({
|
|
1964
|
+
reader: handle.reader,
|
|
1965
|
+
pageTarget: handle.pageTarget,
|
|
1966
|
+
});
|
|
1967
|
+
const readerBlocked = readerNetworkBlocked(
|
|
1968
|
+
handle.reader,
|
|
1969
|
+
handle.readerSession,
|
|
1970
|
+
url,
|
|
1971
|
+
handle.readerEventFrom ?? 0
|
|
1972
|
+
);
|
|
1973
|
+
return markScored(
|
|
1974
|
+
handle,
|
|
1975
|
+
scoreProtectedPlant({
|
|
1976
|
+
pauseCount: hung ? 'incomplete' : pauseEvents(client.events, from, url, methods).length,
|
|
1977
|
+
fixtureHits: hung ? 'incomplete' : evidence.fixtureHits,
|
|
1978
|
+
planted: hung ? 'incomplete' : evidence.planted,
|
|
1979
|
+
pageHref,
|
|
1980
|
+
notes,
|
|
1981
|
+
label,
|
|
1982
|
+
triggerOutcome: hung ? { unresolved: true } : settled,
|
|
1983
|
+
blockedMarkers,
|
|
1984
|
+
handle,
|
|
1985
|
+
postTriggerRefusal: state.postTriggerRefusal || refused(waited.postTriggerRefusal),
|
|
1986
|
+
triggerIssued: true,
|
|
1987
|
+
fetchEnableOk,
|
|
1988
|
+
doorAbsent,
|
|
1989
|
+
rawDoor,
|
|
1990
|
+
readerBlocked,
|
|
1991
|
+
})
|
|
1992
|
+
);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
async function runGuardedProtectedPlantBody({
|
|
1996
|
+
handle,
|
|
1997
|
+
url,
|
|
1998
|
+
cookie,
|
|
1999
|
+
build,
|
|
2000
|
+
budget,
|
|
2001
|
+
notes,
|
|
2002
|
+
label,
|
|
2003
|
+
topLevel,
|
|
2004
|
+
fixtureLog,
|
|
2005
|
+
tag,
|
|
2006
|
+
from,
|
|
2007
|
+
pauseMs,
|
|
2008
|
+
state,
|
|
2009
|
+
blockedMarkers,
|
|
2010
|
+
proofTag,
|
|
2011
|
+
rawDoor = null,
|
|
2012
|
+
}) {
|
|
2013
|
+
const { client, reader, readerSession, transport } = handle;
|
|
2014
|
+
const doorAbsent = doorAbsentOf(rawDoor);
|
|
2015
|
+
const fetchEnableOk = fetchEnableOkOf(handle);
|
|
2016
|
+
if (refused(handle.fetchEnable)) {
|
|
2017
|
+
handle.evidenceIncomplete = false;
|
|
2018
|
+
await capped(clearCookie(handle, cookie), 800, 'clearCookie');
|
|
2019
|
+
const jar = await capped(readJarWithCanary(handle, cookie), 1500, 'readJar');
|
|
2020
|
+
return scoreProtectedPlant({
|
|
2021
|
+
pauseCount: 0,
|
|
2022
|
+
fixtureHits: await fixtureHitsFor(fixtureLog, url, Number.POSITIVE_INFINITY, tag, proofTag),
|
|
2023
|
+
planted: plantedOf(jar),
|
|
2024
|
+
pageHref: null,
|
|
2025
|
+
notes,
|
|
2026
|
+
label,
|
|
2027
|
+
triggerOutcome: handle.fetchEnable,
|
|
2028
|
+
blockedMarkers,
|
|
2029
|
+
handle,
|
|
2030
|
+
postTriggerRefusal: false,
|
|
2031
|
+
triggerIssued: false,
|
|
2032
|
+
fetchEnableOk: null,
|
|
2033
|
+
doorAbsent,
|
|
2034
|
+
rawDoor,
|
|
2035
|
+
plantSurfaceRefused: true,
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
if (!handle.pageSession) {
|
|
2039
|
+
handle.evidenceIncomplete = true;
|
|
2040
|
+
return scoreProtectedPlant({
|
|
2041
|
+
pauseCount: 'incomplete',
|
|
2042
|
+
fixtureHits: 'incomplete',
|
|
2043
|
+
planted: 'incomplete',
|
|
2044
|
+
pageHref: null,
|
|
2045
|
+
notes,
|
|
2046
|
+
label,
|
|
2047
|
+
triggerOutcome: { unresolved: true },
|
|
2048
|
+
blockedMarkers,
|
|
2049
|
+
handle,
|
|
2050
|
+
fetchEnableOk,
|
|
2051
|
+
doorAbsent,
|
|
2052
|
+
rawDoor,
|
|
2053
|
+
});
|
|
2054
|
+
}
|
|
2055
|
+
await capped(clearCookie(handle, cookie), 800, 'clearCookie');
|
|
2056
|
+
const methods =
|
|
2057
|
+
transport.kind === 'legacy' ? ['Network.requestIntercepted'] : ['Fetch.requestPaused'];
|
|
2058
|
+
state.triggerIssued = true;
|
|
2059
|
+
const triggerSentAt = Date.now();
|
|
2060
|
+
handle.triggerSentAt = triggerSentAt;
|
|
2061
|
+
handle.readerEventFrom = handle.reader?.events?.length ?? 0;
|
|
2062
|
+
state.triggerPromise = topLevel
|
|
2063
|
+
? triggerNavigate(client, handle.pageSession, url)
|
|
2064
|
+
: triggerFetch(client, handle.pageSession, url);
|
|
2065
|
+
const waited = await waitPauseOrBlocked({
|
|
2066
|
+
client,
|
|
2067
|
+
reader,
|
|
2068
|
+
pageTarget: handle.pageTarget,
|
|
2069
|
+
pageSession: handle.pageSession,
|
|
2070
|
+
homeUrl: handle.homeUrl,
|
|
2071
|
+
from,
|
|
2072
|
+
url,
|
|
2073
|
+
methods,
|
|
2074
|
+
pauseMs: Math.max(pauseMs, pathCeiling(budget)),
|
|
2075
|
+
triggerPromise: state.triggerPromise,
|
|
2076
|
+
blockedMarkers,
|
|
2077
|
+
fixtureLog,
|
|
2078
|
+
handle,
|
|
2079
|
+
tag,
|
|
2080
|
+
proofTag,
|
|
2081
|
+
triggerSentAt,
|
|
2082
|
+
cookie,
|
|
2083
|
+
});
|
|
2084
|
+
state.paused = waited.paused;
|
|
2085
|
+
state.postTriggerRefusal = refused(waited.postTriggerRefusal);
|
|
2086
|
+
const shared = {
|
|
2087
|
+
handle,
|
|
2088
|
+
client,
|
|
2089
|
+
reader,
|
|
2090
|
+
readerSession,
|
|
2091
|
+
cookie,
|
|
2092
|
+
build,
|
|
2093
|
+
budget,
|
|
2094
|
+
notes,
|
|
2095
|
+
label,
|
|
2096
|
+
from,
|
|
2097
|
+
url,
|
|
2098
|
+
methods,
|
|
2099
|
+
waited,
|
|
2100
|
+
state,
|
|
2101
|
+
blockedMarkers,
|
|
2102
|
+
fetchEnableOk,
|
|
2103
|
+
doorAbsent,
|
|
2104
|
+
rawDoor,
|
|
2105
|
+
fixtureLog,
|
|
2106
|
+
tag,
|
|
2107
|
+
proofTag,
|
|
2108
|
+
startedAt: triggerSentAt,
|
|
2109
|
+
};
|
|
2110
|
+
if (state.paused) return scorePausedGuardedPlant(shared);
|
|
2111
|
+
return scoreUnpausedGuardedPlant(shared);
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
async function runPlant({
|
|
2115
|
+
handle,
|
|
2116
|
+
url,
|
|
2117
|
+
cookie,
|
|
2118
|
+
build,
|
|
2119
|
+
budget,
|
|
2120
|
+
notes,
|
|
2121
|
+
label,
|
|
2122
|
+
stage = 'Request',
|
|
2123
|
+
topLevel = true,
|
|
2124
|
+
fixtureLog,
|
|
2125
|
+
legStartedAt,
|
|
2126
|
+
firstIncomplete,
|
|
2127
|
+
protectedBlock = false,
|
|
2128
|
+
tag,
|
|
2129
|
+
blockedMarkers,
|
|
2130
|
+
proofTag,
|
|
2131
|
+
rawDoor = null,
|
|
2132
|
+
}) {
|
|
2133
|
+
const { client, transport } = handle;
|
|
2134
|
+
const state = { paused: null, triggerPromise: Promise.resolve() };
|
|
2135
|
+
const from = client.events.length;
|
|
2136
|
+
const pauseMs = Math.min(budget, protectedBlock ? 1200 : 2000);
|
|
2137
|
+
const startedAt = Date.now();
|
|
2138
|
+
const legAt = legStartedAt ?? startedAt;
|
|
2139
|
+
try {
|
|
2140
|
+
return await withPathBudget(
|
|
2141
|
+
protectedBlock
|
|
2142
|
+
? runGuardedProtectedPlantBody({
|
|
2143
|
+
handle,
|
|
2144
|
+
url,
|
|
2145
|
+
cookie,
|
|
2146
|
+
build,
|
|
2147
|
+
budget,
|
|
2148
|
+
notes,
|
|
2149
|
+
label,
|
|
2150
|
+
topLevel,
|
|
2151
|
+
fixtureLog,
|
|
2152
|
+
tag,
|
|
2153
|
+
from,
|
|
2154
|
+
pauseMs,
|
|
2155
|
+
state,
|
|
2156
|
+
blockedMarkers,
|
|
2157
|
+
proofTag,
|
|
2158
|
+
rawDoor,
|
|
2159
|
+
})
|
|
2160
|
+
: runPlantBody({
|
|
2161
|
+
handle,
|
|
2162
|
+
url,
|
|
2163
|
+
cookie,
|
|
2164
|
+
build,
|
|
2165
|
+
budget,
|
|
2166
|
+
notes,
|
|
2167
|
+
label,
|
|
2168
|
+
stage,
|
|
2169
|
+
topLevel,
|
|
2170
|
+
fixtureLog,
|
|
2171
|
+
legAt,
|
|
2172
|
+
firstIncomplete,
|
|
2173
|
+
from,
|
|
2174
|
+
pauseMs,
|
|
2175
|
+
startedAt,
|
|
2176
|
+
state,
|
|
2177
|
+
}),
|
|
2178
|
+
pathCeiling(budget),
|
|
2179
|
+
label
|
|
2180
|
+
);
|
|
2181
|
+
} catch (error) {
|
|
2182
|
+
if (sessionCut({ ok: false, error })) return recordSessionCut({ handle, cookie, notes, label });
|
|
2183
|
+
if (protectedBlock) {
|
|
2184
|
+
const since = handle.triggerSentAt ?? Number.POSITIVE_INFINITY;
|
|
2185
|
+
const fixtureHits = await fixtureHitsFor(fixtureLog, url, since, tag, proofTag);
|
|
2186
|
+
const jar = await capped(readJarWithCanary(handle, cookie), 1500, 'readJar');
|
|
2187
|
+
const planted = plantedOf(
|
|
2188
|
+
jar?.error?.message?.includes('timeout') ? { incomplete: 'cookie jar unreadable' } : jar
|
|
2189
|
+
);
|
|
2190
|
+
const pageHref = await readTabHref({
|
|
2191
|
+
reader: handle.reader,
|
|
2192
|
+
pageTarget: handle.pageTarget,
|
|
2193
|
+
});
|
|
2194
|
+
const scored = scoreProtectedPlant({
|
|
2195
|
+
pauseCount: 'incomplete',
|
|
2196
|
+
fixtureHits,
|
|
2197
|
+
planted,
|
|
2198
|
+
pageHref,
|
|
2199
|
+
notes,
|
|
2200
|
+
label,
|
|
2201
|
+
triggerOutcome: { unresolved: true },
|
|
2202
|
+
blockedMarkers,
|
|
2203
|
+
handle,
|
|
2204
|
+
readerBlocked: readerNetworkBlocked(
|
|
2205
|
+
handle.reader,
|
|
2206
|
+
handle.readerSession,
|
|
2207
|
+
url,
|
|
2208
|
+
handle.readerEventFrom ?? 0
|
|
2209
|
+
),
|
|
2210
|
+
});
|
|
2211
|
+
if (scored.planted === 'incomplete') handle.evidenceIncomplete = true;
|
|
2212
|
+
return scored;
|
|
2213
|
+
}
|
|
2214
|
+
await diagnoseIncomplete({
|
|
2215
|
+
notes,
|
|
2216
|
+
label,
|
|
2217
|
+
incomplete: String(error?.message ?? error),
|
|
2218
|
+
url,
|
|
2219
|
+
client,
|
|
2220
|
+
pageSession: handle.pageSession,
|
|
2221
|
+
from,
|
|
2222
|
+
methods:
|
|
2223
|
+
transport?.kind === 'legacy' ? ['Network.requestIntercepted'] : ['Fetch.requestPaused'],
|
|
2224
|
+
pauseMs,
|
|
2225
|
+
startedAt,
|
|
2226
|
+
legStartedAt: legAt,
|
|
2227
|
+
fixtureLog,
|
|
2228
|
+
ensure: null,
|
|
2229
|
+
trigger: null,
|
|
2230
|
+
firstIncomplete,
|
|
2231
|
+
});
|
|
2232
|
+
return attemptRecord(
|
|
2233
|
+
{ ok: false, error: { message: String(error?.message ?? error) } },
|
|
2234
|
+
'incomplete'
|
|
2235
|
+
);
|
|
2236
|
+
} finally {
|
|
2237
|
+
try {
|
|
2238
|
+
await withPathBudget(
|
|
2239
|
+
cleanupPath({
|
|
2240
|
+
handle,
|
|
2241
|
+
paused: state.paused,
|
|
2242
|
+
from,
|
|
2243
|
+
triggerPromise: state.triggerPromise,
|
|
2244
|
+
budget,
|
|
2245
|
+
}),
|
|
2246
|
+
cleanupCeiling(budget),
|
|
2247
|
+
`${label}:cleanup`
|
|
2248
|
+
);
|
|
2249
|
+
} catch (error) {
|
|
2250
|
+
note(notes, `cookie-plant.${label}`, {
|
|
2251
|
+
cleanup: String(error?.message ?? error),
|
|
2252
|
+
});
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
|
|
2257
|
+
function fetchFulfill(params) {
|
|
2258
|
+
return {
|
|
2259
|
+
send: (client, paused) =>
|
|
2260
|
+
outcome(
|
|
2261
|
+
client.send(
|
|
2262
|
+
'Fetch.fulfillRequest',
|
|
2263
|
+
{
|
|
2264
|
+
requestId: paused.params.requestId,
|
|
2265
|
+
responseCode: params.responseCode ?? 200,
|
|
2266
|
+
...params,
|
|
2267
|
+
},
|
|
2268
|
+
paused.sessionId
|
|
2269
|
+
)
|
|
2270
|
+
),
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
function fetchContinueResponse(params) {
|
|
2275
|
+
return {
|
|
2276
|
+
send: (client, paused) =>
|
|
2277
|
+
outcome(
|
|
2278
|
+
client.send(
|
|
2279
|
+
'Fetch.continueResponse',
|
|
2280
|
+
{
|
|
2281
|
+
requestId: paused.params.requestId,
|
|
2282
|
+
responseCode: params.responseCode ?? paused.params.responseStatusCode ?? 200,
|
|
2283
|
+
...params,
|
|
2284
|
+
},
|
|
2285
|
+
paused.sessionId
|
|
2286
|
+
)
|
|
2287
|
+
),
|
|
2288
|
+
};
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
function legacyContinue(params) {
|
|
2292
|
+
return {
|
|
2293
|
+
send: (client, paused) =>
|
|
2294
|
+
outcome(
|
|
2295
|
+
client.send(
|
|
2296
|
+
'Network.continueInterceptedRequest',
|
|
2297
|
+
{
|
|
2298
|
+
interceptionId: paused.params.interceptionId,
|
|
2299
|
+
...params,
|
|
2300
|
+
},
|
|
2301
|
+
paused.sessionId
|
|
2302
|
+
)
|
|
2303
|
+
),
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
function flattenAttempt(prefix, attempt) {
|
|
2308
|
+
const out = {
|
|
2309
|
+
[`${prefix}Answered`]: attempt.answered,
|
|
2310
|
+
[`${prefix}Refused`]: attempt.refused,
|
|
2311
|
+
[`${prefix}Planted`]: attempt.planted,
|
|
2312
|
+
};
|
|
2313
|
+
if (attempt.cleared !== undefined) out[`${prefix}Cleared`] = attempt.cleared;
|
|
2314
|
+
return out;
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
async function proveDoor({
|
|
2318
|
+
reader,
|
|
2319
|
+
sessionId,
|
|
2320
|
+
protectedOrigin,
|
|
2321
|
+
homeUrl,
|
|
2322
|
+
tag,
|
|
2323
|
+
budget,
|
|
2324
|
+
notes,
|
|
2325
|
+
transport,
|
|
2326
|
+
plantName,
|
|
2327
|
+
browserContextId = null,
|
|
2328
|
+
browserContexts = false,
|
|
2329
|
+
}) {
|
|
2330
|
+
let paused = null;
|
|
2331
|
+
let triggerPromise = Promise.resolve();
|
|
2332
|
+
const from = reader.events.length;
|
|
2333
|
+
const host = hostOf(protectedOrigin);
|
|
2334
|
+
const domain = `.${host}`;
|
|
2335
|
+
const url = `${protectedOrigin}/data?n=door-${tag}`;
|
|
2336
|
+
const cookie = {
|
|
2337
|
+
name: plantName,
|
|
2338
|
+
value: `door-${tag}`,
|
|
2339
|
+
domain,
|
|
2340
|
+
url: `${protectedOrigin}/`,
|
|
2341
|
+
};
|
|
2342
|
+
const canary = canarySpec({ tag, homeUrl });
|
|
2343
|
+
const jarHandle = {
|
|
2344
|
+
reader,
|
|
2345
|
+
readerSession: sessionId,
|
|
2346
|
+
browserContextId,
|
|
2347
|
+
browserContexts: Boolean(browserContexts),
|
|
2348
|
+
canary,
|
|
2349
|
+
};
|
|
2350
|
+
requireAttemptHandle(jarHandle, 'proveDoor');
|
|
2351
|
+
if (jarContextIncomplete(jarHandle))
|
|
2352
|
+
return { incomplete: 'unknown context', browserContextId: browserContextId ?? null };
|
|
2353
|
+
try {
|
|
2354
|
+
return await withPathBudget(
|
|
2355
|
+
(async () => {
|
|
2356
|
+
await capped(clearCookie(jarHandle, cookie), 800, 'door-clear');
|
|
2357
|
+
await plantCanary(jarHandle);
|
|
2358
|
+
if (transport.kind === 'fetch') {
|
|
2359
|
+
await capped(
|
|
2360
|
+
outcome(
|
|
2361
|
+
reader.send(
|
|
2362
|
+
'Fetch.enable',
|
|
2363
|
+
{
|
|
2364
|
+
patterns: [
|
|
2365
|
+
{ urlPattern: '*', requestStage: 'Request' },
|
|
2366
|
+
{ urlPattern: '*', requestStage: 'Response' },
|
|
2367
|
+
],
|
|
2368
|
+
},
|
|
2369
|
+
sessionId
|
|
2370
|
+
)
|
|
2371
|
+
),
|
|
2372
|
+
800,
|
|
2373
|
+
'door-enable'
|
|
2374
|
+
);
|
|
2375
|
+
} else {
|
|
2376
|
+
await capped(enableLegacy(reader, sessionId), 800, 'door-enable');
|
|
2377
|
+
}
|
|
2378
|
+
triggerPromise = triggerNavigate(reader, sessionId, url);
|
|
2379
|
+
const methods =
|
|
2380
|
+
transport.kind === 'legacy' ? ['Network.requestIntercepted'] : ['Fetch.requestPaused'];
|
|
2381
|
+
paused = await waitPause(reader, from, url, methods, Math.min(budget, 2000));
|
|
2382
|
+
if (!paused) {
|
|
2383
|
+
return { live: false, incomplete: 'raw leg: no pause for top-level plant navigation' };
|
|
2384
|
+
}
|
|
2385
|
+
const setCookie = cookieHeader(plantName, cookie.value, domain);
|
|
2386
|
+
const out = await capped(
|
|
2387
|
+
fulfillPaused(reader, paused, {
|
|
2388
|
+
responseCode: 200,
|
|
2389
|
+
responseHeaders: [
|
|
2390
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
2391
|
+
{ name: 'Set-Cookie', value: setCookie },
|
|
2392
|
+
],
|
|
2393
|
+
body: b64text(`door-${tag}`),
|
|
2394
|
+
}),
|
|
2395
|
+
1500,
|
|
2396
|
+
'door-fulfill'
|
|
2397
|
+
);
|
|
2398
|
+
if (refused(out) || !out.ok) await releasePause(reader, paused);
|
|
2399
|
+
await settleTrigger(triggerPromise, Math.min(budget, 500));
|
|
2400
|
+
const jar = await capped(readJarWithCanary(jarHandle, cookie), 1500, 'door-jar');
|
|
2401
|
+
const planted = plantedOf(
|
|
2402
|
+
jar?.error?.message?.includes('timeout') ? { incomplete: 'cookie jar unreadable' } : jar
|
|
2403
|
+
);
|
|
2404
|
+
note(notes, 'cookie-plant.door', {
|
|
2405
|
+
answered: answered(out),
|
|
2406
|
+
planted,
|
|
2407
|
+
via: jar?.via,
|
|
2408
|
+
domain,
|
|
2409
|
+
browserContextId,
|
|
2410
|
+
});
|
|
2411
|
+
await capped(clearCookie(jarHandle, cookie), 800, 'door-clear');
|
|
2412
|
+
if (!answered(out))
|
|
2413
|
+
return { live: false, incomplete: `raw leg: fulfill unanswered: ${out.error?.message}` };
|
|
2414
|
+
if (planted === 'incomplete')
|
|
2415
|
+
return {
|
|
2416
|
+
live: false,
|
|
2417
|
+
incomplete: jar?.canaryMissing
|
|
2418
|
+
? 'raw leg: jar view canary absent'
|
|
2419
|
+
: 'raw leg: cookie jar unreadable after plant',
|
|
2420
|
+
};
|
|
2421
|
+
if (!planted)
|
|
2422
|
+
return {
|
|
2423
|
+
live: false,
|
|
2424
|
+
incomplete: 'raw leg: Chrome did not store Domain=.<protected host> Set-Cookie',
|
|
2425
|
+
};
|
|
2426
|
+
return { live: true, doorVia: jar.via, browserContextId };
|
|
2427
|
+
})(),
|
|
2428
|
+
Math.min(Math.max(budget * 3, 800), 12000),
|
|
2429
|
+
'door'
|
|
2430
|
+
);
|
|
2431
|
+
} catch (error) {
|
|
2432
|
+
note(notes, 'cookie-plant.door', { incomplete: String(error?.message ?? error) });
|
|
2433
|
+
return { live: false, incomplete: `raw leg: ${String(error?.message ?? error)}` };
|
|
2434
|
+
} finally {
|
|
2435
|
+
try {
|
|
2436
|
+
await withPathBudget(
|
|
2437
|
+
(async () => {
|
|
2438
|
+
await releasePause(reader, paused);
|
|
2439
|
+
await drainPauses(reader, from);
|
|
2440
|
+
await settleTrigger(triggerPromise, Math.min(budget, 500));
|
|
2441
|
+
await capped(disableInterception(reader, sessionId, transport), 800, 'door-disable');
|
|
2442
|
+
await capped(restorePage(reader, sessionId, homeUrl), 1500, 'door-restore');
|
|
2443
|
+
})(),
|
|
2444
|
+
cleanupCeiling(budget),
|
|
2445
|
+
'door:cleanup'
|
|
2446
|
+
);
|
|
2447
|
+
} catch (error) {
|
|
2448
|
+
note(notes, 'cookie-plant.door', { cleanup: String(error?.message ?? error) });
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
const EMPTY_ATTEMPT = {
|
|
2454
|
+
answered: 'incomplete',
|
|
2455
|
+
refused: 'incomplete',
|
|
2456
|
+
planted: 'incomplete',
|
|
2457
|
+
};
|
|
2458
|
+
|
|
2459
|
+
const FETCH_PATH_NAMES = [
|
|
2460
|
+
'fulfillArray',
|
|
2461
|
+
'fulfillObject',
|
|
2462
|
+
'fulfillLower',
|
|
2463
|
+
'fulfillSetCookie2',
|
|
2464
|
+
'fulfillNewline',
|
|
2465
|
+
'fulfillBinary',
|
|
2466
|
+
'continueResponse',
|
|
2467
|
+
'redirect3xx',
|
|
2468
|
+
'binaryLf',
|
|
2469
|
+
'binaryObsFold',
|
|
2470
|
+
'domainQuoted',
|
|
2471
|
+
'domainUpper',
|
|
2472
|
+
'domainTrailDot',
|
|
2473
|
+
'domainRepeated',
|
|
2474
|
+
'domainWs',
|
|
2475
|
+
'headerPadded',
|
|
2476
|
+
'setCookieSecond',
|
|
2477
|
+
'responsePhrase',
|
|
2478
|
+
'continueAtRequest',
|
|
2479
|
+
];
|
|
2480
|
+
|
|
2481
|
+
const CREDENTIAL_PATH_NAMES = ['hostOnly', 'domainCover', 'subHost'];
|
|
2482
|
+
|
|
2483
|
+
const ALL_PATH_NAMES = [
|
|
2484
|
+
...FETCH_PATH_NAMES,
|
|
2485
|
+
...CREDENTIAL_PATH_NAMES,
|
|
2486
|
+
'legacyHeaders',
|
|
2487
|
+
'legacyRaw',
|
|
2488
|
+
'ordinary',
|
|
2489
|
+
'deletion',
|
|
2490
|
+
'adobe',
|
|
2491
|
+
];
|
|
2492
|
+
|
|
2493
|
+
function incompletePaths() {
|
|
2494
|
+
return Object.fromEntries(
|
|
2495
|
+
ALL_PATH_NAMES.flatMap((name) => [
|
|
2496
|
+
[`${name}Answered`, 'incomplete'],
|
|
2497
|
+
[`${name}Refused`, 'incomplete'],
|
|
2498
|
+
[`${name}Planted`, 'incomplete'],
|
|
2499
|
+
])
|
|
2500
|
+
);
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
function notSupportedAttempt() {
|
|
2504
|
+
return {
|
|
2505
|
+
answered: 'not-supported',
|
|
2506
|
+
refused: 'not-supported',
|
|
2507
|
+
planted: 'not-supported',
|
|
2508
|
+
};
|
|
2509
|
+
}
|
|
2510
|
+
|
|
2511
|
+
function plantCtx(fields) {
|
|
2512
|
+
return { ...fields };
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
function timingOf(handle, pathStartedAt = null) {
|
|
2516
|
+
const t = handle?.timing ?? {};
|
|
2517
|
+
const elapsedMs =
|
|
2518
|
+
t.firstSent != null ? Math.max(0, (t.firstReply ?? Date.now()) - t.firstSent) : null;
|
|
2519
|
+
const started = pathStartedAt ?? t.pathStartedAt ?? null;
|
|
2520
|
+
return {
|
|
2521
|
+
firstSentAt: t.firstSent ?? null,
|
|
2522
|
+
firstReplyAt: t.firstReply ?? null,
|
|
2523
|
+
elapsedMs,
|
|
2524
|
+
pathStartedAt: started,
|
|
2525
|
+
pathElapsedMs: started != null ? Math.max(0, Date.now() - started) : null,
|
|
2526
|
+
};
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
function timedClient(client, timing) {
|
|
2530
|
+
return {
|
|
2531
|
+
...client,
|
|
2532
|
+
get events() {
|
|
2533
|
+
return client.events;
|
|
2534
|
+
},
|
|
2535
|
+
send: async (method, params, sessionId) => {
|
|
2536
|
+
if (timing.firstSent == null) timing.firstSent = Date.now();
|
|
2537
|
+
try {
|
|
2538
|
+
const result = await client.send(method, params, sessionId);
|
|
2539
|
+
if (timing.firstReply == null) timing.firstReply = Date.now();
|
|
2540
|
+
return result;
|
|
2541
|
+
} catch (error) {
|
|
2542
|
+
if (timing.firstReply == null) timing.firstReply = Date.now();
|
|
2543
|
+
throw error;
|
|
2544
|
+
}
|
|
2545
|
+
},
|
|
2546
|
+
};
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
async function withFreshAttemptTab(ctx, run) {
|
|
2550
|
+
const { client, reader, homeUrl, notes, internalSessions, browserContextId } = ctx;
|
|
2551
|
+
const page = await openPage(reader, homeUrl, notes, internalSessions, browserContextId);
|
|
2552
|
+
if (!page.ok)
|
|
2553
|
+
return attemptRecord(
|
|
2554
|
+
{ ok: false, error: { message: `open failed: ${page.error?.message ?? page.error}` } },
|
|
2555
|
+
'incomplete'
|
|
2556
|
+
);
|
|
2557
|
+
if (page.result?.incomplete)
|
|
2558
|
+
return attemptRecord({ ok: false, error: { message: page.result.incomplete } }, 'incomplete');
|
|
2559
|
+
const readerSession = page.result.sessionId;
|
|
2560
|
+
const pageTarget = page.result.targetId;
|
|
2561
|
+
const timing = { pathStartedAt: Date.now() };
|
|
2562
|
+
const attached = await attachClientPage(client, pageTarget, internalSessions);
|
|
2563
|
+
if (attached.incomplete) {
|
|
2564
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
2565
|
+
return attemptRecord({ ok: false, error: { message: attached.incomplete } }, 'incomplete');
|
|
2566
|
+
}
|
|
2567
|
+
if (attached.refused && refused(attached.refused)) {
|
|
2568
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
2569
|
+
return attemptRecord(attached.refused, 'incomplete');
|
|
2570
|
+
}
|
|
2571
|
+
const pageSession = attached.pageSession;
|
|
2572
|
+
if (!pageSession) {
|
|
2573
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
2574
|
+
return attemptRecord(
|
|
2575
|
+
{ ok: false, error: { message: 'client has no page session for interception attempts' } },
|
|
2576
|
+
'incomplete'
|
|
2577
|
+
);
|
|
2578
|
+
}
|
|
2579
|
+
const enabled = await enableClientTransport(client, pageSession, notes);
|
|
2580
|
+
if (enabled.incomplete) {
|
|
2581
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
2582
|
+
return attemptRecord({ ok: false, error: { message: enabled.incomplete } }, 'incomplete');
|
|
2583
|
+
}
|
|
2584
|
+
const tabContextId = await resolveTabContextId(reader, pageTarget, browserContextId ?? null);
|
|
2585
|
+
if (ctx.browserContexts && (tabContextId == null || tabContextId === '')) {
|
|
2586
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
2587
|
+
return attemptRecord({ ok: false, error: { message: 'unknown context' } }, 'incomplete');
|
|
2588
|
+
}
|
|
2589
|
+
const canary = canarySpec({ tag: ctx.tag, homeUrl });
|
|
2590
|
+
const handle = {
|
|
2591
|
+
client: timedClient(client, timing),
|
|
2592
|
+
reader,
|
|
2593
|
+
pageSession,
|
|
2594
|
+
readerSession,
|
|
2595
|
+
pageTarget,
|
|
2596
|
+
homeUrl,
|
|
2597
|
+
browserContextId: tabContextId,
|
|
2598
|
+
browserContexts: Boolean(ctx.browserContexts),
|
|
2599
|
+
canary,
|
|
2600
|
+
transport: enabled.transport,
|
|
2601
|
+
fetchEnable: enabled.fetchEnable ?? null,
|
|
2602
|
+
internalSessions,
|
|
2603
|
+
notes,
|
|
2604
|
+
timing,
|
|
2605
|
+
evidenceIncomplete: false,
|
|
2606
|
+
};
|
|
2607
|
+
await plantCanary(handle);
|
|
2608
|
+
try {
|
|
2609
|
+
return await run(handle, enabled);
|
|
2610
|
+
} finally {
|
|
2611
|
+
await capped(
|
|
2612
|
+
disableInterception(client, pageSession, enabled.transport),
|
|
2613
|
+
800,
|
|
2614
|
+
'attempt-disable'
|
|
2615
|
+
);
|
|
2616
|
+
await capped(
|
|
2617
|
+
outcome(reader.send('Target.closeTarget', { targetId: pageTarget })),
|
|
2618
|
+
800,
|
|
2619
|
+
'attempt-close'
|
|
2620
|
+
);
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
function fetchAttackSpecs(ctx, header, bareDomain) {
|
|
2625
|
+
const v = (prefix) => `${prefix}-${ctx.tag}`;
|
|
2626
|
+
const set = (name, value) => [
|
|
2627
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
2628
|
+
{ name, value },
|
|
2629
|
+
];
|
|
2630
|
+
return [
|
|
2631
|
+
{
|
|
2632
|
+
label: 'fulfillArray',
|
|
2633
|
+
value: ctx.plantCookie.value,
|
|
2634
|
+
build: () =>
|
|
2635
|
+
fetchFulfill({
|
|
2636
|
+
responseHeaders: set('Set-Cookie', header(ctx.plantCookie.value)),
|
|
2637
|
+
body: b64text('ok'),
|
|
2638
|
+
}),
|
|
2639
|
+
},
|
|
2640
|
+
{
|
|
2641
|
+
label: 'fulfillObject',
|
|
2642
|
+
value: v('obj'),
|
|
2643
|
+
build: () =>
|
|
2644
|
+
fetchFulfill({
|
|
2645
|
+
responseHeaders: { 'content-type': 'text/plain', 'Set-Cookie': header(v('obj')) },
|
|
2646
|
+
body: b64text('ok'),
|
|
2647
|
+
}),
|
|
2648
|
+
},
|
|
2649
|
+
{
|
|
2650
|
+
label: 'fulfillLower',
|
|
2651
|
+
value: v('low'),
|
|
2652
|
+
build: () =>
|
|
2653
|
+
fetchFulfill({
|
|
2654
|
+
responseHeaders: set('set-cookie', header(v('low'))),
|
|
2655
|
+
body: b64text('ok'),
|
|
2656
|
+
}),
|
|
2657
|
+
},
|
|
2658
|
+
{
|
|
2659
|
+
label: 'fulfillSetCookie2',
|
|
2660
|
+
value: v('sc2'),
|
|
2661
|
+
build: () =>
|
|
2662
|
+
fetchFulfill({
|
|
2663
|
+
responseHeaders: set('Set-Cookie2', header(v('sc2'))),
|
|
2664
|
+
body: b64text('ok'),
|
|
2665
|
+
}),
|
|
2666
|
+
},
|
|
2667
|
+
{
|
|
2668
|
+
label: 'fulfillNewline',
|
|
2669
|
+
value: v('nl'),
|
|
2670
|
+
build: () =>
|
|
2671
|
+
fetchFulfill({
|
|
2672
|
+
responseHeaders: set(
|
|
2673
|
+
'Set-Cookie',
|
|
2674
|
+
`${header(v('nl'))}\n${cookieHeader(`${ctx.names.plant}o`, '1', ctx.domain)}`
|
|
2675
|
+
),
|
|
2676
|
+
body: b64text('ok'),
|
|
2677
|
+
}),
|
|
2678
|
+
},
|
|
2679
|
+
{
|
|
2680
|
+
label: 'fulfillBinary',
|
|
2681
|
+
value: v('bin'),
|
|
2682
|
+
build: () =>
|
|
2683
|
+
fetchFulfill({
|
|
2684
|
+
binaryResponseHeaders: binaryHeaders(set('Set-Cookie', header(v('bin')))),
|
|
2685
|
+
body: b64text('ok'),
|
|
2686
|
+
}),
|
|
2687
|
+
},
|
|
2688
|
+
{
|
|
2689
|
+
label: 'continueResponse',
|
|
2690
|
+
value: v('cr'),
|
|
2691
|
+
stage: 'Response',
|
|
2692
|
+
build: () =>
|
|
2693
|
+
fetchContinueResponse({
|
|
2694
|
+
responseHeaders: set('Set-Cookie', header(v('cr'))),
|
|
2695
|
+
}),
|
|
2696
|
+
},
|
|
2697
|
+
{
|
|
2698
|
+
label: 'redirect3xx',
|
|
2699
|
+
value: v('rx'),
|
|
2700
|
+
build: () =>
|
|
2701
|
+
fetchFulfill({
|
|
2702
|
+
responseCode: 302,
|
|
2703
|
+
responseHeaders: [
|
|
2704
|
+
{ name: 'Location', value: `${ctx.plantOrigin}/doc?n=redir-${ctx.tag}` },
|
|
2705
|
+
{ name: 'Set-Cookie', value: header(v('rx')) },
|
|
2706
|
+
],
|
|
2707
|
+
body: b64text(''),
|
|
2708
|
+
}),
|
|
2709
|
+
},
|
|
2710
|
+
{
|
|
2711
|
+
label: 'binaryLf',
|
|
2712
|
+
value: v('blf'),
|
|
2713
|
+
build: () =>
|
|
2714
|
+
fetchFulfill({
|
|
2715
|
+
binaryResponseHeaders: binaryHeaders([
|
|
2716
|
+
{ name: 'X-A', value: `1\nSet-Cookie: ${header(v('blf'))}` },
|
|
2717
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
2718
|
+
]),
|
|
2719
|
+
body: b64text('ok'),
|
|
2720
|
+
}),
|
|
2721
|
+
},
|
|
2722
|
+
{
|
|
2723
|
+
label: 'binaryObsFold',
|
|
2724
|
+
value: v('bof'),
|
|
2725
|
+
build: () =>
|
|
2726
|
+
fetchFulfill({
|
|
2727
|
+
binaryResponseHeaders: b64text(
|
|
2728
|
+
`content-type: text/plain\0Set-Cookie: ${ctx.names.plant}=${v('bof')}\r\n Domain=${ctx.domain}; Path=/\0`
|
|
2729
|
+
),
|
|
2730
|
+
body: b64text('ok'),
|
|
2731
|
+
}),
|
|
2732
|
+
},
|
|
2733
|
+
{
|
|
2734
|
+
label: 'domainQuoted',
|
|
2735
|
+
value: v('dq'),
|
|
2736
|
+
build: () =>
|
|
2737
|
+
fetchFulfill({
|
|
2738
|
+
responseHeaders: set('Set-Cookie', header(v('dq'), ctx.domain, `Domain="${bareDomain}"`)),
|
|
2739
|
+
body: b64text('ok'),
|
|
2740
|
+
}),
|
|
2741
|
+
},
|
|
2742
|
+
{
|
|
2743
|
+
label: 'domainUpper',
|
|
2744
|
+
value: v('du'),
|
|
2745
|
+
build: () =>
|
|
2746
|
+
fetchFulfill({
|
|
2747
|
+
responseHeaders: set('Set-Cookie', header(v('du'), ctx.domain, `DOMAIN=${ctx.domain}`)),
|
|
2748
|
+
body: b64text('ok'),
|
|
2749
|
+
}),
|
|
2750
|
+
},
|
|
2751
|
+
{
|
|
2752
|
+
label: 'domainTrailDot',
|
|
2753
|
+
value: v('dtd'),
|
|
2754
|
+
build: () =>
|
|
2755
|
+
fetchFulfill({
|
|
2756
|
+
responseHeaders: set('Set-Cookie', header(v('dtd'), ctx.domain, `Domain=${bareDomain}.`)),
|
|
2757
|
+
body: b64text('ok'),
|
|
2758
|
+
}),
|
|
2759
|
+
},
|
|
2760
|
+
{
|
|
2761
|
+
label: 'domainRepeated',
|
|
2762
|
+
value: v('dr'),
|
|
2763
|
+
build: () =>
|
|
2764
|
+
fetchFulfill({
|
|
2765
|
+
responseHeaders: set(
|
|
2766
|
+
'Set-Cookie',
|
|
2767
|
+
`${ctx.names.plant}=${v('dr')}; Domain=example.invalid; Domain=${ctx.domain}; Path=/`
|
|
2768
|
+
),
|
|
2769
|
+
body: b64text('ok'),
|
|
2770
|
+
}),
|
|
2771
|
+
},
|
|
2772
|
+
{
|
|
2773
|
+
label: 'domainWs',
|
|
2774
|
+
value: v('dws'),
|
|
2775
|
+
build: () =>
|
|
2776
|
+
fetchFulfill({
|
|
2777
|
+
responseHeaders: set(
|
|
2778
|
+
'Set-Cookie',
|
|
2779
|
+
header(v('dws'), ctx.domain, `Domain = ${ctx.domain}`)
|
|
2780
|
+
),
|
|
2781
|
+
body: b64text('ok'),
|
|
2782
|
+
}),
|
|
2783
|
+
},
|
|
2784
|
+
{
|
|
2785
|
+
label: 'headerPadded',
|
|
2786
|
+
value: v('hp'),
|
|
2787
|
+
build: () =>
|
|
2788
|
+
fetchFulfill({
|
|
2789
|
+
responseHeaders: set('Set-Cookie\t', header(v('hp'))),
|
|
2790
|
+
body: b64text('ok'),
|
|
2791
|
+
}),
|
|
2792
|
+
},
|
|
2793
|
+
{
|
|
2794
|
+
label: 'setCookieSecond',
|
|
2795
|
+
value: v('sc2nd'),
|
|
2796
|
+
build: () =>
|
|
2797
|
+
fetchFulfill({
|
|
2798
|
+
responseHeaders: [
|
|
2799
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
2800
|
+
{ name: 'X-Other', value: '1' },
|
|
2801
|
+
{ name: 'Set-Cookie', value: header(v('sc2nd')) },
|
|
2802
|
+
],
|
|
2803
|
+
body: b64text('ok'),
|
|
2804
|
+
}),
|
|
2805
|
+
},
|
|
2806
|
+
{
|
|
2807
|
+
label: 'responsePhrase',
|
|
2808
|
+
value: v('rp'),
|
|
2809
|
+
build: () =>
|
|
2810
|
+
fetchFulfill({
|
|
2811
|
+
responseCode: 200,
|
|
2812
|
+
responsePhrase: `OK\r\nSet-Cookie: ${header(v('rp'))}`,
|
|
2813
|
+
responseHeaders: [{ name: 'content-type', value: 'text/plain' }],
|
|
2814
|
+
body: b64text('ok'),
|
|
2815
|
+
}),
|
|
2816
|
+
},
|
|
2817
|
+
{
|
|
2818
|
+
label: 'continueAtRequest',
|
|
2819
|
+
value: v('car'),
|
|
2820
|
+
stage: 'Request',
|
|
2821
|
+
build: () =>
|
|
2822
|
+
fetchContinueResponse({
|
|
2823
|
+
responseCode: 200,
|
|
2824
|
+
responseHeaders: set('Set-Cookie', header(v('car'))),
|
|
2825
|
+
}),
|
|
2826
|
+
},
|
|
2827
|
+
];
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
function doorAbsentOf(raw) {
|
|
2831
|
+
if (raw?.observed !== true || raw?.incomplete) return false;
|
|
2832
|
+
return raw.doorPresent === false;
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
function noteRawDoor(notes, label, raw, text, handle = null, pathStartedAt = null) {
|
|
2836
|
+
note(notes, `cookie-plant.raw.${label}`, {
|
|
2837
|
+
...raw,
|
|
2838
|
+
...timingOf(handle, pathStartedAt),
|
|
2839
|
+
note: text,
|
|
2840
|
+
});
|
|
2841
|
+
return raw;
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2844
|
+
function forcedRawDoor(forced, notes, label) {
|
|
2845
|
+
const pathStartedAt = Date.now();
|
|
2846
|
+
if (forced === 'timeout') {
|
|
2847
|
+
return noteRawDoor(
|
|
2848
|
+
notes,
|
|
2849
|
+
label,
|
|
2850
|
+
{
|
|
2851
|
+
observed: true,
|
|
2852
|
+
answered: false,
|
|
2853
|
+
planted: false,
|
|
2854
|
+
timedOut: true,
|
|
2855
|
+
doorPresent: false,
|
|
2856
|
+
},
|
|
2857
|
+
'door not present on this browser',
|
|
2858
|
+
null,
|
|
2859
|
+
pathStartedAt
|
|
2860
|
+
);
|
|
2861
|
+
}
|
|
2862
|
+
if (forced === 'plant') {
|
|
2863
|
+
return noteRawDoor(
|
|
2864
|
+
notes,
|
|
2865
|
+
label,
|
|
2866
|
+
{
|
|
2867
|
+
observed: true,
|
|
2868
|
+
answered: true,
|
|
2869
|
+
planted: true,
|
|
2870
|
+
timedOut: false,
|
|
2871
|
+
doorPresent: true,
|
|
2872
|
+
},
|
|
2873
|
+
'raw leg planted: plant path',
|
|
2874
|
+
null,
|
|
2875
|
+
pathStartedAt
|
|
2876
|
+
);
|
|
2877
|
+
}
|
|
2878
|
+
const incompleteBy = {
|
|
2879
|
+
unreadable: 'cookie jar unreadable',
|
|
2880
|
+
'open-fail': 'raw open failed',
|
|
2881
|
+
'enable-fail': 'raw Fetch.enable failed',
|
|
2882
|
+
'no-pause': 'raw leg: no pause',
|
|
2883
|
+
missing: 'raw leg missing',
|
|
2884
|
+
};
|
|
2885
|
+
if (!Object.hasOwn(incompleteBy, forced)) return null;
|
|
2886
|
+
return noteRawDoor(
|
|
2887
|
+
notes,
|
|
2888
|
+
label,
|
|
2889
|
+
{
|
|
2890
|
+
observed: false,
|
|
2891
|
+
answered: false,
|
|
2892
|
+
planted: false,
|
|
2893
|
+
timedOut: false,
|
|
2894
|
+
doorPresent: false,
|
|
2895
|
+
incomplete: incompleteBy[forced],
|
|
2896
|
+
},
|
|
2897
|
+
'raw leg incomplete',
|
|
2898
|
+
null,
|
|
2899
|
+
pathStartedAt
|
|
2900
|
+
);
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2903
|
+
function incompleteRaw(incomplete) {
|
|
2904
|
+
return {
|
|
2905
|
+
observed: false,
|
|
2906
|
+
answered: false,
|
|
2907
|
+
planted: false,
|
|
2908
|
+
timedOut: false,
|
|
2909
|
+
doorPresent: false,
|
|
2910
|
+
incomplete,
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
async function observeRawPlantSend({
|
|
2915
|
+
reader,
|
|
2916
|
+
sessionId,
|
|
2917
|
+
cookie,
|
|
2918
|
+
plantUrl,
|
|
2919
|
+
budget,
|
|
2920
|
+
from,
|
|
2921
|
+
spec,
|
|
2922
|
+
notes,
|
|
2923
|
+
label,
|
|
2924
|
+
triggerHolder,
|
|
2925
|
+
handle,
|
|
2926
|
+
pathStartedAt,
|
|
2927
|
+
browserContextId,
|
|
2928
|
+
canary,
|
|
2929
|
+
}) {
|
|
2930
|
+
const jarHandle = {
|
|
2931
|
+
reader,
|
|
2932
|
+
readerSession: sessionId,
|
|
2933
|
+
browserContextId,
|
|
2934
|
+
browserContexts: Boolean(handle?.browserContexts),
|
|
2935
|
+
canary,
|
|
2936
|
+
};
|
|
2937
|
+
requireAttemptHandle(jarHandle, 'observeRawPlantSend');
|
|
2938
|
+
if (!canary) throw new Error('cookie-plant.observeRawPlantSend: canary required');
|
|
2939
|
+
if (jarContextIncomplete(jarHandle))
|
|
2940
|
+
return noteRawDoor(
|
|
2941
|
+
notes,
|
|
2942
|
+
label,
|
|
2943
|
+
{ ...incompleteRaw('unknown context'), browserContextId },
|
|
2944
|
+
'unknown context',
|
|
2945
|
+
handle,
|
|
2946
|
+
pathStartedAt
|
|
2947
|
+
);
|
|
2948
|
+
await capped(clearCookie(jarHandle, cookie), 800, 'raw-clear');
|
|
2949
|
+
await plantCanary(jarHandle);
|
|
2950
|
+
const enabled = await capped(
|
|
2951
|
+
outcome(
|
|
2952
|
+
reader.send(
|
|
2953
|
+
'Fetch.enable',
|
|
2954
|
+
{
|
|
2955
|
+
patterns: [
|
|
2956
|
+
{ urlPattern: '*', requestStage: 'Request' },
|
|
2957
|
+
{ urlPattern: '*', requestStage: 'Response' },
|
|
2958
|
+
],
|
|
2959
|
+
},
|
|
2960
|
+
sessionId
|
|
2961
|
+
)
|
|
2962
|
+
),
|
|
2963
|
+
800,
|
|
2964
|
+
'raw-enable'
|
|
2965
|
+
);
|
|
2966
|
+
if (!enabled.ok) {
|
|
2967
|
+
return noteRawDoor(
|
|
2968
|
+
notes,
|
|
2969
|
+
label,
|
|
2970
|
+
{
|
|
2971
|
+
...incompleteRaw(String(enabled.error?.message ?? 'raw Fetch.enable failed')),
|
|
2972
|
+
browserContextId,
|
|
2973
|
+
},
|
|
2974
|
+
'raw leg incomplete',
|
|
2975
|
+
handle,
|
|
2976
|
+
pathStartedAt
|
|
2977
|
+
);
|
|
2978
|
+
}
|
|
2979
|
+
triggerHolder.promise = triggerNavigate(reader, sessionId, plantUrl);
|
|
2980
|
+
triggerHolder.paused = await waitPause(
|
|
2981
|
+
reader,
|
|
2982
|
+
from,
|
|
2983
|
+
plantUrl,
|
|
2984
|
+
['Fetch.requestPaused'],
|
|
2985
|
+
Math.min(budget, 2000)
|
|
2986
|
+
);
|
|
2987
|
+
if (!triggerHolder.paused) {
|
|
2988
|
+
return noteRawDoor(
|
|
2989
|
+
notes,
|
|
2990
|
+
label,
|
|
2991
|
+
{ ...incompleteRaw('raw leg: no pause'), browserContextId },
|
|
2992
|
+
'raw leg incomplete',
|
|
2993
|
+
handle,
|
|
2994
|
+
pathStartedAt
|
|
2995
|
+
);
|
|
2996
|
+
}
|
|
2997
|
+
const out = await capped(
|
|
2998
|
+
spec.build(triggerHolder.paused).send(reader, triggerHolder.paused),
|
|
2999
|
+
Math.min(budget, 1500),
|
|
3000
|
+
'raw-plant-send'
|
|
3001
|
+
);
|
|
3002
|
+
const timedOut = Boolean(out?.error?.message && /timeout/i.test(String(out.error.message)));
|
|
3003
|
+
if (refused(out) || !out.ok) await releasePause(reader, triggerHolder.paused);
|
|
3004
|
+
await settleTrigger(triggerHolder.promise, Math.min(budget, 500));
|
|
3005
|
+
const jar = await capped(readJarWithCanary(jarHandle, cookie), 1500, 'raw-jar');
|
|
3006
|
+
if (
|
|
3007
|
+
jar?.error?.message?.includes('timeout') ||
|
|
3008
|
+
jar?.incomplete ||
|
|
3009
|
+
plantedOf(jar) === 'incomplete'
|
|
3010
|
+
) {
|
|
3011
|
+
return noteRawDoor(
|
|
3012
|
+
notes,
|
|
3013
|
+
label,
|
|
3014
|
+
{
|
|
3015
|
+
observed: true,
|
|
3016
|
+
answered: answered(out),
|
|
3017
|
+
planted: false,
|
|
3018
|
+
timedOut,
|
|
3019
|
+
doorPresent: false,
|
|
3020
|
+
incomplete: jar?.canaryMissing ? 'jar view canary absent' : 'cookie jar unreadable',
|
|
3021
|
+
browserContextId,
|
|
3022
|
+
},
|
|
3023
|
+
'raw leg incomplete',
|
|
3024
|
+
handle,
|
|
3025
|
+
pathStartedAt
|
|
3026
|
+
);
|
|
3027
|
+
}
|
|
3028
|
+
const planted = plantedOf(jar) === true;
|
|
3029
|
+
const answeredOk = answered(out);
|
|
3030
|
+
const doorPresent = answeredOk === true && planted;
|
|
3031
|
+
const raw = {
|
|
3032
|
+
observed: true,
|
|
3033
|
+
answered: answeredOk,
|
|
3034
|
+
planted,
|
|
3035
|
+
timedOut,
|
|
3036
|
+
doorPresent,
|
|
3037
|
+
browserContextId,
|
|
3038
|
+
};
|
|
3039
|
+
noteRawDoor(
|
|
3040
|
+
notes,
|
|
3041
|
+
label,
|
|
3042
|
+
{ ...raw, via: jar?.via },
|
|
3043
|
+
doorPresent ? 'raw leg planted: plant path' : 'door not present on this browser',
|
|
3044
|
+
handle,
|
|
3045
|
+
pathStartedAt
|
|
3046
|
+
);
|
|
3047
|
+
await capped(clearCookie(jarHandle, cookie), 800, 'raw-clear');
|
|
3048
|
+
return raw;
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
async function measureRawDoor(ctx, spec) {
|
|
3052
|
+
const {
|
|
3053
|
+
reader,
|
|
3054
|
+
homeUrl,
|
|
3055
|
+
notes,
|
|
3056
|
+
internalSessions,
|
|
3057
|
+
budget,
|
|
3058
|
+
plantUrl,
|
|
3059
|
+
plantCookie,
|
|
3060
|
+
forcedRaw,
|
|
3061
|
+
browserContextId = null,
|
|
3062
|
+
} = ctx;
|
|
3063
|
+
const forced = forcedRawDoor(forcedRaw?.[spec.label], notes, spec.label);
|
|
3064
|
+
if (forced) return forced;
|
|
3065
|
+
const pathStartedAt = Date.now();
|
|
3066
|
+
const timing = { pathStartedAt };
|
|
3067
|
+
const timedReader = timedClient(reader, timing);
|
|
3068
|
+
const handle = { timing };
|
|
3069
|
+
const page = await openPage(timedReader, homeUrl, notes, internalSessions, browserContextId);
|
|
3070
|
+
if (!page.ok || page.result?.incomplete) {
|
|
3071
|
+
return noteRawDoor(
|
|
3072
|
+
notes,
|
|
3073
|
+
spec.label,
|
|
3074
|
+
incompleteRaw(page.result?.incomplete ?? page.error?.message ?? 'raw open failed'),
|
|
3075
|
+
'raw leg incomplete',
|
|
3076
|
+
handle,
|
|
3077
|
+
pathStartedAt
|
|
3078
|
+
);
|
|
3079
|
+
}
|
|
3080
|
+
const sessionId = page.result.sessionId;
|
|
3081
|
+
const targetId = page.result.targetId;
|
|
3082
|
+
const tabContextId = await resolveTabContextId(timedReader, targetId, browserContextId ?? null);
|
|
3083
|
+
if (ctx.browserContexts && (tabContextId == null || tabContextId === '')) {
|
|
3084
|
+
await outcome(timedReader.send('Target.closeTarget', { targetId }));
|
|
3085
|
+
return noteRawDoor(
|
|
3086
|
+
notes,
|
|
3087
|
+
spec.label,
|
|
3088
|
+
incompleteRaw('unknown context'),
|
|
3089
|
+
'unknown context',
|
|
3090
|
+
handle,
|
|
3091
|
+
pathStartedAt
|
|
3092
|
+
);
|
|
3093
|
+
}
|
|
3094
|
+
const canary = canarySpec({ tag: ctx.tag, homeUrl });
|
|
3095
|
+
const cookie = { ...plantCookie, value: spec.value };
|
|
3096
|
+
const triggerHolder = { paused: null, promise: Promise.resolve() };
|
|
3097
|
+
const from = timedReader.events.length;
|
|
3098
|
+
handle.browserContexts = Boolean(ctx.browserContexts);
|
|
3099
|
+
handle.browserContextId = tabContextId;
|
|
3100
|
+
try {
|
|
3101
|
+
return await withPathBudget(
|
|
3102
|
+
observeRawPlantSend({
|
|
3103
|
+
reader: timedReader,
|
|
3104
|
+
sessionId,
|
|
3105
|
+
cookie,
|
|
3106
|
+
plantUrl,
|
|
3107
|
+
budget,
|
|
3108
|
+
from,
|
|
3109
|
+
spec,
|
|
3110
|
+
notes,
|
|
3111
|
+
label: spec.label,
|
|
3112
|
+
triggerHolder,
|
|
3113
|
+
handle,
|
|
3114
|
+
pathStartedAt,
|
|
3115
|
+
browserContextId: tabContextId,
|
|
3116
|
+
canary,
|
|
3117
|
+
}),
|
|
3118
|
+
pathCeiling(budget),
|
|
3119
|
+
`raw:${spec.label}`
|
|
3120
|
+
);
|
|
3121
|
+
} catch (error) {
|
|
3122
|
+
return noteRawDoor(
|
|
3123
|
+
notes,
|
|
3124
|
+
spec.label,
|
|
3125
|
+
{
|
|
3126
|
+
...incompleteRaw(String(error?.message ?? error)),
|
|
3127
|
+
timedOut: /timeout/i.test(String(error?.message ?? error)),
|
|
3128
|
+
},
|
|
3129
|
+
'raw leg incomplete',
|
|
3130
|
+
handle,
|
|
3131
|
+
pathStartedAt
|
|
3132
|
+
);
|
|
3133
|
+
} finally {
|
|
3134
|
+
try {
|
|
3135
|
+
await releasePause(timedReader, triggerHolder.paused);
|
|
3136
|
+
await drainPauses(timedReader, from);
|
|
3137
|
+
await settleTrigger(triggerHolder.promise, Math.min(budget, 500));
|
|
3138
|
+
await capped(
|
|
3139
|
+
disableInterception(timedReader, sessionId, { fetch: true, legacy: false }),
|
|
3140
|
+
800,
|
|
3141
|
+
'raw-disable'
|
|
3142
|
+
);
|
|
3143
|
+
await capped(outcome(timedReader.send('Target.closeTarget', { targetId })), 800, 'raw-close');
|
|
3144
|
+
} catch {
|
|
3145
|
+
await outcome(timedReader.send('Target.closeTarget', { targetId })).catch(() => {});
|
|
3146
|
+
}
|
|
3147
|
+
}
|
|
3148
|
+
}
|
|
3149
|
+
|
|
3150
|
+
function fetchAttacks(ctx) {
|
|
3151
|
+
if (!ctx.transport?.fetch) return null;
|
|
3152
|
+
const header = (value, domain = ctx.domain, domainAttr = null) =>
|
|
3153
|
+
cookieHeader(ctx.names.plant, value, domain, '', domainAttr);
|
|
3154
|
+
const bareDomain = ctx.domain.replace(/^\./, '');
|
|
3155
|
+
const out = {};
|
|
3156
|
+
for (const spec of fetchAttackSpecs(ctx, header, bareDomain)) {
|
|
3157
|
+
out[spec.label] = () =>
|
|
3158
|
+
(async () => {
|
|
3159
|
+
let rawDoor = ctx.rawDoors?.[spec.label] ?? null;
|
|
3160
|
+
if (ctx.guardedProtected && !rawDoor) {
|
|
3161
|
+
rawDoor = await measureRawDoor(ctx, spec);
|
|
3162
|
+
ctx.rawDoors = { ...(ctx.rawDoors ?? {}), [spec.label]: rawDoor };
|
|
3163
|
+
}
|
|
3164
|
+
return withFreshAttemptTab(ctx, (handle) =>
|
|
3165
|
+
runPlant({
|
|
3166
|
+
handle,
|
|
3167
|
+
url: ctx.plantUrl,
|
|
3168
|
+
budget: ctx.budget,
|
|
3169
|
+
notes: ctx.notes,
|
|
3170
|
+
topLevel: true,
|
|
3171
|
+
fixtureLog: ctx.fixtureLog,
|
|
3172
|
+
legStartedAt: ctx.legStartedAt,
|
|
3173
|
+
firstIncomplete: ctx.firstIncomplete,
|
|
3174
|
+
protectedBlock: Boolean(ctx.guardedProtected),
|
|
3175
|
+
tag: ctx.tag,
|
|
3176
|
+
blockedMarkers: ctx.blockedMarkers,
|
|
3177
|
+
proofTag: ctx.proofTag,
|
|
3178
|
+
cookie: { ...ctx.plantCookie, value: spec.value },
|
|
3179
|
+
label: spec.label,
|
|
3180
|
+
stage: spec.stage ?? 'Request',
|
|
3181
|
+
build: spec.build,
|
|
3182
|
+
rawDoor,
|
|
3183
|
+
})
|
|
3184
|
+
);
|
|
3185
|
+
})();
|
|
3186
|
+
}
|
|
3187
|
+
return out;
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
async function withLegacyOnly(handle, transport, run) {
|
|
3191
|
+
const session = () => handle.pageSession;
|
|
3192
|
+
if (transport.fetch) await outcome(handle.client.send('Fetch.disable', {}, session()));
|
|
3193
|
+
await enableLegacy(handle.client, session());
|
|
3194
|
+
try {
|
|
3195
|
+
return await run();
|
|
3196
|
+
} finally {
|
|
3197
|
+
if (transport.fetch) {
|
|
3198
|
+
await outcome(
|
|
3199
|
+
handle.client.send(
|
|
3200
|
+
'Fetch.enable',
|
|
3201
|
+
{
|
|
3202
|
+
patterns: [
|
|
3203
|
+
{ urlPattern: '*', requestStage: 'Request' },
|
|
3204
|
+
{ urlPattern: '*', requestStage: 'Response' },
|
|
3205
|
+
],
|
|
3206
|
+
},
|
|
3207
|
+
session()
|
|
3208
|
+
)
|
|
3209
|
+
);
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
function legacyAttacks(ctx, legacyReady) {
|
|
3215
|
+
if (!legacyReady) return null;
|
|
3216
|
+
const legacyTransport = { kind: 'legacy', fetch: false, legacy: true };
|
|
3217
|
+
const runLegacy = (label, value) => () =>
|
|
3218
|
+
withFreshAttemptTab(ctx, (handle) =>
|
|
3219
|
+
withLegacyOnly(handle, handle.transport, () => {
|
|
3220
|
+
const prior = handle.transport;
|
|
3221
|
+
handle.transport = legacyTransport;
|
|
3222
|
+
return runPlant({
|
|
3223
|
+
handle,
|
|
3224
|
+
url: ctx.plantUrl,
|
|
3225
|
+
budget: ctx.budget,
|
|
3226
|
+
notes: ctx.notes,
|
|
3227
|
+
topLevel: true,
|
|
3228
|
+
fixtureLog: ctx.fixtureLog,
|
|
3229
|
+
legStartedAt: ctx.legStartedAt,
|
|
3230
|
+
firstIncomplete: ctx.firstIncomplete,
|
|
3231
|
+
protectedBlock: Boolean(ctx.guardedProtected),
|
|
3232
|
+
tag: ctx.tag,
|
|
3233
|
+
blockedMarkers: ctx.blockedMarkers,
|
|
3234
|
+
proofTag: ctx.proofTag,
|
|
3235
|
+
cookie: { ...ctx.plantCookie, value },
|
|
3236
|
+
label,
|
|
3237
|
+
build: () =>
|
|
3238
|
+
legacyContinue({
|
|
3239
|
+
rawResponse: rawHttpResponse({
|
|
3240
|
+
code: 200,
|
|
3241
|
+
phrase: 'OK',
|
|
3242
|
+
headers: [
|
|
3243
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
3244
|
+
{
|
|
3245
|
+
name: 'Set-Cookie',
|
|
3246
|
+
value: cookieHeader(ctx.names.plant, value, ctx.domain),
|
|
3247
|
+
},
|
|
3248
|
+
],
|
|
3249
|
+
body: 'ok',
|
|
3250
|
+
}),
|
|
3251
|
+
}),
|
|
3252
|
+
}).finally(() => {
|
|
3253
|
+
handle.transport = prior;
|
|
3254
|
+
});
|
|
3255
|
+
})
|
|
3256
|
+
);
|
|
3257
|
+
return {
|
|
3258
|
+
legacyHeaders: runLegacy('legacyHeaders', `lh-${ctx.tag}`),
|
|
3259
|
+
legacyRaw: runLegacy('legacyRaw', `lr-${ctx.tag}`),
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
|
|
3263
|
+
async function allowedHeaderAttempt({
|
|
3264
|
+
handle,
|
|
3265
|
+
url,
|
|
3266
|
+
budget,
|
|
3267
|
+
notes,
|
|
3268
|
+
label,
|
|
3269
|
+
header,
|
|
3270
|
+
cookie,
|
|
3271
|
+
fetchReady,
|
|
3272
|
+
topLevel = false,
|
|
3273
|
+
fixtureLog,
|
|
3274
|
+
legStartedAt,
|
|
3275
|
+
firstIncomplete,
|
|
3276
|
+
}) {
|
|
3277
|
+
const { client, transport } = handle;
|
|
3278
|
+
let pageSession = handle.pageSession;
|
|
3279
|
+
let paused = null;
|
|
3280
|
+
let triggerPromise = Promise.resolve();
|
|
3281
|
+
const from = client.events.length;
|
|
3282
|
+
const pauseMs = Math.min(budget, 2000);
|
|
3283
|
+
const startedAt = Date.now();
|
|
3284
|
+
const legAt = legStartedAt ?? startedAt;
|
|
3285
|
+
const finish = (out) =>
|
|
3286
|
+
cookie
|
|
3287
|
+
? finishPlant({ out, cookie, notes, label, handle })
|
|
3288
|
+
: (() => {
|
|
3289
|
+
note(notes, `cookie-plant.${label}`, {
|
|
3290
|
+
answered: answered(out),
|
|
3291
|
+
refused: refused(out),
|
|
3292
|
+
});
|
|
3293
|
+
return {
|
|
3294
|
+
answered: answered(out) ? true : 'incomplete',
|
|
3295
|
+
refused: answered(out) ? refused(out) : 'incomplete',
|
|
3296
|
+
planted: false,
|
|
3297
|
+
};
|
|
3298
|
+
})();
|
|
3299
|
+
try {
|
|
3300
|
+
return await withPathBudget(
|
|
3301
|
+
(async () => {
|
|
3302
|
+
const ensure = await ensureInterceptionLive(handle);
|
|
3303
|
+
pageSession = handle.pageSession;
|
|
3304
|
+
if (sessionCut(ensure))
|
|
3305
|
+
return cookie
|
|
3306
|
+
? recordSessionCut({ handle, cookie, notes, label })
|
|
3307
|
+
: finish({
|
|
3308
|
+
ok: false,
|
|
3309
|
+
error: { message: 'slicc: refused: session cut on protected execution context' },
|
|
3310
|
+
});
|
|
3311
|
+
if (!ensure.ok) {
|
|
3312
|
+
await diagnoseIncomplete({
|
|
3313
|
+
notes,
|
|
3314
|
+
label,
|
|
3315
|
+
incomplete: String(ensure.error?.message ?? 'ensure failed'),
|
|
3316
|
+
url,
|
|
3317
|
+
client,
|
|
3318
|
+
pageSession,
|
|
3319
|
+
from,
|
|
3320
|
+
methods:
|
|
3321
|
+
transport.kind === 'legacy'
|
|
3322
|
+
? ['Network.requestIntercepted']
|
|
3323
|
+
: ['Fetch.requestPaused'],
|
|
3324
|
+
pauseMs,
|
|
3325
|
+
startedAt,
|
|
3326
|
+
legStartedAt: legAt,
|
|
3327
|
+
fixtureLog,
|
|
3328
|
+
ensure,
|
|
3329
|
+
trigger: null,
|
|
3330
|
+
firstIncomplete,
|
|
3331
|
+
});
|
|
3332
|
+
return attemptRecord(
|
|
3333
|
+
{ ok: false, error: ensure.error ?? { message: 'ensure failed' } },
|
|
3334
|
+
'incomplete'
|
|
3335
|
+
);
|
|
3336
|
+
}
|
|
3337
|
+
const methods =
|
|
3338
|
+
transport.kind === 'legacy' ? ['Network.requestIntercepted'] : ['Fetch.requestPaused'];
|
|
3339
|
+
triggerPromise = topLevel
|
|
3340
|
+
? triggerNavigate(client, pageSession, url)
|
|
3341
|
+
: triggerFetch(client, pageSession, url);
|
|
3342
|
+
paused = await waitPause(client, from, url, methods, pauseMs);
|
|
3343
|
+
if (!paused) {
|
|
3344
|
+
const trigger = await settleTrigger(triggerPromise, Math.min(budget, 500));
|
|
3345
|
+
triggerPromise = Promise.resolve(trigger);
|
|
3346
|
+
await diagnoseIncomplete({
|
|
3347
|
+
notes,
|
|
3348
|
+
label,
|
|
3349
|
+
incomplete: 'no pause',
|
|
3350
|
+
url,
|
|
3351
|
+
client,
|
|
3352
|
+
pageSession,
|
|
3353
|
+
from,
|
|
3354
|
+
methods,
|
|
3355
|
+
pauseMs,
|
|
3356
|
+
startedAt,
|
|
3357
|
+
legStartedAt: legAt,
|
|
3358
|
+
fixtureLog,
|
|
3359
|
+
ensure,
|
|
3360
|
+
trigger,
|
|
3361
|
+
firstIncomplete,
|
|
3362
|
+
});
|
|
3363
|
+
return attemptRecord(
|
|
3364
|
+
{ ok: false, error: { message: 'timeout: no pause' } },
|
|
3365
|
+
'incomplete'
|
|
3366
|
+
);
|
|
3367
|
+
}
|
|
3368
|
+
const out = await capped(
|
|
3369
|
+
fetchReady
|
|
3370
|
+
? fetchFulfill({
|
|
3371
|
+
responseHeaders: [
|
|
3372
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
3373
|
+
{ name: 'Set-Cookie', value: header },
|
|
3374
|
+
],
|
|
3375
|
+
body: b64text('ok'),
|
|
3376
|
+
}).send(client, paused)
|
|
3377
|
+
: legacyContinue({
|
|
3378
|
+
rawResponse: rawHttpResponse({
|
|
3379
|
+
code: 200,
|
|
3380
|
+
phrase: 'OK',
|
|
3381
|
+
headers: [{ name: 'Set-Cookie', value: header }],
|
|
3382
|
+
body: 'ok',
|
|
3383
|
+
}),
|
|
3384
|
+
}).send(client, paused),
|
|
3385
|
+
1500,
|
|
3386
|
+
'allowed-send'
|
|
3387
|
+
);
|
|
3388
|
+
if (sessionCut(out))
|
|
3389
|
+
return cookie ? recordSessionCut({ handle, cookie, notes, label }) : finish(out);
|
|
3390
|
+
return finish(out);
|
|
3391
|
+
})(),
|
|
3392
|
+
pathCeiling(budget),
|
|
3393
|
+
label
|
|
3394
|
+
);
|
|
3395
|
+
} catch (error) {
|
|
3396
|
+
if (sessionCut({ ok: false, error }))
|
|
3397
|
+
return cookie
|
|
3398
|
+
? recordSessionCut({ handle, cookie, notes, label })
|
|
3399
|
+
: finish({
|
|
3400
|
+
ok: false,
|
|
3401
|
+
error: { message: 'slicc: refused: session cut on protected execution context' },
|
|
3402
|
+
});
|
|
3403
|
+
note(notes, `cookie-plant.${label}`, { incomplete: String(error?.message ?? error) });
|
|
3404
|
+
return attemptRecord(
|
|
3405
|
+
{ ok: false, error: { message: String(error?.message ?? error) } },
|
|
3406
|
+
'incomplete'
|
|
3407
|
+
);
|
|
3408
|
+
} finally {
|
|
3409
|
+
try {
|
|
3410
|
+
await withPathBudget(
|
|
3411
|
+
cleanupPath({
|
|
3412
|
+
handle,
|
|
3413
|
+
paused,
|
|
3414
|
+
from,
|
|
3415
|
+
triggerPromise,
|
|
3416
|
+
budget,
|
|
3417
|
+
}),
|
|
3418
|
+
cleanupCeiling(budget),
|
|
3419
|
+
`${label}:cleanup`
|
|
3420
|
+
);
|
|
3421
|
+
} catch (error) {
|
|
3422
|
+
note(notes, `cookie-plant.${label}`, {
|
|
3423
|
+
cleanup: String(error?.message ?? error),
|
|
3424
|
+
});
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
function seedProof(jar, cookie) {
|
|
3430
|
+
if (plantedOf(jar) !== true || !jar?.cookie) return false;
|
|
3431
|
+
const got = jar.cookie;
|
|
3432
|
+
if (got.name !== cookie.name) return false;
|
|
3433
|
+
if (got.domain.replace(/^\./, '') !== String(cookie.domain ?? '').replace(/^\./, ''))
|
|
3434
|
+
return false;
|
|
3435
|
+
if ((got.path ?? '/') !== (cookie.path ?? '/')) return false;
|
|
3436
|
+
if (cookie.value !== undefined && got.value !== cookie.value) return false;
|
|
3437
|
+
return true;
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
async function seedCookie(handle, cookie) {
|
|
3441
|
+
requireAttemptHandle(handle, 'seedCookie');
|
|
3442
|
+
const unknown = jarContextIncomplete(handle);
|
|
3443
|
+
if (unknown) return unknown;
|
|
3444
|
+
const path = cookie.path ?? '/';
|
|
3445
|
+
await clearCookie(handle, { ...cookie, path });
|
|
3446
|
+
const all = await outcome(
|
|
3447
|
+
handle.reader.send('Storage.getCookies', storageContextParams(handle.browserContextId))
|
|
3448
|
+
);
|
|
3449
|
+
const rest = (all.result?.cookies ?? []).filter(
|
|
3450
|
+
(entry) =>
|
|
3451
|
+
!(
|
|
3452
|
+
entry.name === cookie.name &&
|
|
3453
|
+
entry.domain.replace(/^\./, '') === cookie.domain.replace(/^\./, '') &&
|
|
3454
|
+
(entry.path ?? '/') === path
|
|
3455
|
+
)
|
|
3456
|
+
);
|
|
3457
|
+
const seeded = cookie.url
|
|
3458
|
+
? { name: cookie.name, value: cookie.value, url: cookie.url, path }
|
|
3459
|
+
: { name: cookie.name, value: cookie.value, domain: cookie.domain, path };
|
|
3460
|
+
await outcome(
|
|
3461
|
+
handle.reader.send('Storage.setCookies', {
|
|
3462
|
+
...storageContextParams(handle.browserContextId),
|
|
3463
|
+
cookies: [...rest, seeded],
|
|
3464
|
+
})
|
|
3465
|
+
);
|
|
3466
|
+
return readJar(handle, {
|
|
3467
|
+
name: cookie.name,
|
|
3468
|
+
domain: cookie.domain,
|
|
3469
|
+
value: cookie.value,
|
|
3470
|
+
path,
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
function controlAttacks(ctx) {
|
|
3475
|
+
const ordinaryCookie = {
|
|
3476
|
+
name: ctx.names.ordinary,
|
|
3477
|
+
value: `o-${ctx.tag}`,
|
|
3478
|
+
domain: hostOf(ctx.ordinary),
|
|
3479
|
+
url: `${ctx.ordinary}/`,
|
|
3480
|
+
};
|
|
3481
|
+
const ordinaryUrl = `${ctx.ordinary}/data?n=ctrl-${ctx.tag}`;
|
|
3482
|
+
const diag = (handle) => ({
|
|
3483
|
+
handle,
|
|
3484
|
+
budget: ctx.budget,
|
|
3485
|
+
notes: ctx.notes,
|
|
3486
|
+
fixtureLog: ctx.fixtureLog,
|
|
3487
|
+
legStartedAt: ctx.legStartedAt,
|
|
3488
|
+
firstIncomplete: ctx.firstIncomplete,
|
|
3489
|
+
});
|
|
3490
|
+
return {
|
|
3491
|
+
ordinary: () =>
|
|
3492
|
+
withFreshAttemptTab(ctx, (handle) => {
|
|
3493
|
+
const fetchReady = Boolean(handle.transport?.fetch);
|
|
3494
|
+
return runPlant({
|
|
3495
|
+
...diag(handle),
|
|
3496
|
+
url: ordinaryUrl,
|
|
3497
|
+
cookie: ordinaryCookie,
|
|
3498
|
+
label: 'ordinary',
|
|
3499
|
+
topLevel: false,
|
|
3500
|
+
build: () =>
|
|
3501
|
+
fetchReady
|
|
3502
|
+
? fetchFulfill({
|
|
3503
|
+
responseHeaders: [
|
|
3504
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
3505
|
+
{
|
|
3506
|
+
name: 'Set-Cookie',
|
|
3507
|
+
value: cookieHeader(ctx.names.ordinary, ordinaryCookie.value, null),
|
|
3508
|
+
},
|
|
3509
|
+
],
|
|
3510
|
+
body: b64text('ok'),
|
|
3511
|
+
})
|
|
3512
|
+
: legacyContinue({
|
|
3513
|
+
rawResponse: rawHttpResponse({
|
|
3514
|
+
code: 200,
|
|
3515
|
+
phrase: 'OK',
|
|
3516
|
+
headers: [
|
|
3517
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
3518
|
+
{
|
|
3519
|
+
name: 'Set-Cookie',
|
|
3520
|
+
value: cookieHeader(ctx.names.ordinary, ordinaryCookie.value, null),
|
|
3521
|
+
},
|
|
3522
|
+
],
|
|
3523
|
+
body: 'ok',
|
|
3524
|
+
}),
|
|
3525
|
+
}),
|
|
3526
|
+
});
|
|
3527
|
+
}),
|
|
3528
|
+
adobe: () =>
|
|
3529
|
+
withFreshAttemptTab(ctx, (handle) => {
|
|
3530
|
+
const fetchReady = Boolean(handle.transport?.fetch);
|
|
3531
|
+
const adobeOrigin =
|
|
3532
|
+
fixtureOriginFor(ctx.ordinary, 'www.adobe.com') ?? 'https://www.adobe.com';
|
|
3533
|
+
const adobeCookie = {
|
|
3534
|
+
name: ctx.names.adobe,
|
|
3535
|
+
value: `a-${ctx.tag}`,
|
|
3536
|
+
domain: '.adobe.com',
|
|
3537
|
+
url: `${adobeOrigin}/`,
|
|
3538
|
+
};
|
|
3539
|
+
return allowedHeaderAttempt({
|
|
3540
|
+
...diag(handle),
|
|
3541
|
+
url: `${adobeOrigin}/data?n=adobe-${ctx.tag}`,
|
|
3542
|
+
label: 'adobe',
|
|
3543
|
+
header: cookieHeader(ctx.names.adobe, adobeCookie.value, '.adobe.com'),
|
|
3544
|
+
cookie: adobeCookie,
|
|
3545
|
+
fetchReady,
|
|
3546
|
+
topLevel: true,
|
|
3547
|
+
});
|
|
3548
|
+
}),
|
|
3549
|
+
deletion: () =>
|
|
3550
|
+
withFreshAttemptTab(ctx, async (handle) => {
|
|
3551
|
+
const fetchReady = Boolean(handle.transport?.fetch);
|
|
3552
|
+
const browserContextId = handle.browserContextId ?? null;
|
|
3553
|
+
const deleteOnOrdinary = {
|
|
3554
|
+
name: ctx.names.delete,
|
|
3555
|
+
value: `seed-${ctx.tag}`,
|
|
3556
|
+
domain: hostOf(ctx.ordinary),
|
|
3557
|
+
path: '/',
|
|
3558
|
+
url: `${ctx.ordinary}/`,
|
|
3559
|
+
};
|
|
3560
|
+
const incompleteDeletion = (reason) => {
|
|
3561
|
+
note(ctx.notes, 'cookie-plant.deletion', {
|
|
3562
|
+
incomplete: reason,
|
|
3563
|
+
browserContextId,
|
|
3564
|
+
...timingOf(handle),
|
|
3565
|
+
});
|
|
3566
|
+
return {
|
|
3567
|
+
answered: 'incomplete',
|
|
3568
|
+
refused: 'incomplete',
|
|
3569
|
+
planted: 'incomplete',
|
|
3570
|
+
cleared: 'incomplete',
|
|
3571
|
+
};
|
|
3572
|
+
};
|
|
3573
|
+
const seeded = await seedCookie(handle, deleteOnOrdinary);
|
|
3574
|
+
if (!seedProof(seeded, deleteOnOrdinary))
|
|
3575
|
+
return incompleteDeletion(
|
|
3576
|
+
seeded?.incomplete ? 'seed jar unreadable' : 'seed missing exact name+domain+path'
|
|
3577
|
+
);
|
|
3578
|
+
const attempt = await allowedHeaderAttempt({
|
|
3579
|
+
...diag(handle),
|
|
3580
|
+
url: ordinaryUrl,
|
|
3581
|
+
label: 'deletion',
|
|
3582
|
+
header: cookieHeader(ctx.names.delete, '', null, 'Max-Age=0'),
|
|
3583
|
+
cookie: deleteOnOrdinary,
|
|
3584
|
+
fetchReady,
|
|
3585
|
+
topLevel: false,
|
|
3586
|
+
});
|
|
3587
|
+
if (attempt.answered === 'incomplete' || attempt.planted === 'incomplete') {
|
|
3588
|
+
note(ctx.notes, 'cookie-plant.deletion.cleared', {
|
|
3589
|
+
cleared: 'incomplete',
|
|
3590
|
+
incomplete: 'delete attempt incomplete',
|
|
3591
|
+
browserContextId,
|
|
3592
|
+
...timingOf(handle),
|
|
3593
|
+
});
|
|
3594
|
+
return { ...attempt, cleared: 'incomplete' };
|
|
3595
|
+
}
|
|
3596
|
+
const after = await readJarWithCanary(handle, {
|
|
3597
|
+
name: ctx.names.delete,
|
|
3598
|
+
domain: deleteOnOrdinary.domain,
|
|
3599
|
+
path: deleteOnOrdinary.path,
|
|
3600
|
+
});
|
|
3601
|
+
const afterPlanted = plantedOf(after);
|
|
3602
|
+
if (afterPlanted === 'incomplete') {
|
|
3603
|
+
note(ctx.notes, 'cookie-plant.deletion.cleared', {
|
|
3604
|
+
cleared: 'incomplete',
|
|
3605
|
+
incomplete: 'after jar unreadable',
|
|
3606
|
+
browserContextId,
|
|
3607
|
+
...timingOf(handle),
|
|
3608
|
+
});
|
|
3609
|
+
return { ...attempt, cleared: 'incomplete' };
|
|
3610
|
+
}
|
|
3611
|
+
const cleared = afterPlanted === false;
|
|
3612
|
+
note(ctx.notes, 'cookie-plant.deletion.cleared', {
|
|
3613
|
+
cleared,
|
|
3614
|
+
via: after?.via,
|
|
3615
|
+
browserContextId,
|
|
3616
|
+
seedVia: seeded?.via,
|
|
3617
|
+
...timingOf(handle),
|
|
3618
|
+
});
|
|
3619
|
+
return { ...attempt, cleared };
|
|
3620
|
+
}),
|
|
3621
|
+
};
|
|
3622
|
+
}
|
|
3623
|
+
|
|
3624
|
+
function fillMissingAttempts(results, legacyReady) {
|
|
3625
|
+
for (const name of ALL_PATH_NAMES) {
|
|
3626
|
+
if (results[name]) continue;
|
|
3627
|
+
if (!legacyReady && (name === 'legacyHeaders' || name === 'legacyRaw'))
|
|
3628
|
+
results[name] = notSupportedAttempt();
|
|
3629
|
+
else if (CREDENTIAL_PATH_NAMES.includes(name)) results[name] = notSupportedAttempt();
|
|
3630
|
+
else results[name] = EMPTY_ATTEMPT;
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
async function runOneAttempt(name, run, ceiling, legacyReady, results, ran) {
|
|
3635
|
+
if (!legacyReady && (name === 'legacyHeaders' || name === 'legacyRaw')) {
|
|
3636
|
+
results[name] = notSupportedAttempt();
|
|
3637
|
+
ran.add(name);
|
|
3638
|
+
return;
|
|
3639
|
+
}
|
|
3640
|
+
try {
|
|
3641
|
+
results[name] = await withPathBudget(run(), ceiling, name);
|
|
3642
|
+
} catch (error) {
|
|
3643
|
+
results[name] = attemptRecord(
|
|
3644
|
+
{ ok: false, error: { message: String(error?.message ?? error) } },
|
|
3645
|
+
'incomplete'
|
|
3646
|
+
);
|
|
3647
|
+
}
|
|
3648
|
+
ran.add(name);
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
async function runAttempts(groups, budget = 5000, onlyPaths = null, legacyReady = true) {
|
|
3652
|
+
const results = {};
|
|
3653
|
+
const ran = new Set();
|
|
3654
|
+
const ceiling = pathCeiling(budget) + cleanupCeiling(budget) + Math.min(budget, 500);
|
|
3655
|
+
const allow =
|
|
3656
|
+
Array.isArray(onlyPaths) && onlyPaths.length ? new Set(onlyPaths.map(String)) : null;
|
|
3657
|
+
for (const group of groups) {
|
|
3658
|
+
for (const [name, run] of Object.entries(group ?? {})) {
|
|
3659
|
+
if (allow && !allow.has(name)) continue;
|
|
3660
|
+
await runOneAttempt(name, run, ceiling, legacyReady, results, ran);
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
fillMissingAttempts(results, legacyReady);
|
|
3664
|
+
return { results, ran };
|
|
3665
|
+
}
|
|
3666
|
+
|
|
3667
|
+
async function attachClientPage(client, pageTarget, internalSessions) {
|
|
3668
|
+
const attached = await capped(
|
|
3669
|
+
outcome(client.send('Target.attachToTarget', { targetId: pageTarget, flatten: true })),
|
|
3670
|
+
800,
|
|
3671
|
+
'attachToTarget'
|
|
3672
|
+
);
|
|
3673
|
+
if (!attached.ok) {
|
|
3674
|
+
if (sessionCut(attached) || refused(attached)) return { refused: attached, pageSession: null };
|
|
3675
|
+
return {
|
|
3676
|
+
incomplete: `client attach failed: ${attached.error?.message ?? attached.error}`,
|
|
3677
|
+
};
|
|
3678
|
+
}
|
|
3679
|
+
const pageSession = attached.result?.sessionId;
|
|
3680
|
+
if (pageSession) {
|
|
3681
|
+
internalSessions.add(pageSession);
|
|
3682
|
+
for (const [method, label] of [
|
|
3683
|
+
['Page.enable', 'Page.enable'],
|
|
3684
|
+
['Runtime.enable', 'Runtime.enable'],
|
|
3685
|
+
['Network.enable', 'Network.enable'],
|
|
3686
|
+
]) {
|
|
3687
|
+
const enabled = await capped(outcome(client.send(method, {}, pageSession)), 800, label);
|
|
3688
|
+
if (!enabled.ok) {
|
|
3689
|
+
if (sessionCut(enabled) || refused(enabled)) return { refused: enabled, pageSession };
|
|
3690
|
+
return {
|
|
3691
|
+
incomplete: `client ${label} failed: ${enabled.error?.message ?? enabled.error}`,
|
|
3692
|
+
};
|
|
3693
|
+
}
|
|
3694
|
+
}
|
|
3695
|
+
}
|
|
3696
|
+
return { pageSession };
|
|
3697
|
+
}
|
|
3698
|
+
|
|
3699
|
+
async function enableClientTransport(client, pageSession, notes) {
|
|
3700
|
+
const transport = await detectTransport(client, pageSession, notes);
|
|
3701
|
+
if (!transport.kind)
|
|
3702
|
+
return {
|
|
3703
|
+
incomplete:
|
|
3704
|
+
'neither Fetch.enable nor Network.setRequestInterception is available on the guarded client',
|
|
3705
|
+
};
|
|
3706
|
+
let fetchEnable = transport.fetchEnable ?? null;
|
|
3707
|
+
if (transport.fetch && refused(fetchEnable))
|
|
3708
|
+
return { transport, legacyReady: false, fetchEnable };
|
|
3709
|
+
if (transport.fetch && fetchEnable && !fetchEnable.ok)
|
|
3710
|
+
return { transport, legacyReady: false, fetchEnable };
|
|
3711
|
+
let legacyReady = transport.legacy;
|
|
3712
|
+
if (!legacyReady && transport.fetch && fetchEnable?.ok) {
|
|
3713
|
+
await outcome(client.send('Fetch.disable', {}, pageSession));
|
|
3714
|
+
const legacy = await enableLegacy(client, pageSession);
|
|
3715
|
+
legacyReady = legacy.ok;
|
|
3716
|
+
if (legacyReady) {
|
|
3717
|
+
transport.legacy = true;
|
|
3718
|
+
await outcome(client.send('Network.setRequestInterception', { patterns: [] }, pageSession));
|
|
3719
|
+
}
|
|
3720
|
+
fetchEnable = await capped(
|
|
3721
|
+
outcome(
|
|
3722
|
+
client.send(
|
|
3723
|
+
'Fetch.enable',
|
|
3724
|
+
{
|
|
3725
|
+
patterns: [
|
|
3726
|
+
{ urlPattern: '*', requestStage: 'Request' },
|
|
3727
|
+
{ urlPattern: '*', requestStage: 'Response' },
|
|
3728
|
+
],
|
|
3729
|
+
},
|
|
3730
|
+
pageSession
|
|
3731
|
+
)
|
|
3732
|
+
),
|
|
3733
|
+
800,
|
|
3734
|
+
'Fetch.enable'
|
|
3735
|
+
);
|
|
3736
|
+
if (refused(fetchEnable)) return { transport, legacyReady, fetchEnable };
|
|
3737
|
+
if (!fetchEnable.ok) return { transport, legacyReady, fetchEnable };
|
|
3738
|
+
if (legacyReady) note(notes, 'cookie-plant.legacyProbe', { ready: true });
|
|
3739
|
+
else
|
|
3740
|
+
note(notes, 'cookie-plant.legacyProbe', {
|
|
3741
|
+
ready: false,
|
|
3742
|
+
note: 'legacy unsupported in this Chrome',
|
|
3743
|
+
});
|
|
3744
|
+
}
|
|
3745
|
+
return { transport, legacyReady, fetchEnable };
|
|
3746
|
+
}
|
|
3747
|
+
|
|
3748
|
+
function credentialAttacks(ctx) {
|
|
3749
|
+
if (!ctx.credential) return null;
|
|
3750
|
+
const hostOnlyUrl = ctx.plantUrl;
|
|
3751
|
+
const hostOnlyCookie = {
|
|
3752
|
+
name: ctx.names.plant,
|
|
3753
|
+
value: `ho-${ctx.tag}`,
|
|
3754
|
+
domain: hostOf(hostOnlyUrl) || ctx.credentialHost,
|
|
3755
|
+
url: `${ctx.plantOrigin}/`,
|
|
3756
|
+
};
|
|
3757
|
+
const coverCookie = {
|
|
3758
|
+
name: ctx.names.plant,
|
|
3759
|
+
value: `dc-${ctx.tag}`,
|
|
3760
|
+
domain: ctx.credentialSiteDomain,
|
|
3761
|
+
url: `${ctx.plantOrigin}/`,
|
|
3762
|
+
};
|
|
3763
|
+
const subHost = `x.${ctx.credentialHost}`;
|
|
3764
|
+
const idpFixture =
|
|
3765
|
+
fixtureOriginFor(ctx.plantOrigin ?? ctx.ordinary, ctx.credentialHost) ??
|
|
3766
|
+
fixtureOriginFor(ctx.ordinary, ctx.credentialHost);
|
|
3767
|
+
const subUrl = `${fixtureOriginFor(idpFixture ?? ctx.ordinary, subHost) ?? `https://${subHost}`}/data?n=sub-${ctx.tag}`;
|
|
3768
|
+
const diag = (handle) => ({
|
|
3769
|
+
handle,
|
|
3770
|
+
budget: ctx.budget,
|
|
3771
|
+
notes: ctx.notes,
|
|
3772
|
+
fixtureLog: ctx.fixtureLog,
|
|
3773
|
+
legStartedAt: ctx.legStartedAt,
|
|
3774
|
+
firstIncomplete: ctx.firstIncomplete,
|
|
3775
|
+
});
|
|
3776
|
+
return {
|
|
3777
|
+
hostOnly: () =>
|
|
3778
|
+
withFreshAttemptTab(ctx, (handle) => {
|
|
3779
|
+
const fetchReady = Boolean(handle.transport?.fetch);
|
|
3780
|
+
return runPlant({
|
|
3781
|
+
...diag(handle),
|
|
3782
|
+
url: hostOnlyUrl,
|
|
3783
|
+
cookie: hostOnlyCookie,
|
|
3784
|
+
label: 'hostOnly',
|
|
3785
|
+
topLevel: true,
|
|
3786
|
+
build: () =>
|
|
3787
|
+
fetchReady
|
|
3788
|
+
? fetchFulfill({
|
|
3789
|
+
responseHeaders: [
|
|
3790
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
3791
|
+
{
|
|
3792
|
+
name: 'Set-Cookie',
|
|
3793
|
+
value: cookieHeader(ctx.names.plant, hostOnlyCookie.value, null),
|
|
3794
|
+
},
|
|
3795
|
+
],
|
|
3796
|
+
body: b64text('ok'),
|
|
3797
|
+
})
|
|
3798
|
+
: legacyContinue({
|
|
3799
|
+
rawResponse: rawHttpResponse({
|
|
3800
|
+
code: 200,
|
|
3801
|
+
phrase: 'OK',
|
|
3802
|
+
headers: [
|
|
3803
|
+
{
|
|
3804
|
+
name: 'Set-Cookie',
|
|
3805
|
+
value: cookieHeader(ctx.names.plant, hostOnlyCookie.value, null),
|
|
3806
|
+
},
|
|
3807
|
+
],
|
|
3808
|
+
body: 'ok',
|
|
3809
|
+
}),
|
|
3810
|
+
}),
|
|
3811
|
+
});
|
|
3812
|
+
}),
|
|
3813
|
+
domainCover: () =>
|
|
3814
|
+
withFreshAttemptTab(ctx, (handle) => {
|
|
3815
|
+
const fetchReady = Boolean(handle.transport?.fetch);
|
|
3816
|
+
return runPlant({
|
|
3817
|
+
...diag(handle),
|
|
3818
|
+
url: subUrl,
|
|
3819
|
+
cookie: coverCookie,
|
|
3820
|
+
label: 'domainCover',
|
|
3821
|
+
topLevel: true,
|
|
3822
|
+
build: () =>
|
|
3823
|
+
fetchReady
|
|
3824
|
+
? fetchFulfill({
|
|
3825
|
+
responseHeaders: [
|
|
3826
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
3827
|
+
{
|
|
3828
|
+
name: 'Set-Cookie',
|
|
3829
|
+
value: cookieHeader(
|
|
3830
|
+
ctx.names.plant,
|
|
3831
|
+
coverCookie.value,
|
|
3832
|
+
ctx.credentialSiteDomain
|
|
3833
|
+
),
|
|
3834
|
+
},
|
|
3835
|
+
],
|
|
3836
|
+
body: b64text('ok'),
|
|
3837
|
+
})
|
|
3838
|
+
: legacyContinue({
|
|
3839
|
+
rawResponse: rawHttpResponse({
|
|
3840
|
+
code: 200,
|
|
3841
|
+
phrase: 'OK',
|
|
3842
|
+
headers: [
|
|
3843
|
+
{
|
|
3844
|
+
name: 'Set-Cookie',
|
|
3845
|
+
value: cookieHeader(
|
|
3846
|
+
ctx.names.plant,
|
|
3847
|
+
coverCookie.value,
|
|
3848
|
+
ctx.credentialSiteDomain
|
|
3849
|
+
),
|
|
3850
|
+
},
|
|
3851
|
+
],
|
|
3852
|
+
body: 'ok',
|
|
3853
|
+
}),
|
|
3854
|
+
}),
|
|
3855
|
+
});
|
|
3856
|
+
}),
|
|
3857
|
+
subHost: () =>
|
|
3858
|
+
withFreshAttemptTab(ctx, (handle) => {
|
|
3859
|
+
const fetchReady = Boolean(handle.transport?.fetch);
|
|
3860
|
+
const subCookie = {
|
|
3861
|
+
name: ctx.names.ordinary,
|
|
3862
|
+
value: `sub-${ctx.tag}`,
|
|
3863
|
+
domain: `.${subHost}`,
|
|
3864
|
+
url: `${fixtureOriginFor(idpFixture ?? ctx.ordinary, subHost) ?? `https://${subHost}`}/`,
|
|
3865
|
+
};
|
|
3866
|
+
return allowedHeaderAttempt({
|
|
3867
|
+
...diag(handle),
|
|
3868
|
+
url: subUrl,
|
|
3869
|
+
label: 'subHost',
|
|
3870
|
+
header: cookieHeader(ctx.names.ordinary, subCookie.value, `.${subHost}`),
|
|
3871
|
+
cookie: subCookie,
|
|
3872
|
+
fetchReady,
|
|
3873
|
+
topLevel: true,
|
|
3874
|
+
});
|
|
3875
|
+
}),
|
|
3876
|
+
};
|
|
3877
|
+
}
|
|
3878
|
+
|
|
3879
|
+
function sessionBlockedPlantResults(credential, notes = []) {
|
|
3880
|
+
const blocked = Object.fromEntries(
|
|
3881
|
+
ALL_PATH_NAMES.filter((name) => !['ordinary', 'adobe', 'deletion'].includes(name)).map(
|
|
3882
|
+
(name) => [
|
|
3883
|
+
name,
|
|
3884
|
+
scoreProtectedPlant({
|
|
3885
|
+
pauseCount: 0,
|
|
3886
|
+
fixtureHits: 0,
|
|
3887
|
+
planted: 'incomplete',
|
|
3888
|
+
pageHref: null,
|
|
3889
|
+
notes,
|
|
3890
|
+
label: name,
|
|
3891
|
+
triggerOutcome: {
|
|
3892
|
+
ok: false,
|
|
3893
|
+
error: { message: 'slicc: refused: session cut on protected execution context' },
|
|
3894
|
+
},
|
|
3895
|
+
blockedMarkers: [],
|
|
3896
|
+
triggerIssued: false,
|
|
3897
|
+
fetchEnableOk: null,
|
|
3898
|
+
plantSurfaceRefused: true,
|
|
3899
|
+
}),
|
|
3900
|
+
]
|
|
3901
|
+
)
|
|
3902
|
+
);
|
|
3903
|
+
return finishCookiePlant({
|
|
3904
|
+
control: false,
|
|
3905
|
+
credential,
|
|
3906
|
+
fetch: false,
|
|
3907
|
+
legacy: false,
|
|
3908
|
+
evidenceIncomplete: true,
|
|
3909
|
+
results: {
|
|
3910
|
+
...Object.fromEntries(ALL_PATH_NAMES.map((name) => [name, EMPTY_ATTEMPT])),
|
|
3911
|
+
...blocked,
|
|
3912
|
+
ordinary: EMPTY_ATTEMPT,
|
|
3913
|
+
adobe: EMPTY_ATTEMPT,
|
|
3914
|
+
deletion: EMPTY_ATTEMPT,
|
|
3915
|
+
},
|
|
3916
|
+
});
|
|
3917
|
+
}
|
|
3918
|
+
|
|
3919
|
+
async function proveDoorOnOwnTab({
|
|
3920
|
+
reader,
|
|
3921
|
+
homeUrl,
|
|
3922
|
+
doorOrigin,
|
|
3923
|
+
tag,
|
|
3924
|
+
budget,
|
|
3925
|
+
notes,
|
|
3926
|
+
internalSessions,
|
|
3927
|
+
plantName,
|
|
3928
|
+
browserContextId = null,
|
|
3929
|
+
browserContexts = false,
|
|
3930
|
+
}) {
|
|
3931
|
+
const host = hostOf(doorOrigin);
|
|
3932
|
+
const domain = `.${host}`;
|
|
3933
|
+
const value = `door-${tag}`;
|
|
3934
|
+
const setCookie = cookieHeader(plantName, value, domain);
|
|
3935
|
+
const probePage = await openPage(reader, homeUrl, notes, internalSessions, browserContextId);
|
|
3936
|
+
if (!probePage.ok)
|
|
3937
|
+
return { incomplete: `open failed: ${probePage.error?.message ?? probePage.error}` };
|
|
3938
|
+
if (probePage.result?.incomplete) return { incomplete: probePage.result.incomplete };
|
|
3939
|
+
const probeSession = probePage.result.sessionId;
|
|
3940
|
+
const probeTarget = probePage.result.targetId;
|
|
3941
|
+
const readerTransport = await detectTransport(reader, probeSession, notes);
|
|
3942
|
+
await capped(
|
|
3943
|
+
outcome(reader.send('Target.closeTarget', { targetId: probeTarget })),
|
|
3944
|
+
800,
|
|
3945
|
+
'door-probe-close'
|
|
3946
|
+
);
|
|
3947
|
+
if (!readerTransport.kind) {
|
|
3948
|
+
return {
|
|
3949
|
+
incomplete:
|
|
3950
|
+
'neither Fetch.enable nor Network.setRequestInterception is available on the unguarded session',
|
|
3951
|
+
live: false,
|
|
3952
|
+
};
|
|
3953
|
+
}
|
|
3954
|
+
if (readerTransport.kind === 'fetch') {
|
|
3955
|
+
const raw = await measureRawDoor(
|
|
3956
|
+
{
|
|
3957
|
+
reader,
|
|
3958
|
+
homeUrl,
|
|
3959
|
+
notes,
|
|
3960
|
+
internalSessions,
|
|
3961
|
+
budget,
|
|
3962
|
+
browserContextId,
|
|
3963
|
+
browserContexts,
|
|
3964
|
+
plantUrl: `${doorOrigin}/data?n=door-${tag}`,
|
|
3965
|
+
plantCookie: {
|
|
3966
|
+
name: plantName,
|
|
3967
|
+
value,
|
|
3968
|
+
domain,
|
|
3969
|
+
url: `${doorOrigin}/`,
|
|
3970
|
+
},
|
|
3971
|
+
forcedRaw: null,
|
|
3972
|
+
},
|
|
3973
|
+
{
|
|
3974
|
+
label: 'door',
|
|
3975
|
+
value,
|
|
3976
|
+
build: (paused) => ({
|
|
3977
|
+
send: (client, pause) =>
|
|
3978
|
+
fulfillPaused(client, pause, {
|
|
3979
|
+
responseCode: 200,
|
|
3980
|
+
responseHeaders: [
|
|
3981
|
+
{ name: 'content-type', value: 'text/plain' },
|
|
3982
|
+
{ name: 'Set-Cookie', value: setCookie },
|
|
3983
|
+
],
|
|
3984
|
+
body: b64text(value),
|
|
3985
|
+
}),
|
|
3986
|
+
}),
|
|
3987
|
+
}
|
|
3988
|
+
);
|
|
3989
|
+
if (raw.incomplete || raw.observed !== true) {
|
|
3990
|
+
return { live: false, incomplete: raw.incomplete ?? 'raw leg incomplete' };
|
|
3991
|
+
}
|
|
3992
|
+
if (!raw.doorPresent) {
|
|
3993
|
+
return {
|
|
3994
|
+
live: false,
|
|
3995
|
+
incomplete: 'raw leg: Chrome did not store Domain=.<protected host> Set-Cookie',
|
|
3996
|
+
};
|
|
3997
|
+
}
|
|
3998
|
+
note(notes, 'cookie-plant.door', {
|
|
3999
|
+
answered: raw.answered,
|
|
4000
|
+
planted: raw.planted,
|
|
4001
|
+
domain,
|
|
4002
|
+
});
|
|
4003
|
+
return { live: true };
|
|
4004
|
+
}
|
|
4005
|
+
const doorPage = await openPage(reader, homeUrl, notes, internalSessions, browserContextId);
|
|
4006
|
+
if (!doorPage.ok)
|
|
4007
|
+
return { incomplete: `open failed: ${doorPage.error?.message ?? doorPage.error}` };
|
|
4008
|
+
if (doorPage.result?.incomplete) return { incomplete: doorPage.result.incomplete };
|
|
4009
|
+
const doorContextId = await resolveTabContextId(
|
|
4010
|
+
reader,
|
|
4011
|
+
doorPage.result.targetId,
|
|
4012
|
+
browserContextId ?? null
|
|
4013
|
+
);
|
|
4014
|
+
if (browserContexts && (doorContextId == null || doorContextId === ''))
|
|
4015
|
+
return { incomplete: 'unknown context', browserContextId: null };
|
|
4016
|
+
const door = await proveDoor({
|
|
4017
|
+
reader,
|
|
4018
|
+
sessionId: doorPage.result.sessionId,
|
|
4019
|
+
protectedOrigin: doorOrigin,
|
|
4020
|
+
homeUrl,
|
|
4021
|
+
tag,
|
|
4022
|
+
budget,
|
|
4023
|
+
notes,
|
|
4024
|
+
transport: readerTransport,
|
|
4025
|
+
plantName,
|
|
4026
|
+
browserContextId: doorContextId,
|
|
4027
|
+
browserContexts,
|
|
4028
|
+
});
|
|
4029
|
+
await capped(
|
|
4030
|
+
outcome(reader.send('Target.closeTarget', { targetId: doorPage.result.targetId })),
|
|
4031
|
+
800,
|
|
4032
|
+
'door-close'
|
|
4033
|
+
);
|
|
4034
|
+
return door.live ? { live: true, doorVia: door.doorVia } : { ...door, live: false };
|
|
4035
|
+
}
|
|
4036
|
+
|
|
4037
|
+
async function openPlantClient({
|
|
4038
|
+
client,
|
|
4039
|
+
reader,
|
|
4040
|
+
homeUrl,
|
|
4041
|
+
notes,
|
|
4042
|
+
internalSessions,
|
|
4043
|
+
control,
|
|
4044
|
+
credential,
|
|
4045
|
+
browserContextId = null,
|
|
4046
|
+
}) {
|
|
4047
|
+
const page = await openPage(reader, homeUrl, notes, internalSessions, browserContextId);
|
|
4048
|
+
if (!page.ok)
|
|
4049
|
+
return { done: { incomplete: `open failed: ${page.error?.message ?? page.error}` } };
|
|
4050
|
+
if (page.result?.incomplete) return { done: { incomplete: page.result.incomplete } };
|
|
4051
|
+
const readerSession = page.result.sessionId;
|
|
4052
|
+
const pageTarget = page.result.targetId;
|
|
4053
|
+
const attached = await attachClientPage(client, pageTarget, internalSessions);
|
|
4054
|
+
if (attached.incomplete) {
|
|
4055
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
4056
|
+
return { done: { incomplete: attached.incomplete, live: true } };
|
|
4057
|
+
}
|
|
4058
|
+
if (attached.refused && sessionCut(attached.refused)) {
|
|
4059
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
4060
|
+
return {
|
|
4061
|
+
done: {
|
|
4062
|
+
live: true,
|
|
4063
|
+
incomplete: String(attached.refused.error?.message ?? 'session refused before trigger'),
|
|
4064
|
+
...incompletePaths(),
|
|
4065
|
+
},
|
|
4066
|
+
};
|
|
4067
|
+
}
|
|
4068
|
+
const pageSession = attached.pageSession;
|
|
4069
|
+
if (!pageSession) {
|
|
4070
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
4071
|
+
return {
|
|
4072
|
+
done: {
|
|
4073
|
+
live: true,
|
|
4074
|
+
incomplete: 'client has no page session for interception attempts',
|
|
4075
|
+
...incompletePaths(),
|
|
4076
|
+
},
|
|
4077
|
+
};
|
|
4078
|
+
}
|
|
4079
|
+
const enabled = await enableClientTransport(client, pageSession, notes);
|
|
4080
|
+
if (enabled.incomplete) {
|
|
4081
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
4082
|
+
if (sessionCut({ ok: false, error: { message: enabled.incomplete } }) && !control)
|
|
4083
|
+
return { done: sessionBlockedPlantResults(credential, notes) };
|
|
4084
|
+
return { done: { live: true, incomplete: enabled.incomplete } };
|
|
4085
|
+
}
|
|
4086
|
+
if (
|
|
4087
|
+
!control &&
|
|
4088
|
+
enabled.fetchEnable &&
|
|
4089
|
+
/session cut on protected execution context/i.test(
|
|
4090
|
+
String(enabled.fetchEnable.error?.message ?? '')
|
|
4091
|
+
)
|
|
4092
|
+
) {
|
|
4093
|
+
await outcome(reader.send('Target.closeTarget', { targetId: pageTarget }));
|
|
4094
|
+
return { done: sessionBlockedPlantResults(credential, notes) };
|
|
4095
|
+
}
|
|
4096
|
+
return { readerSession, pageTarget, pageSession, enabled };
|
|
4097
|
+
}
|
|
4098
|
+
|
|
4099
|
+
export async function cookiePlant({
|
|
4100
|
+
client,
|
|
4101
|
+
reader,
|
|
4102
|
+
protectedOrigin,
|
|
4103
|
+
ordinary,
|
|
4104
|
+
tag,
|
|
4105
|
+
internalSessions = new Set(),
|
|
4106
|
+
notes = [],
|
|
4107
|
+
budget = 5000,
|
|
4108
|
+
control = false,
|
|
4109
|
+
mode = 'set-cookie',
|
|
4110
|
+
credentialOrigin,
|
|
4111
|
+
fixtureLog,
|
|
4112
|
+
blockedMarkers,
|
|
4113
|
+
onlyPaths = null,
|
|
4114
|
+
forcedRaw = null,
|
|
4115
|
+
browserContextId = null,
|
|
4116
|
+
browserContexts = false,
|
|
4117
|
+
}) {
|
|
4118
|
+
if (!reader) return { incomplete: 'missing unguarded reader' };
|
|
4119
|
+
const credential = mode === 'credential' || mode === 'credential-set-cookie';
|
|
4120
|
+
const sourceOrigin = credential ? (credentialOrigin ?? protectedOrigin) : protectedOrigin;
|
|
4121
|
+
if (!sourceOrigin) return { incomplete: 'missing protected origin' };
|
|
4122
|
+
if (!ordinary) return { incomplete: 'missing ordinary origin' };
|
|
4123
|
+
|
|
4124
|
+
const names = cookieNames(tag);
|
|
4125
|
+
const credentialHost = hostOf(sourceOrigin);
|
|
4126
|
+
const mappedOrigin = fixtureOriginFor(ordinary, credentialHost) ?? sourceOrigin;
|
|
4127
|
+
const plantOrigin = control ? ordinary : credential ? mappedOrigin : sourceOrigin;
|
|
4128
|
+
const credentialSiteDomain = `.${siteHost(credentialHost)}`;
|
|
4129
|
+
const domain = credential
|
|
4130
|
+
? control
|
|
4131
|
+
? `.${hostOf(ordinary)}`
|
|
4132
|
+
: credentialSiteDomain
|
|
4133
|
+
: `.${hostOf(plantOrigin)}`;
|
|
4134
|
+
const homeUrl = `${ordinary}/doc?n=cookie-plant-${tag}`;
|
|
4135
|
+
|
|
4136
|
+
const door = await proveDoorOnOwnTab({
|
|
4137
|
+
reader,
|
|
4138
|
+
homeUrl,
|
|
4139
|
+
doorOrigin: credential ? mappedOrigin : sourceOrigin,
|
|
4140
|
+
tag,
|
|
4141
|
+
budget,
|
|
4142
|
+
notes,
|
|
4143
|
+
internalSessions,
|
|
4144
|
+
plantName: names.plant,
|
|
4145
|
+
browserContextId,
|
|
4146
|
+
browserContexts,
|
|
4147
|
+
});
|
|
4148
|
+
if (!door.live) return door;
|
|
4149
|
+
|
|
4150
|
+
const probe = await openPlantClient({
|
|
4151
|
+
client,
|
|
4152
|
+
reader,
|
|
4153
|
+
homeUrl,
|
|
4154
|
+
notes,
|
|
4155
|
+
internalSessions,
|
|
4156
|
+
control,
|
|
4157
|
+
credential,
|
|
4158
|
+
browserContextId,
|
|
4159
|
+
});
|
|
4160
|
+
if (probe.done) return probe.done;
|
|
4161
|
+
const transport = probe.enabled.transport;
|
|
4162
|
+
const legacyReady = probe.enabled.legacyReady;
|
|
4163
|
+
await capped(disableInterception(client, probe.pageSession, transport), 800, 'probe-disable');
|
|
4164
|
+
await capped(
|
|
4165
|
+
outcome(reader.send('Target.closeTarget', { targetId: probe.pageTarget })),
|
|
4166
|
+
800,
|
|
4167
|
+
'probe-close'
|
|
4168
|
+
);
|
|
4169
|
+
|
|
4170
|
+
const ctx = plantCtx({
|
|
4171
|
+
client,
|
|
4172
|
+
reader,
|
|
4173
|
+
plantUrl: `${plantOrigin}/data?n=plant-${tag}`,
|
|
4174
|
+
plantCookie: {
|
|
4175
|
+
name: names.plant,
|
|
4176
|
+
value: `p-${tag}`,
|
|
4177
|
+
domain,
|
|
4178
|
+
url: `${plantOrigin}/`,
|
|
4179
|
+
},
|
|
4180
|
+
domain,
|
|
4181
|
+
tag,
|
|
4182
|
+
names,
|
|
4183
|
+
plantOrigin,
|
|
4184
|
+
protectedOrigin: sourceOrigin,
|
|
4185
|
+
ordinary,
|
|
4186
|
+
homeUrl,
|
|
4187
|
+
transport,
|
|
4188
|
+
budget,
|
|
4189
|
+
notes,
|
|
4190
|
+
internalSessions,
|
|
4191
|
+
credential,
|
|
4192
|
+
credentialHost,
|
|
4193
|
+
credentialSiteDomain,
|
|
4194
|
+
fixtureLog,
|
|
4195
|
+
legStartedAt: Date.now(),
|
|
4196
|
+
firstIncomplete: { noted: false },
|
|
4197
|
+
guardedProtected: !control && !credential,
|
|
4198
|
+
blockedMarkers: Array.isArray(blockedMarkers) ? blockedMarkers : [],
|
|
4199
|
+
proofTag: tag,
|
|
4200
|
+
rawDoors: {},
|
|
4201
|
+
forcedRaw: forcedRaw && typeof forcedRaw === 'object' ? forcedRaw : null,
|
|
4202
|
+
browserContextId,
|
|
4203
|
+
browserContexts: Boolean(browserContexts),
|
|
4204
|
+
});
|
|
4205
|
+
|
|
4206
|
+
const { results, ran } = await runAttempts(
|
|
4207
|
+
control
|
|
4208
|
+
? [controlAttacks(ctx)]
|
|
4209
|
+
: [
|
|
4210
|
+
controlAttacks(ctx),
|
|
4211
|
+
fetchAttacks(ctx),
|
|
4212
|
+
legacyAttacks(ctx, legacyReady),
|
|
4213
|
+
credential ? credentialAttacks(ctx) : null,
|
|
4214
|
+
],
|
|
4215
|
+
budget,
|
|
4216
|
+
onlyPaths,
|
|
4217
|
+
legacyReady
|
|
4218
|
+
);
|
|
4219
|
+
|
|
4220
|
+
const evidenceIncomplete =
|
|
4221
|
+
!control &&
|
|
4222
|
+
[...ran].some((name) => {
|
|
4223
|
+
const attempt = results[name];
|
|
4224
|
+
if (!attempt || attempt.answered === 'not-supported') return false;
|
|
4225
|
+
return (
|
|
4226
|
+
attempt.planted === 'incomplete' ||
|
|
4227
|
+
attempt.answered === 'incomplete' ||
|
|
4228
|
+
attempt.refused === 'incomplete'
|
|
4229
|
+
);
|
|
4230
|
+
});
|
|
4231
|
+
|
|
4232
|
+
return finishCookiePlant({
|
|
4233
|
+
control,
|
|
4234
|
+
credential,
|
|
4235
|
+
fetch: Boolean(transport.fetch),
|
|
4236
|
+
legacy: Boolean(legacyReady),
|
|
4237
|
+
evidenceIncomplete,
|
|
4238
|
+
results,
|
|
4239
|
+
});
|
|
4240
|
+
}
|
|
4241
|
+
|
|
4242
|
+
function finishCookiePlant({ control, credential, fetch, legacy, evidenceIncomplete, results }) {
|
|
4243
|
+
return Object.assign(
|
|
4244
|
+
{
|
|
4245
|
+
live: true,
|
|
4246
|
+
control: Boolean(control),
|
|
4247
|
+
fetch,
|
|
4248
|
+
legacy,
|
|
4249
|
+
credential,
|
|
4250
|
+
...(evidenceIncomplete && !control
|
|
4251
|
+
? { incomplete: 'protected plant evidence incomplete' }
|
|
4252
|
+
: {}),
|
|
4253
|
+
},
|
|
4254
|
+
...Object.entries(results).map(([name, attempt]) => flattenAttempt(name, attempt))
|
|
4255
|
+
);
|
|
4256
|
+
}
|
|
4257
|
+
|
|
4258
|
+
export { cookieNames };
|
|
4259
|
+
|
|
4260
|
+
export const cookiePlantHandleApi = {
|
|
4261
|
+
requireAttemptHandle,
|
|
4262
|
+
jarContextIncomplete,
|
|
4263
|
+
plantCanary,
|
|
4264
|
+
clearCookie,
|
|
4265
|
+
readJar,
|
|
4266
|
+
readJarView,
|
|
4267
|
+
readJarWithCanary,
|
|
4268
|
+
seedCookie,
|
|
4269
|
+
finishPlant,
|
|
4270
|
+
recordSessionCut,
|
|
4271
|
+
continueItselfEvidence,
|
|
4272
|
+
evidenceAfterTrigger,
|
|
4273
|
+
};
|