@ai-ecoverse/slicc-browsers 1.44.0 → 1.46.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.
@@ -1,1511 +0,0 @@
1
- import { outcome, parseURL, waitFor } from './guard-driver.mjs';
2
- import { createObserverTarget } from './observer-target.mjs';
3
-
4
- const refused = (out) => !out.ok && /^slicc: refused:/.test(out.error?.message ?? '');
5
- const unsupported = (out) =>
6
- !out.ok &&
7
- /(?:Method|method) (?:not found|doesn't exist)|wasn't found|Unknown method|not supported|Not supported/i.test(
8
- String(out.error?.message ?? out.error ?? '')
9
- );
10
-
11
- const hostOf = (text) => {
12
- const u = typeof text === 'string' ? parseURL(text) : text;
13
- const host = (u?.hostname ?? '').toLowerCase();
14
- return host.endsWith('.') ? host.slice(0, -1) : host;
15
- };
16
-
17
- const originOf = (text) => {
18
- const u = parseURL(text);
19
- if (!u?.host) return null;
20
- const host = hostOf(u);
21
- if (!host) return null;
22
- return `${u.protocol}//${host}${u.port ? `:${u.port}` : ''}`;
23
- };
24
-
25
- const siteHost = (host) => {
26
- const parts = host.split('.');
27
- return parts.length >= 2 ? parts.slice(-2).join('.') : host;
28
- };
29
-
30
- const hstsPreloaded = (host) => {
31
- const name = String(host ?? '')
32
- .toLowerCase()
33
- .replace(/\.$/, '');
34
- return (
35
- name === 'adobe.com' ||
36
- name.endsWith('.adobe.com') ||
37
- name === 'adobelogin.com' ||
38
- name.endsWith('.adobelogin.com')
39
- );
40
- };
41
-
42
- function siteOf(url) {
43
- const parsed = parseURL(url);
44
- if (!parsed?.hostname) return null;
45
- return `${parsed.protocol}//${siteHost(hostOf(parsed))}`;
46
- }
47
-
48
- function fixtureOriginFor(templateUrl, host, { insecurePreloaded = false } = {}) {
49
- const parsed = parseURL(templateUrl);
50
- if (!parsed?.hostname && !host) return null;
51
- const name = host ?? hostOf(parsed);
52
- const port = parsed?.port ? `:${parsed.port}` : '';
53
- const scheme =
54
- !insecurePreloaded && hstsPreloaded(name) ? 'https:' : (parsed?.protocol ?? 'http:');
55
- return `${scheme}//${name}${port}`;
56
- }
57
-
58
- const partitionSite = (cookie) => {
59
- const key = cookie?.partitionKey;
60
- return typeof key === 'string' ? key : (key?.topLevelSite ?? null);
61
- };
62
-
63
- const partitionedUnder = (cookie, site) => {
64
- const key = partitionSite(cookie);
65
- return Boolean(key) && hostOf(key) === hostOf(site);
66
- };
67
-
68
- function cookieHit(cookies, { name, host, value }) {
69
- return (cookies ?? []).some((cookie) => {
70
- if (cookie?.name !== name) return false;
71
- if (value !== undefined && cookie.value !== value) return false;
72
- const domain = String(cookie.domain ?? '')
73
- .toLowerCase()
74
- .replace(/^\./, '')
75
- .replace(/\.$/, '');
76
- return !host || domain === host || host.endsWith(`.${domain}`) || domain === '' || !domain;
77
- });
78
- }
79
-
80
- const hasEntry = (entries, key, value) =>
81
- (entries ?? []).some(
82
- (entry) => entry?.[0] === key && (value === undefined || entry?.[1] === value)
83
- );
84
-
85
- async function pageReady(reader, sessionId, accept) {
86
- const ev = await outcome(
87
- reader.send(
88
- 'Runtime.evaluate',
89
- {
90
- expression: `({href:location.href,ready:document.readyState,title:document.title})`,
91
- returnByValue: true,
92
- },
93
- sessionId
94
- )
95
- );
96
- const value = ev.result?.result?.value;
97
- return Boolean(
98
- ev.ok && value?.ready === 'complete' && typeof value.href === 'string' && accept(value)
99
- );
100
- }
101
-
102
- async function openPage(reader, url, notes, internalSessions) {
103
- const opened = await outcome(
104
- createObserverTarget(reader, { url }, notes).then(async (created) => {
105
- const { sessionId } = await reader.send('Target.attachToTarget', {
106
- targetId: created.targetId,
107
- flatten: true,
108
- });
109
- await reader.send('Page.enable', {}, sessionId);
110
- await reader.send('Runtime.enable', {}, sessionId);
111
- await reader.send('Network.enable', {}, sessionId);
112
- const ready = await waitFor(
113
- () =>
114
- pageReady(
115
- reader,
116
- sessionId,
117
- (value) => value.href.includes('/credential') && value.title === 'credential'
118
- ),
119
- 5000
120
- );
121
- if (!ready) throw new Error('credential page did not become ready');
122
- return { targetId: created.targetId, sessionId };
123
- })
124
- );
125
- if (!opened.ok) return opened;
126
- internalSessions.add(opened.result.sessionId);
127
- return opened;
128
- }
129
-
130
- const credentialCookieParams = (planted, origin, tag) => [
131
- [
132
- 'HttpOnly',
133
- { name: planted.httpOnly, value: tag, url: `${origin}/`, httpOnly: true, path: '/' },
134
- ],
135
- ['open', { name: planted.open, value: tag, url: `${origin}/`, httpOnly: false, path: '/' }],
136
- ['parent-domain', { name: planted.parent, value: tag, domain: planted.parentDomain, path: '/' }],
137
- ];
138
-
139
- async function setCookies(reader, sessionId, list) {
140
- for (const [label, params] of list) {
141
- const set = await outcome(reader.send('Network.setCookie', params, sessionId));
142
- if (!set.ok || set.result?.success === false)
143
- return `plant ${label} cookie failed: ${set.error?.message ?? 'no success'}`;
144
- }
145
- return null;
146
- }
147
-
148
- async function plantState(reader, { origin, host, tag, sessionId }) {
149
- const names = {
150
- httpOnly: `cred-http-${tag}`,
151
- open: `cred-open-${tag}`,
152
- parent: `cred-parent-${tag}`,
153
- parentDomain: `.${siteHost(host)}`,
154
- };
155
- const failed = await setCookies(reader, sessionId, credentialCookieParams(names, origin, tag));
156
- if (failed) return { incomplete: failed };
157
- const lsKey = `cred-ls-${tag}`;
158
- const dbName = `cred-db-${tag}`;
159
- const cacheName = `cred-cache-${tag}`;
160
- const cacheUrl = `${origin}/cred-cache-${tag}`;
161
- const q = JSON.stringify;
162
- const planted = await outcome(
163
- reader.send(
164
- 'Runtime.evaluate',
165
- {
166
- expression: `(async()=>{
167
- const secure=self.isSecureContext===true;
168
- const localStorageOk=(()=>{try{localStorage.setItem(${q(lsKey)},${q(tag)});return localStorage.getItem(${q(lsKey)})===${q(tag)};}catch(e){return 'err:'+e.message;}})();
169
- const idb=await (async()=>{try{const open=indexedDB.open(${q(dbName)},1);const db=await new Promise((ok,err)=>{open.onupgradeneeded=()=>open.result.createObjectStore('s');open.onsuccess=()=>ok(open.result);open.onerror=()=>err(open.error);});const tx=db.transaction('s','readwrite');tx.objectStore('s').put(${q(tag)},'k');await new Promise((ok,err)=>{tx.oncomplete=()=>ok(true);tx.onerror=()=>err(tx.error);tx.onabort=()=>err(tx.error);});db.close();return true;}catch(e){return 'err:'+e.message;}})();
170
- const cache=await (async()=>{if(!secure)return 'insecure-context';try{const c=await caches.open(${q(cacheName)});await c.put(${q(cacheUrl)},new Response(${q(tag)}));const m=await c.match(${q(cacheUrl)});return m?await m.text():false;}catch(e){return 'err:'+e.message;}})();
171
- return {secure,localStorage:localStorageOk,idb,cache};
172
- })()`,
173
- awaitPromise: true,
174
- returnByValue: true,
175
- },
176
- sessionId
177
- )
178
- );
179
- const value = planted.result?.result?.value;
180
- if (!planted.ok || !value || value.localStorage !== true || value.idb !== true)
181
- return {
182
- incomplete: `plant storage failed: ${planted.error?.message ?? JSON.stringify(value)}`,
183
- };
184
- const secure = value.secure === true;
185
- const cachePlanted = secure && value.cache === tag;
186
- if (secure && !cachePlanted)
187
- return {
188
- incomplete: `plant cache failed: ${typeof value.cache === 'string' ? value.cache : JSON.stringify(value.cache)}`,
189
- };
190
- const proved = await provePlanted(reader, sessionId, {
191
- ...names,
192
- origin,
193
- host,
194
- tag,
195
- lsKey,
196
- dbName,
197
- cacheName,
198
- cachePlanted,
199
- });
200
- if (proved.incomplete) return proved;
201
- return {
202
- ...names,
203
- lsKey,
204
- dbName,
205
- secure,
206
- cacheName: cachePlanted ? cacheName : null,
207
- cacheUrl: cachePlanted ? cacheUrl : null,
208
- cachePlanted,
209
- };
210
- }
211
-
212
- async function readerEntries(reader, sessions, storageId) {
213
- for (const session of sessions) {
214
- const read = await outcome(
215
- reader.send('DOMStorage.getDOMStorageItems', { storageId }, session)
216
- );
217
- if (read.ok && Array.isArray(read.result?.entries)) return read.result.entries;
218
- }
219
- return null;
220
- }
221
-
222
- async function readerDatabases(reader, sessionId, origin) {
223
- const read = await outcome(
224
- reader.send('IndexedDB.requestDatabaseNames', { securityOrigin: origin }, sessionId)
225
- );
226
- return read.ok ? (read.result?.databaseNames ?? []) : null;
227
- }
228
-
229
- async function readerCaches(reader, sessionId, origin) {
230
- const read = await outcome(
231
- reader.send('CacheStorage.requestCacheNames', { securityOrigin: origin }, sessionId)
232
- );
233
- return read.ok ? (read.result?.caches ?? []) : null;
234
- }
235
-
236
- const cacheNameOf = (cache) => cache?.cacheName ?? cache;
237
-
238
- const survivingCookies = (cookies, planted, host, tag) =>
239
- cookieHit(cookies, { name: planted.httpOnly, host, value: tag }) &&
240
- cookieHit(cookies, { name: planted.parent, host, value: tag });
241
-
242
- async function provePlanted(reader, sessionId, planted) {
243
- const { origin, host, tag, lsKey, dbName, cacheName, cachePlanted } = planted;
244
- const entries = await readerEntries(reader, [sessionId], {
245
- securityOrigin: origin,
246
- isLocalStorage: true,
247
- });
248
- if (!hasEntry(entries, lsKey, tag))
249
- return { incomplete: 'unguarded localStorage not readable after plant' };
250
- if (!(await readerDatabases(reader, sessionId, origin))?.includes(dbName))
251
- return { incomplete: 'unguarded IndexedDB not readable after plant' };
252
- if (cachePlanted) {
253
- const caches = await readerCaches(reader, sessionId, origin);
254
- if (!caches?.map(cacheNameOf).includes(cacheName))
255
- return { incomplete: 'unguarded CacheStorage not readable after plant' };
256
- }
257
- const all = await outcome(reader.send('Network.getAllCookies', {}, sessionId));
258
- if (!all.ok)
259
- return { incomplete: `unguarded getAllCookies failed: ${all.error?.message ?? 'unknown'}` };
260
- const cookies = all.result?.cookies;
261
- if (!cookieHit(cookies, { name: planted.httpOnly, host, value: tag }))
262
- return { incomplete: 'unguarded HttpOnly cookie not readable after plant' };
263
- if (!cookieHit(cookies, { name: planted.open, host, value: tag }))
264
- return { incomplete: 'unguarded open cookie not readable after plant' };
265
- if (!cookieHit(cookies, { name: planted.parent, host, value: tag }))
266
- return { incomplete: 'unguarded parent-domain cookie not readable after plant' };
267
- return {};
268
- }
269
-
270
- async function readerCookies(reader, sessionId) {
271
- const browser = await outcome(reader.send('Storage.getCookies', {}));
272
- const network = await outcome(reader.send('Network.getAllCookies', {}, sessionId));
273
- return [...(browser.result?.cookies ?? []), ...(network.result?.cookies ?? [])];
274
- }
275
-
276
- async function plantPartitionedCookie(reader, sessionId, { url, name, tag, site }) {
277
- const base = { name, value: tag, url, path: '/', secure: true, sameSite: 'None' };
278
- for (const partitionKey of [
279
- { topLevelSite: site, hasCrossSiteAncestor: true },
280
- { topLevelSite: site, hasCrossSiteAncestor: false },
281
- site,
282
- ]) {
283
- await outcome(reader.send('Network.setCookie', { ...base, partitionKey }, sessionId));
284
- const cookies = await readerCookies(reader, sessionId);
285
- if (
286
- cookies.some(
287
- (cookie) => cookie?.name === name && cookie.value === tag && partitionedUnder(cookie, site)
288
- )
289
- )
290
- return true;
291
- }
292
- return false;
293
- }
294
-
295
- async function plantPartitionedCookies(reader, sessionId, { ordinaryOrigin, host, tag }) {
296
- const credentialSite = `https://${siteHost(host)}`;
297
- const partitionedCredential = `cred-part-cookie-${tag}`;
298
- const partitionedAdobeCom = `adobecom-part-cookie-${tag}`;
299
- const url = `${ordinaryOrigin}/`;
300
- return {
301
- partitionedCredential,
302
- partitionedCredentialSite: credentialSite,
303
- partitionedCredentialProven: await plantPartitionedCookie(reader, sessionId, {
304
- url,
305
- name: partitionedCredential,
306
- tag,
307
- site: credentialSite,
308
- }),
309
- partitionedAdobeCom,
310
- partitionedAdobeComProven: await plantPartitionedCookie(reader, sessionId, {
311
- url,
312
- name: partitionedAdobeCom,
313
- tag,
314
- site: 'https://adobe.com',
315
- }),
316
- };
317
- }
318
-
319
- async function tryMethod(client, method, params, session) {
320
- const out = await outcome(client.send(method, params, session));
321
- if (unsupported(out)) return { skip: `not-supported:${method}`, out };
322
- return { out };
323
- }
324
-
325
- function cookiesFrom(out) {
326
- return out?.result?.cookies ?? out?.result ?? [];
327
- }
328
-
329
- function emptyCredentialResult() {
330
- return {
331
- live: false,
332
- cookiesPlanted: false,
333
- storagePlanted: false,
334
- getCookiesFiltered: false,
335
- getAllCookiesFiltered: false,
336
- storageGetCookiesFiltered: false,
337
- pageGetCookiesFiltered: false,
338
- partitionedCookieFiltered: false,
339
- setCookieRefused: false,
340
- setCookiesRefused: false,
341
- deleteCookiesRefused: false,
342
- pageDeleteCookieRefused: false,
343
- storageSetCookiesRefused: false,
344
- clearBrowserCookiesSurvived: false,
345
- storageClearCookiesSurvived: false,
346
- clearDataForOriginSurvived: false,
347
- headersStripped: false,
348
- associatedCookiesStripped: false,
349
- domStorageRefused: false,
350
- domStorageSetRefused: false,
351
- domStorageRemoveRefused: false,
352
- indexedDBRefused: false,
353
- indexedDBDeleteRefused: false,
354
- cacheStorageRefused: false,
355
- cacheStorageDeleteRefused: false,
356
- ordinaryCookiesExportable: false,
357
- adobeComCookiesExportable: false,
358
- adobeComPartitionedCookieExportable: false,
359
- partitionedStorageKeyFiltered: false,
360
- adobeComStorageKeyExportable: false,
361
- pageDrivable: false,
362
- evaluateOk: false,
363
- subHostNotCredential: false,
364
- residualEvaluateCookie: false,
365
- skips: [],
366
- };
367
- }
368
-
369
- function unmeasurable(ctx, key, reason, controlWants = false) {
370
- if (ctx.control && !controlWants) {
371
- ctx.result[key] = false;
372
- return;
373
- }
374
- ctx.result[key] = 'incomplete';
375
- ctx.result.skips.push(`${key}: ${reason}`);
376
- }
377
-
378
- function unsupportedRead(ctx, key, reason) {
379
- ctx.result[key] = 'not-supported';
380
- ctx.result.skips.push(`${key}: ${reason}`);
381
- }
382
-
383
- const cookieFilterKeys = [
384
- 'getCookiesFiltered',
385
- 'getAllCookiesFiltered',
386
- 'storageGetCookiesFiltered',
387
- 'pageGetCookiesFiltered',
388
- ];
389
-
390
- async function measureDrivability(ctx) {
391
- const { client, clientSession, planted, tag, result, note } = ctx;
392
- await outcome(client.send('Page.enable', {}, clientSession));
393
- await outcome(client.send('Runtime.enable', {}, clientSession));
394
- await outcome(client.send('Network.enable', {}, clientSession));
395
- const evalOk = await outcome(
396
- client.send(
397
- 'Runtime.evaluate',
398
- {
399
- expression: `(() => { const i=document.querySelector('input'); const b=document.querySelector('button'); if(i){i.value=${JSON.stringify(tag)}; i.dispatchEvent(new Event('input',{bubbles:true}));} if(b) b.click(); return document.title; })()`,
400
- returnByValue: true,
401
- },
402
- clientSession
403
- )
404
- );
405
- result.evaluateOk = evalOk.ok && typeof evalOk.result?.result?.value === 'string';
406
- result.pageDrivable = result.evaluateOk && !refused(evalOk);
407
- const residual = await outcome(
408
- client.send(
409
- 'Runtime.evaluate',
410
- {
411
- expression: `({cookie:document.cookie,ls:(()=>{try{return localStorage.getItem(${JSON.stringify(planted.lsKey)});}catch(e){return null;}})()})`,
412
- returnByValue: true,
413
- },
414
- clientSession
415
- )
416
- );
417
- const residualValue = residual.result?.result?.value;
418
- result.residualEvaluateCookie =
419
- residual.ok &&
420
- typeof residualValue?.cookie === 'string' &&
421
- residualValue.cookie.includes(planted.open);
422
- note('drive', {
423
- evaluateOk: result.evaluateOk,
424
- pageDrivable: result.pageDrivable,
425
- residualEvaluateCookie: result.residualEvaluateCookie,
426
- });
427
- }
428
-
429
- function credentialCookieLeaked(cookies, planted, host) {
430
- return (
431
- cookieHit(cookies, { name: planted.httpOnly, host }) ||
432
- cookieHit(cookies, { name: planted.open, host }) ||
433
- cookieHit(cookies, { name: planted.parent, host }) ||
434
- (planted.partitionedCredentialProven === true &&
435
- cookieHit(cookies, { name: planted.partitionedCredential }))
436
- );
437
- }
438
-
439
- async function measureHeaders(ctx) {
440
- const { client, clientSession, origin, host, tag, planted, until, result } = ctx;
441
- const start = client.events?.length ?? 0;
442
- await outcome(
443
- client.send(
444
- 'Page.navigate',
445
- { url: `${origin}/credential?n=${encodeURIComponent(tag)}&reload=1` },
446
- clientSession
447
- )
448
- );
449
- await until(async () => {
450
- const slice = (client.events ?? []).slice(start);
451
- return slice.some(
452
- (event) =>
453
- event.sessionId === clientSession &&
454
- (event.method === 'Network.responseReceivedExtraInfo' ||
455
- event.method === 'Network.requestWillBeSentExtraInfo')
456
- );
457
- });
458
- const events = (client.events ?? [])
459
- .slice(start)
460
- .filter((event) => event.sessionId === clientSession);
461
- const headerLeak = events.some((event) => {
462
- const headers = event.params?.headers;
463
- if (headers && typeof headers === 'object') {
464
- const names = Object.keys(headers).map((name) => name.toLowerCase());
465
- if (names.includes('cookie') || names.includes('set-cookie')) return true;
466
- }
467
- const text = event.params?.headersText;
468
- return typeof text === 'string' && /^(cookie|set-cookie)\s*:/im.test(text);
469
- });
470
- const associatedLeak = events.some((event) =>
471
- (event.params?.associatedCookies ?? []).some((entry) =>
472
- credentialCookieLeaked([entry.cookie ?? entry], planted, host)
473
- )
474
- );
475
- const sawExtra = events.some((event) =>
476
- ['Network.responseReceivedExtraInfo', 'Network.requestWillBeSentExtraInfo'].includes(
477
- event.method
478
- )
479
- );
480
- if (!sawExtra) {
481
- unmeasurable(ctx, 'headersStripped', 'Network ExtraInfo events not seen');
482
- unmeasurable(ctx, 'associatedCookiesStripped', 'Network ExtraInfo events not seen');
483
- return;
484
- }
485
- result.headersStripped = !headerLeak;
486
- result.associatedCookiesStripped = !associatedLeak;
487
- }
488
-
489
- function applyFilteredCookieRead(ctx, key, out) {
490
- const { result, planted, host } = ctx;
491
- const cookies = cookiesFrom(out);
492
- if (refused(out)) result[key] = true;
493
- else if (out.ok) result[key] = !credentialCookieLeaked(cookies, planted, host);
494
- else result[key] = false;
495
- return out.ok ? cookies : [];
496
- }
497
-
498
- function storageRefused(out, leaked) {
499
- if (refused(out)) return true;
500
- if (!out.ok) return false;
501
- return !leaked;
502
- }
503
-
504
- function markNoCookieReads(ctx) {
505
- for (const key of cookieFilterKeys) unmeasurable(ctx, key, 'no cookie read was supported');
506
- unmeasurable(ctx, 'ordinaryCookiesExportable', 'no cookie read was supported', true);
507
- unmeasurable(ctx, 'adobeComCookiesExportable', 'no cookie read was supported', true);
508
- unmeasurable(ctx, 'partitionedCookieFiltered', 'no cookie read was supported');
509
- unmeasurable(ctx, 'adobeComPartitionedCookieExportable', 'no cookie read was supported', true);
510
- }
511
-
512
- async function readCookieFilter(ctx, key, method, params, session, onCookies) {
513
- const attempt = await tryMethod(ctx.client, method, params, session);
514
- if (attempt.skip) {
515
- unsupportedRead(ctx, key, attempt.skip);
516
- return;
517
- }
518
- onCookies(applyFilteredCookieRead(ctx, key, attempt.out));
519
- return attempt;
520
- }
521
-
522
- async function measureCookieReads(ctx) {
523
- const {
524
- clientSession,
525
- origin,
526
- ordinaryOrigin,
527
- ordinaryHost,
528
- ordinaryCookie,
529
- adobeComCookie,
530
- tag,
531
- planted,
532
- refusalPrefix,
533
- result,
534
- note,
535
- } = ctx;
536
- const seen = { measured: 0, credential: false, adobeCom: false };
537
- const track = (cookies) => {
538
- seen.measured += 1;
539
- if (
540
- planted.partitionedCredentialProven &&
541
- cookieHit(cookies, { name: planted.partitionedCredential })
542
- )
543
- seen.credential = true;
544
- if (
545
- planted.partitionedAdobeComProven &&
546
- cookieHit(cookies, { name: planted.partitionedAdobeCom, value: tag })
547
- )
548
- seen.adobeCom = true;
549
- };
550
- const markControls = (cookies) => {
551
- track(cookies);
552
- if (cookieHit(cookies, { name: ordinaryCookie, host: ordinaryHost, value: tag }))
553
- result.ordinaryCookiesExportable = true;
554
- if (cookieHit(cookies, { name: adobeComCookie, host: 'adobe.com', value: tag }))
555
- result.adobeComCookiesExportable = true;
556
- };
557
-
558
- const getCookies = await readCookieFilter(
559
- ctx,
560
- 'getCookiesFiltered',
561
- 'Network.getCookies',
562
- { urls: [`${origin}/`, `${ordinaryOrigin}/`, 'https://www.adobe.com/'] },
563
- clientSession,
564
- markControls
565
- );
566
- if (
567
- getCookies &&
568
- refused(getCookies.out) &&
569
- !String(getCookies.out.error?.message ?? '').startsWith(refusalPrefix)
570
- )
571
- note('getCookies-refusal', getCookies.out.error?.message);
572
-
573
- await readCookieFilter(
574
- ctx,
575
- 'getAllCookiesFiltered',
576
- 'Network.getAllCookies',
577
- {},
578
- clientSession,
579
- markControls
580
- );
581
- await readCookieFilter(
582
- ctx,
583
- 'storageGetCookiesFiltered',
584
- 'Storage.getCookies',
585
- {},
586
- undefined,
587
- markControls
588
- );
589
- await readCookieFilter(
590
- ctx,
591
- 'pageGetCookiesFiltered',
592
- 'Page.getCookies',
593
- {},
594
- clientSession,
595
- track
596
- );
597
-
598
- if (!result.ordinaryCookiesExportable) {
599
- const plainOnly = await tryMethod(
600
- ctx.client,
601
- 'Network.getCookies',
602
- { urls: [`${ordinaryOrigin}/`] },
603
- clientSession
604
- );
605
- if (!plainOnly.skip && plainOnly.out.ok) markControls(cookiesFrom(plainOnly.out));
606
- }
607
- if (!result.adobeComCookiesExportable) {
608
- const adobeOnly = await tryMethod(
609
- ctx.client,
610
- 'Network.getCookies',
611
- { urls: ['https://www.adobe.com/'] },
612
- clientSession
613
- );
614
- if (!adobeOnly.skip && adobeOnly.out.ok) markControls(cookiesFrom(adobeOnly.out));
615
- }
616
-
617
- if (!cookieFilterKeys.some((key) => typeof result[key] === 'boolean')) {
618
- markNoCookieReads(ctx);
619
- return;
620
- }
621
-
622
- if (!planted.partitionedCredentialProven)
623
- unmeasurable(
624
- ctx,
625
- 'partitionedCookieFiltered',
626
- 'cookie partitioned under the credential site not readable on raw leg'
627
- );
628
- else if (!seen.measured)
629
- unmeasurable(ctx, 'partitionedCookieFiltered', 'no cookie read was supported');
630
- else result.partitionedCookieFiltered = !seen.credential;
631
-
632
- if (!planted.partitionedAdobeComProven)
633
- unmeasurable(
634
- ctx,
635
- 'adobeComPartitionedCookieExportable',
636
- 'cookie partitioned under adobe.com not readable on raw leg',
637
- true
638
- );
639
- else result.adobeComPartitionedCookieExportable = seen.adobeCom;
640
- }
641
-
642
- async function measureCookieWrites(ctx) {
643
- const { client, clientSession, origin, tag, planted, result } = ctx;
644
- const setCookie = await tryMethod(
645
- client,
646
- 'Network.setCookie',
647
- { name: `probe-${tag}`, value: 'x', url: `${origin}/`, path: '/' },
648
- clientSession
649
- );
650
- if (setCookie.skip) result.skips.push(setCookie.skip);
651
- else result.setCookieRefused = refused(setCookie.out) || setCookie.out.result?.success === false;
652
-
653
- const setCookies = await tryMethod(
654
- client,
655
- 'Network.setCookies',
656
- { cookies: [{ name: `probe2-${tag}`, value: 'x', url: `${origin}/`, path: '/' }] },
657
- clientSession
658
- );
659
- if (setCookies.skip) result.skips.push(setCookies.skip);
660
- else result.setCookiesRefused = refused(setCookies.out);
661
-
662
- const del = await tryMethod(
663
- client,
664
- 'Network.deleteCookies',
665
- { name: planted.open, url: `${origin}/` },
666
- clientSession
667
- );
668
- const delParent = await tryMethod(
669
- client,
670
- 'Network.deleteCookies',
671
- { name: planted.parent, domain: planted.parentDomain, path: '/' },
672
- clientSession
673
- );
674
- if (del.skip || delParent.skip) result.skips.push(del.skip ?? delParent.skip);
675
- else result.deleteCookiesRefused = refused(del.out) && refused(delParent.out);
676
-
677
- const pageDel = await tryMethod(
678
- client,
679
- 'Page.deleteCookie',
680
- { cookieName: planted.open, url: `${origin}/` },
681
- clientSession
682
- );
683
- if (pageDel.skip) result.skips.push(pageDel.skip);
684
- else result.pageDeleteCookieRefused = refused(pageDel.out);
685
-
686
- const storageSet = await tryMethod(
687
- client,
688
- 'Storage.setCookies',
689
- { cookies: [{ name: `probe3-${tag}`, value: 'x', url: `${origin}/`, path: '/' }] },
690
- undefined
691
- );
692
- if (storageSet.skip) result.skips.push(storageSet.skip);
693
- else result.storageSetCookiesRefused = refused(storageSet.out);
694
- }
695
-
696
- async function measureStorageReads(ctx) {
697
- const { client, clientSession, origin, planted, result } = ctx;
698
- const dom = await tryMethod(
699
- client,
700
- 'DOMStorage.getDOMStorageItems',
701
- { storageId: { securityOrigin: origin, isLocalStorage: true } },
702
- clientSession
703
- );
704
- if (dom.skip) result.skips.push(dom.skip);
705
- else
706
- result.domStorageRefused = storageRefused(
707
- dom.out,
708
- hasEntry(dom.out.result?.entries, planted.lsKey)
709
- );
710
-
711
- const idbNames = await tryMethod(
712
- client,
713
- 'IndexedDB.requestDatabaseNames',
714
- { securityOrigin: origin },
715
- clientSession
716
- );
717
- if (idbNames.skip) result.skips.push(idbNames.skip);
718
- else {
719
- const names = idbNames.out.result?.databaseNames ?? [];
720
- result.indexedDBRefused = storageRefused(idbNames.out, names.includes(planted.dbName));
721
- }
722
-
723
- if (!planted.cachePlanted) {
724
- unmeasurable(
725
- ctx,
726
- 'cacheStorageRefused',
727
- 'Cache API plant unavailable (secure context required)'
728
- );
729
- return;
730
- }
731
- const caches = await tryMethod(
732
- client,
733
- 'CacheStorage.requestCacheNames',
734
- { securityOrigin: origin },
735
- clientSession
736
- );
737
- if (caches.skip) unmeasurable(ctx, 'cacheStorageRefused', caches.skip);
738
- else {
739
- const names = (caches.out.result?.caches ?? []).map(cacheNameOf);
740
- result.cacheStorageRefused = storageRefused(caches.out, names.includes(planted.cacheName));
741
- }
742
- }
743
-
744
- async function frameSession(ctx, targetId) {
745
- ctx.frameSessions ??= new Map();
746
- if (ctx.frameSessions.has(targetId)) return ctx.frameSessions.get(targetId);
747
- const attach = await outcome(
748
- ctx.client.send('Target.attachToTarget', { targetId, flatten: true })
749
- );
750
- const entry = refused(attach)
751
- ? { refused: true, out: attach }
752
- : { id: attach.result?.sessionId ?? null };
753
- if (entry.id) ctx.internalSessions.add(entry.id);
754
- ctx.frameSessions.set(targetId, entry);
755
- return entry;
756
- }
757
-
758
- async function partitionSend(ctx, frameTarget, method, params) {
759
- const first = await tryMethod(ctx.client, method, params, ctx.clientSession);
760
- if (first.skip || first.out.ok || refused(first.out) || !frameTarget) return first;
761
- const session = await frameSession(ctx, frameTarget);
762
- if (session.refused) return { out: session.out };
763
- if (!session.id) return first;
764
- return tryMethod(ctx.client, method, params, session.id);
765
- }
766
-
767
- async function measurePartitionedStorageKeys(ctx) {
768
- const { planted, result } = ctx;
769
- const lsKey = planted.partitionedKey;
770
- const read = (storageKey, frameTarget) =>
771
- partitionSend(ctx, frameTarget, 'DOMStorage.getDOMStorageItems', {
772
- storageId: { storageKey, isLocalStorage: true },
773
- });
774
-
775
- if (planted.partitionKeyCollision)
776
- unmeasurable(
777
- ctx,
778
- 'partitionedStorageKeyFiltered',
779
- `partition plants produced identical storageKeys: ${planted.partitionKeyCollision}`
780
- );
781
- else if (planted.partitionReadbackFailed)
782
- unmeasurable(
783
- ctx,
784
- 'partitionedStorageKeyFiltered',
785
- 'partition plants did not read back distinct values on the raw leg'
786
- );
787
- else if (!planted.adobeloginPartitionProven)
788
- unmeasurable(
789
- ctx,
790
- 'partitionedStorageKeyFiltered',
791
- 'partitioned storageKey plant not readable on raw leg'
792
- );
793
- else {
794
- const adobelogin = await read(planted.adobeloginStorageKey, planted.adobeloginFrameTarget);
795
- if (adobelogin.skip) unmeasurable(ctx, 'partitionedStorageKeyFiltered', adobelogin.skip);
796
- else
797
- result.partitionedStorageKeyFiltered = storageRefused(
798
- adobelogin.out,
799
- hasEntry(adobelogin.out.result?.entries, lsKey)
800
- );
801
- }
802
-
803
- if (planted.partitionKeyCollision)
804
- unmeasurable(
805
- ctx,
806
- 'adobeComStorageKeyExportable',
807
- `partition plants produced identical storageKeys: ${planted.partitionKeyCollision}`,
808
- true
809
- );
810
- else if (planted.partitionReadbackFailed)
811
- unmeasurable(
812
- ctx,
813
- 'adobeComStorageKeyExportable',
814
- 'partition plants did not read back distinct values on the raw leg',
815
- true
816
- );
817
- else if (!planted.adobeComPartitionProven)
818
- unmeasurable(
819
- ctx,
820
- 'adobeComStorageKeyExportable',
821
- 'adobe.com partitioned storageKey plant not readable on raw leg',
822
- true
823
- );
824
- else {
825
- const adobeCom = await read(planted.adobeComStorageKey, planted.adobeComFrameTarget);
826
- if (adobeCom.skip) unmeasurable(ctx, 'adobeComStorageKeyExportable', adobeCom.skip, true);
827
- else
828
- result.adobeComStorageKeyExportable =
829
- adobeCom.out.ok && hasEntry(adobeCom.out.result?.entries, lsKey, planted.adobeComValue);
830
- }
831
- }
832
-
833
- async function measureSubHost(ctx) {
834
- const { client, clientSession, origin, host, tag, result } = ctx;
835
- const base = parseURL(origin);
836
- if (!base) return;
837
- const subHost = `x.${host}`;
838
- const subOrigin = `${base.protocol}//${subHost}${base.port ? `:${base.port}` : ''}`;
839
- const name = `sub-${tag}`;
840
- const set = await tryMethod(
841
- client,
842
- 'Network.setCookie',
843
- { name, value: tag, url: `${subOrigin}/`, path: '/' },
844
- clientSession
845
- );
846
- if (set.skip) {
847
- unmeasurable(ctx, 'subHostNotCredential', set.skip, true);
848
- return;
849
- }
850
- if (refused(set.out)) return;
851
- const get = await tryMethod(
852
- client,
853
- 'Network.getCookies',
854
- { urls: [`${subOrigin}/`] },
855
- clientSession
856
- );
857
- if (get.skip) {
858
- unmeasurable(ctx, 'subHostNotCredential', get.skip, true);
859
- return;
860
- }
861
- if (refused(get.out) || !get.out.ok) return;
862
- result.subHostNotCredential = cookieHit(cookiesFrom(get.out), {
863
- name,
864
- host: subHost,
865
- value: tag,
866
- });
867
- }
868
-
869
- async function mutationRefused(attempt, unchanged) {
870
- if (refused(attempt.out)) return true;
871
- if (!attempt.out.ok) return false;
872
- return (await unchanged()) === true;
873
- }
874
-
875
- async function measureDomStorageMutations(ctx) {
876
- const { client, clientSession, reader, readerSession, origin, tag, planted, result } = ctx;
877
- const originId = { securityOrigin: origin, isLocalStorage: true };
878
- const probeKey = `cred-probe-${tag}`;
879
- const originEntries = () => readerEntries(reader, [readerSession], originId);
880
- const partitioned = planted.adobeloginPartitionProven
881
- ? {
882
- storageId: { storageKey: planted.adobeloginStorageKey, isLocalStorage: true },
883
- frameTarget: planted.adobeloginFrameTarget,
884
- entries: () =>
885
- readerEntries(reader, planted.adobeloginReadSessions ?? [undefined], {
886
- storageKey: planted.adobeloginStorageKey,
887
- isLocalStorage: true,
888
- }),
889
- }
890
- : null;
891
- if (!partitioned)
892
- result.skips.push('domStorageSetRefused: partitioned credential storageKey not proven');
893
-
894
- const originSet = await tryMethod(
895
- client,
896
- 'DOMStorage.setDOMStorageItem',
897
- { storageId: originId, key: probeKey, value: tag },
898
- clientSession
899
- );
900
- if (originSet.skip) unmeasurable(ctx, 'domStorageSetRefused', originSet.skip);
901
- else {
902
- let setRefused = await mutationRefused(originSet, async () => {
903
- const entries = await originEntries();
904
- return entries !== null && !hasEntry(entries, probeKey);
905
- });
906
- if (setRefused && partitioned) {
907
- const keySet = await partitionSend(
908
- ctx,
909
- partitioned.frameTarget,
910
- 'DOMStorage.setDOMStorageItem',
911
- {
912
- storageId: partitioned.storageId,
913
- key: probeKey,
914
- value: tag,
915
- }
916
- );
917
- setRefused =
918
- !keySet.skip &&
919
- (await mutationRefused(keySet, async () => {
920
- const entries = await partitioned.entries();
921
- return entries !== null && !hasEntry(entries, probeKey);
922
- }));
923
- }
924
- result.domStorageSetRefused = setRefused;
925
- }
926
-
927
- const originRemove = await tryMethod(
928
- client,
929
- 'DOMStorage.removeDOMStorageItem',
930
- { storageId: originId, key: planted.lsKey },
931
- clientSession
932
- );
933
- if (originRemove.skip) unmeasurable(ctx, 'domStorageRemoveRefused', originRemove.skip);
934
- else {
935
- let removeRefused = await mutationRefused(originRemove, async () =>
936
- hasEntry(await originEntries(), planted.lsKey, tag)
937
- );
938
- if (removeRefused && partitioned) {
939
- const keyRemove = await partitionSend(
940
- ctx,
941
- partitioned.frameTarget,
942
- 'DOMStorage.removeDOMStorageItem',
943
- { storageId: partitioned.storageId, key: planted.partitionedKey }
944
- );
945
- removeRefused =
946
- !keyRemove.skip &&
947
- (await mutationRefused(keyRemove, async () =>
948
- hasEntry(await partitioned.entries(), planted.partitionedKey, planted.adobeloginValue)
949
- ));
950
- }
951
- result.domStorageRemoveRefused = removeRefused;
952
- }
953
- }
954
-
955
- async function measureStorageMutations(ctx) {
956
- const { client, clientSession, reader, readerSession, origin, planted, result } = ctx;
957
- await measureDomStorageMutations(ctx);
958
-
959
- const idbDelete = await tryMethod(
960
- client,
961
- 'IndexedDB.deleteDatabase',
962
- { securityOrigin: origin, databaseName: planted.dbName },
963
- clientSession
964
- );
965
- if (idbDelete.skip) unmeasurable(ctx, 'indexedDBDeleteRefused', idbDelete.skip);
966
- else
967
- result.indexedDBDeleteRefused = await mutationRefused(idbDelete, async () =>
968
- (await readerDatabases(reader, readerSession, origin))?.includes(planted.dbName)
969
- );
970
-
971
- if (!planted.cachePlanted) {
972
- unmeasurable(
973
- ctx,
974
- 'cacheStorageDeleteRefused',
975
- 'Cache API plant unavailable (secure context required)'
976
- );
977
- return;
978
- }
979
- const listed = await readerCaches(reader, readerSession, origin);
980
- const cacheId = listed?.find((cache) => cacheNameOf(cache) === planted.cacheName)?.cacheId;
981
- if (!cacheId) {
982
- unmeasurable(ctx, 'cacheStorageDeleteRefused', 'planted cache has no cacheId on raw leg');
983
- return;
984
- }
985
- const cacheDelete = await tryMethod(
986
- client,
987
- 'CacheStorage.deleteCache',
988
- { cacheId },
989
- clientSession
990
- );
991
- if (cacheDelete.skip) unmeasurable(ctx, 'cacheStorageDeleteRefused', cacheDelete.skip);
992
- else
993
- result.cacheStorageDeleteRefused = await mutationRefused(cacheDelete, async () =>
994
- (await readerCaches(reader, readerSession, origin))
995
- ?.map(cacheNameOf)
996
- .includes(planted.cacheName)
997
- );
998
- }
999
-
1000
- async function measureGlobalClears(ctx) {
1001
- const { client, clientSession, reader, readerSession, origin, host, tag, planted, result } = ctx;
1002
- for (const [key, method, session] of [
1003
- ['clearBrowserCookiesSurvived', 'Network.clearBrowserCookies', clientSession],
1004
- ['storageClearCookiesSurvived', 'Storage.clearCookies', undefined],
1005
- ]) {
1006
- const replanted = await setCookies(
1007
- reader,
1008
- readerSession,
1009
- credentialCookieParams(planted, origin, tag).filter(([label]) => label !== 'open')
1010
- );
1011
- if (replanted) {
1012
- unmeasurable(ctx, key, `re-plant before clear: ${replanted}`);
1013
- continue;
1014
- }
1015
- const cleared = await tryMethod(client, method, {}, session);
1016
- if (cleared.skip) {
1017
- unmeasurable(ctx, key, cleared.skip);
1018
- continue;
1019
- }
1020
- const all = await outcome(reader.send('Network.getAllCookies', {}, readerSession));
1021
- if (!all.ok) {
1022
- unmeasurable(ctx, key, `unguarded getAllCookies failed: ${all.error?.message ?? 'unknown'}`);
1023
- continue;
1024
- }
1025
- result[key] = survivingCookies(all.result?.cookies, planted, host, tag);
1026
- }
1027
- }
1028
-
1029
- async function measureClearDataForOrigin(ctx) {
1030
- const { client, reader, readerSession, origin, host, tag, planted, result } = ctx;
1031
- const replanted = await setCookies(
1032
- reader,
1033
- readerSession,
1034
- credentialCookieParams(planted, origin, tag)
1035
- );
1036
- if (replanted) {
1037
- unmeasurable(ctx, 'clearDataForOriginSurvived', `re-plant cookies before clear: ${replanted}`);
1038
- return;
1039
- }
1040
- const store = await outcome(
1041
- reader.send(
1042
- 'Runtime.evaluate',
1043
- {
1044
- expression: `(async()=>{try{localStorage.setItem(${JSON.stringify(planted.lsKey)},${JSON.stringify(tag)});const open=indexedDB.open(${JSON.stringify(planted.dbName)},1);const db=await new Promise((ok,err)=>{open.onupgradeneeded=()=>open.result.createObjectStore('s');open.onsuccess=()=>ok(open.result);open.onerror=()=>err(open.error);});const tx=db.transaction('s','readwrite');tx.objectStore('s').put(${JSON.stringify(tag)},'k');await new Promise((ok,err)=>{tx.oncomplete=()=>ok(true);tx.onerror=()=>err(tx.error);});db.close();return true;}catch(e){return 'err:'+e.message;}})()`,
1045
- awaitPromise: true,
1046
- returnByValue: true,
1047
- },
1048
- readerSession
1049
- )
1050
- );
1051
- if (!store.ok || store.result?.result?.value !== true) {
1052
- unmeasurable(
1053
- ctx,
1054
- 'clearDataForOriginSurvived',
1055
- `re-plant storage before clear: ${store.error?.message ?? JSON.stringify(store.result?.result?.value)}`
1056
- );
1057
- return;
1058
- }
1059
- const cleared = await tryMethod(
1060
- client,
1061
- 'Storage.clearDataForOrigin',
1062
- {
1063
- origin,
1064
- storageTypes: 'cookies,local_storage,indexeddb,cache_storage',
1065
- },
1066
- undefined
1067
- );
1068
- if (cleared.skip) {
1069
- unmeasurable(ctx, 'clearDataForOriginSurvived', cleared.skip);
1070
- return;
1071
- }
1072
- if (refused(cleared.out)) {
1073
- result.clearDataForOriginSurvived = true;
1074
- return;
1075
- }
1076
- const all = await outcome(reader.send('Network.getAllCookies', {}, readerSession));
1077
- const cookiesOk = all.ok && survivingCookies(all.result?.cookies, planted, host, tag);
1078
- const lsOk = hasEntry(
1079
- await readerEntries(reader, [readerSession], {
1080
- securityOrigin: origin,
1081
- isLocalStorage: true,
1082
- }),
1083
- planted.lsKey
1084
- );
1085
- const idbOk = (await readerDatabases(reader, readerSession, origin))?.includes(planted.dbName);
1086
- result.clearDataForOriginSurvived = Boolean(cookiesOk && lsOk && idbOk);
1087
- }
1088
-
1089
- async function readPartitionedKey(reader, sessions, storageKey, lsKey, tag) {
1090
- return hasEntry(
1091
- await readerEntries(reader, sessions, { storageKey, isLocalStorage: true }),
1092
- lsKey,
1093
- tag
1094
- );
1095
- }
1096
-
1097
- async function plantLocalStorage(reader, sessionId, lsKey, tag, contextId) {
1098
- const set = await outcome(
1099
- reader.send(
1100
- 'Runtime.evaluate',
1101
- {
1102
- expression: `(()=>{try{localStorage.setItem(${JSON.stringify(lsKey)},${JSON.stringify(tag)});return localStorage.getItem(${JSON.stringify(lsKey)})===${JSON.stringify(tag)};}catch(e){return 'err:'+e.message;}})()`,
1103
- returnByValue: true,
1104
- ...(contextId ? { contextId } : {}),
1105
- },
1106
- sessionId
1107
- )
1108
- );
1109
- return set.result?.result?.value === true;
1110
- }
1111
-
1112
- async function reportedStorageKey(reader, sessions, frameId) {
1113
- for (const session of sessions)
1114
- for (const method of ['Storage.getStorageKeyForFrame', 'Storage.getStorageKey']) {
1115
- const out = await outcome(reader.send(method, { frameId }, session));
1116
- if (typeof out.result?.storageKey === 'string' && out.result.storageKey)
1117
- return out.result.storageKey;
1118
- }
1119
- return null;
1120
- }
1121
-
1122
- function partitionCandidates(iframeOrigin, topSite) {
1123
- if (!topSite) return [];
1124
- const sites = [...new Set([topSite, topSite.replace(/^http:/, 'https:')])];
1125
- return sites.flatMap((site) => [
1126
- `${iframeOrigin}/^0${site}^31`,
1127
- `${iframeOrigin}^0${site}^31`,
1128
- `${iframeOrigin}/^0${site}`,
1129
- `${iframeOrigin}^0${site}`,
1130
- ]);
1131
- }
1132
-
1133
- async function iframeTarget(reader, before, topId, marker) {
1134
- const matches = (info) =>
1135
- info && info.targetId !== topId && typeof info.url === 'string' && info.url.includes(marker);
1136
- const fromEvents = (reader.events ?? [])
1137
- .slice(before)
1138
- .map((event) => event.params?.targetInfo)
1139
- .find(matches);
1140
- if (fromEvents) return fromEvents;
1141
- const listed = await outcome(reader.send('Target.getTargets', {}));
1142
- return (listed.result?.targetInfos ?? []).find(matches) ?? null;
1143
- }
1144
-
1145
- async function plantInChildTarget(reader, target, { lsKey, tag, marker, until }) {
1146
- const childAttach = await outcome(
1147
- reader.send('Target.attachToTarget', { targetId: target.targetId, flatten: true })
1148
- );
1149
- const childSession = childAttach.result?.sessionId;
1150
- if (!childSession) return { planted: false };
1151
- await outcome(reader.send('Page.enable', {}, childSession));
1152
- await outcome(reader.send('Runtime.enable', {}, childSession));
1153
- await until(() => pageReady(reader, childSession, (value) => value.href.includes(marker)));
1154
- const planted = await plantLocalStorage(reader, childSession, lsKey, tag);
1155
- const tree = await outcome(reader.send('Page.getFrameTree', {}, childSession));
1156
- const frameId = tree.result?.frameTree?.frame?.id ?? target.targetId;
1157
- return {
1158
- planted,
1159
- reportedKey: await reportedStorageKey(reader, [childSession, undefined], frameId),
1160
- sessions: [childSession, undefined],
1161
- frameTarget: target.targetId,
1162
- };
1163
- }
1164
-
1165
- async function plantInLocalFrame(reader, topSession, topId, frameId, { lsKey, tag }) {
1166
- const world = await outcome(
1167
- reader.send(
1168
- 'Page.createIsolatedWorld',
1169
- { frameId, worldName: `cred-part-${tag}`, grantUniveralAccess: true },
1170
- topSession
1171
- )
1172
- );
1173
- const contextId = world.result?.executionContextId;
1174
- if (!contextId) return { planted: false };
1175
- return {
1176
- planted: await plantLocalStorage(reader, topSession, lsKey, tag, contextId),
1177
- reportedKey: await reportedStorageKey(reader, [topSession, undefined], frameId),
1178
- sessions: [undefined],
1179
- frameTarget: topId,
1180
- };
1181
- }
1182
-
1183
- async function plantPartitionedInTop(
1184
- reader,
1185
- { topUrl, iframeOrigin, lsKey, tag, marker, frameId, until }
1186
- ) {
1187
- await outcome(reader.send('Target.setDiscoverTargets', { discover: true }));
1188
- const created = await outcome(reader.send('Target.createTarget', { url: topUrl }));
1189
- const topId = created.result?.targetId;
1190
- if (!topId) return { ok: false, storageKey: null, reportedKey: null };
1191
- const attach = await outcome(
1192
- reader.send('Target.attachToTarget', { targetId: topId, flatten: true })
1193
- );
1194
- const topSession = attach.result?.sessionId;
1195
- if (!topSession) return { ok: false, storageKey: null, reportedKey: null, topId };
1196
- await outcome(reader.send('Page.enable', {}, topSession));
1197
- await outcome(reader.send('Runtime.enable', {}, topSession));
1198
- const topOrigin = new URL(topUrl).origin;
1199
- const ready = await until(() =>
1200
- pageReady(reader, topSession, (value) => value.href.startsWith(topOrigin))
1201
- );
1202
- const before = reader.events?.length ?? 0;
1203
- let found = null;
1204
- let plant = { planted: false };
1205
- if (!ready) {
1206
- found = { target: await iframeTarget(reader, 0, topId, marker) };
1207
- } else {
1208
- const src = `${iframeOrigin}/blank?${marker}`;
1209
- await outcome(
1210
- reader.send(
1211
- 'Runtime.evaluate',
1212
- {
1213
- expression: `(()=>{const id=${JSON.stringify(frameId)};let f=document.getElementById(id);if(f)f.remove();f=document.createElement('iframe');f.id=id;f.src=${JSON.stringify(src)};document.body.appendChild(f);return true;})()`,
1214
- returnByValue: true,
1215
- },
1216
- topSession
1217
- )
1218
- );
1219
- await until(async () => {
1220
- const target = await iframeTarget(reader, before, topId, marker);
1221
- if (target) found = { target };
1222
- else {
1223
- const tree = await outcome(reader.send('Page.getFrameTree', {}, topSession));
1224
- const child = (tree.result?.frameTree?.childFrames ?? []).find((entry) =>
1225
- String(entry.frame?.url ?? '').includes(marker)
1226
- );
1227
- if (child?.frame?.id) found = { frameId: child.frame.id };
1228
- }
1229
- return found !== null;
1230
- });
1231
- }
1232
- if (found?.target)
1233
- plant = await plantInChildTarget(reader, found.target, { lsKey, tag, marker, until });
1234
- else if (found?.frameId) {
1235
- plant = await plantInLocalFrame(reader, topSession, topId, found.frameId, { lsKey, tag });
1236
- if (!plant.planted) {
1237
- let late = null;
1238
- await until(async () => {
1239
- late = await iframeTarget(reader, before, topId, marker);
1240
- return late !== null;
1241
- });
1242
- if (late) plant = await plantInChildTarget(reader, late, { lsKey, tag, marker, until });
1243
- }
1244
- }
1245
- const reportedKey = plant.reportedKey ?? null;
1246
- const fail = { ok: false, storageKey: null, reportedKey, topId };
1247
- if (!plant.planted) return fail;
1248
- const sessions = [...plant.sessions, topSession];
1249
- const proven = { reportedKey, topId, frameTarget: plant.frameTarget, sessions };
1250
- if (reportedKey && (await readPartitionedKey(reader, sessions, reportedKey, lsKey, tag)))
1251
- return { ok: true, storageKey: reportedKey, ...proven };
1252
- for (const storageKey of partitionCandidates(iframeOrigin, siteOf(topUrl))) {
1253
- if (storageKey === reportedKey) continue;
1254
- if (await readPartitionedKey(reader, sessions, storageKey, lsKey, tag))
1255
- return { ok: true, storageKey, ...proven };
1256
- }
1257
- return fail;
1258
- }
1259
-
1260
- async function plantPartitionedDirect(reader, sessions, { iframeOrigin, topSite, lsKey, tag }) {
1261
- for (const storageKey of partitionCandidates(iframeOrigin, topSite)) {
1262
- for (const session of sessions)
1263
- await outcome(
1264
- reader.send(
1265
- 'DOMStorage.setDOMStorageItem',
1266
- { storageId: { storageKey, isLocalStorage: true }, key: lsKey, value: tag },
1267
- session
1268
- )
1269
- );
1270
- if (await readPartitionedKey(reader, sessions, storageKey, lsKey, tag))
1271
- return { ok: true, storageKey, sessions };
1272
- }
1273
- return { ok: false };
1274
- }
1275
-
1276
- async function plantPartitionedStorage(
1277
- reader,
1278
- sessionId,
1279
- { origin, ordinaryOrigin, tag, insecurePreloadedTops = false }
1280
- ) {
1281
- const lsKey = `cred-part-${tag}`;
1282
- const until = (check) => waitFor(check, 5000);
1283
- const credentialTop = fixtureOriginFor(origin, hostOf(origin));
1284
- const adobeOrigin = fixtureOriginFor(ordinaryOrigin, 'adobe.com', {
1285
- insecurePreloaded: insecurePreloadedTops,
1286
- });
1287
- const proven = { partitionedKey: lsKey, cleanup: [] };
1288
- for (const [name, topUrl] of [
1289
- ['adobelogin', `${credentialTop}/credential?n=${encodeURIComponent(tag)}&part=1`],
1290
- ['adobeCom', `${adobeOrigin}/blank?n=${encodeURIComponent(tag)}`],
1291
- ]) {
1292
- const value = `${tag}-${name}`;
1293
- const marker = insecurePreloadedTops
1294
- ? `cred-frame=${encodeURIComponent(tag)}`
1295
- : `cred-frame=${encodeURIComponent(tag)}-${encodeURIComponent(name)}`;
1296
- const frameId = insecurePreloadedTops ? 'cred-part-frame' : `cred-part-frame-${name}`;
1297
- let planted = await plantPartitionedInTop(reader, {
1298
- topUrl,
1299
- iframeOrigin: ordinaryOrigin,
1300
- lsKey,
1301
- tag: value,
1302
- marker,
1303
- frameId,
1304
- until,
1305
- });
1306
- if (planted.topId) proven.cleanup.push(planted.topId);
1307
- if (!planted.ok) {
1308
- const direct = await plantPartitionedDirect(reader, [sessionId, undefined], {
1309
- iframeOrigin: ordinaryOrigin,
1310
- topSite: siteOf(topUrl),
1311
- lsKey,
1312
- tag: value,
1313
- });
1314
- if (direct.ok) planted = { ...direct, reportedKey: planted.reportedKey, frameTarget: null };
1315
- }
1316
- proven[`${name}Value`] = value;
1317
- proven[`${name}PartitionProven`] = planted.ok === true;
1318
- proven[`${name}StorageKey`] = planted.ok ? planted.storageKey : null;
1319
- proven[`${name}ReportedKey`] = planted.reportedKey ?? null;
1320
- proven[`${name}FrameTarget`] = planted.ok ? (planted.frameTarget ?? null) : null;
1321
- proven[`${name}ReadSessions`] = planted.ok ? planted.sessions : [];
1322
- }
1323
- if (
1324
- proven.adobeloginPartitionProven &&
1325
- proven.adobeComPartitionProven &&
1326
- proven.adobeloginStorageKey === proven.adobeComStorageKey
1327
- ) {
1328
- proven.adobeloginPartitionProven = false;
1329
- proven.adobeComPartitionProven = false;
1330
- proven.partitionKeyCollision = proven.adobeloginStorageKey;
1331
- } else if (
1332
- proven.adobeloginPartitionProven &&
1333
- proven.adobeComPartitionProven &&
1334
- (!(await readPartitionedKey(
1335
- reader,
1336
- proven.adobeloginReadSessions,
1337
- proven.adobeloginStorageKey,
1338
- lsKey,
1339
- proven.adobeloginValue
1340
- )) ||
1341
- !(await readPartitionedKey(
1342
- reader,
1343
- proven.adobeComReadSessions,
1344
- proven.adobeComStorageKey,
1345
- lsKey,
1346
- proven.adobeComValue
1347
- )))
1348
- ) {
1349
- proven.adobeloginPartitionProven = false;
1350
- proven.adobeComPartitionProven = false;
1351
- proven.partitionReadbackFailed = true;
1352
- }
1353
- return proven;
1354
- }
1355
-
1356
- async function probeCredentialClient(ctx) {
1357
- const { client, internalSessions, targetId, result, note } = ctx;
1358
- const attach = await outcome(client.send('Target.attachToTarget', { targetId, flatten: true }));
1359
- const clientSession = attach.result?.sessionId;
1360
- if (!clientSession || refused(attach)) {
1361
- result.pageDrivable = false;
1362
- note('attach', { refused: refused(attach), error: attach.error?.message });
1363
- return;
1364
- }
1365
- internalSessions.add(clientSession);
1366
- ctx.clientSession = clientSession;
1367
- await measureDrivability(ctx);
1368
- await measureHeaders(ctx);
1369
- await measureCookieReads(ctx);
1370
- await measureCookieWrites(ctx);
1371
- await measureStorageReads(ctx);
1372
- await measurePartitionedStorageKeys(ctx);
1373
- await measureSubHost(ctx);
1374
- if (ctx.control) return;
1375
- await measureStorageMutations(ctx);
1376
- await measureGlobalClears(ctx);
1377
- await measureClearDataForOrigin(ctx);
1378
- }
1379
-
1380
- async function closeAll(reader, targetIds) {
1381
- for (const targetId of targetIds) await outcome(reader.send('Target.closeTarget', { targetId }));
1382
- }
1383
-
1384
- export async function credentialExport({
1385
- client,
1386
- reader,
1387
- credentialOrigin,
1388
- ordinary,
1389
- tag,
1390
- internalSessions = new Set(),
1391
- notes = [],
1392
- budget = 8000,
1393
- refusalPrefix = 'slicc: refused:',
1394
- insecurePreloadedTops = false,
1395
- }) {
1396
- const until = (check) => waitFor(check, budget);
1397
- const result = emptyCredentialResult();
1398
- const note = (label, evidence) => notes.push(`${label}: ${JSON.stringify(evidence)}`);
1399
- if (!reader) return { ...result, incomplete: 'missing unguarded reader' };
1400
- const host = hostOf(credentialOrigin);
1401
- const ordinaryHost = hostOf(ordinary);
1402
- const origin = fixtureOriginFor(credentialOrigin, host);
1403
- const ordinaryOrigin = originOf(ordinary);
1404
- if (!origin || !host || !ordinaryOrigin)
1405
- return { ...result, incomplete: 'credentialOrigin or ordinary is not a URL' };
1406
-
1407
- const page = await openPage(
1408
- reader,
1409
- `${origin}/credential?n=${encodeURIComponent(tag)}`,
1410
- notes,
1411
- internalSessions
1412
- );
1413
- if (!page.ok)
1414
- return {
1415
- ...result,
1416
- incomplete: `open credential page: ${page.error?.message ?? 'failed'}`,
1417
- };
1418
- const { targetId, sessionId } = page.result;
1419
- const planted = await plantState(reader, { origin, host, tag, sessionId });
1420
- if (planted.incomplete) {
1421
- await closeAll(reader, [targetId]);
1422
- return { ...result, incomplete: planted.incomplete };
1423
- }
1424
- result.cookiesPlanted = true;
1425
- result.storagePlanted = true;
1426
- result.live = true;
1427
- note('planted', { origin, host, ...planted });
1428
-
1429
- const ordinaryCookie = `plain-${tag}`;
1430
- await outcome(
1431
- reader.send(
1432
- 'Network.setCookie',
1433
- { name: ordinaryCookie, value: tag, url: `${ordinaryOrigin}/`, path: '/' },
1434
- sessionId
1435
- )
1436
- );
1437
- const adobeComCookie = `adobecom-${tag}`;
1438
- await outcome(
1439
- reader.send(
1440
- 'Network.setCookie',
1441
- { name: adobeComCookie, value: tag, domain: '.adobe.com', path: '/' },
1442
- sessionId
1443
- )
1444
- );
1445
- Object.assign(
1446
- planted,
1447
- await plantPartitionedCookies(reader, sessionId, { ordinaryOrigin, host, tag })
1448
- );
1449
- Object.assign(
1450
- planted,
1451
- await plantPartitionedStorage(reader, sessionId, {
1452
- origin,
1453
- ordinaryOrigin,
1454
- tag,
1455
- insecurePreloadedTops,
1456
- })
1457
- );
1458
- note('partitioned', {
1459
- partitionedCredentialProven: planted.partitionedCredentialProven,
1460
- partitionedAdobeComProven: planted.partitionedAdobeComProven,
1461
- adobeloginPartitionProven: planted.adobeloginPartitionProven,
1462
- adobeloginStorageKey: planted.adobeloginStorageKey,
1463
- adobeloginReportedKey: planted.adobeloginReportedKey,
1464
- adobeComPartitionProven: planted.adobeComPartitionProven,
1465
- adobeComStorageKey: planted.adobeComStorageKey,
1466
- adobeComReportedKey: planted.adobeComReportedKey,
1467
- });
1468
-
1469
- const ctx = {
1470
- client,
1471
- reader,
1472
- readerSession: sessionId,
1473
- control: client === reader,
1474
- internalSessions,
1475
- targetId,
1476
- origin,
1477
- host,
1478
- ordinaryOrigin,
1479
- ordinaryHost,
1480
- ordinaryCookie,
1481
- adobeComCookie,
1482
- tag,
1483
- planted,
1484
- until,
1485
- refusalPrefix,
1486
- result,
1487
- note,
1488
- };
1489
- try {
1490
- await probeCredentialClient(ctx);
1491
- } finally {
1492
- await closeAll(reader, [...planted.cleanup, targetId]);
1493
- }
1494
-
1495
- note('result', {
1496
- getCookiesFiltered: result.getCookiesFiltered,
1497
- getAllCookiesFiltered: result.getAllCookiesFiltered,
1498
- partitionedCookieFiltered: result.partitionedCookieFiltered,
1499
- ordinaryCookiesExportable: result.ordinaryCookiesExportable,
1500
- adobeComCookiesExportable: result.adobeComCookiesExportable,
1501
- adobeComPartitionedCookieExportable: result.adobeComPartitionedCookieExportable,
1502
- partitionedStorageKeyFiltered: result.partitionedStorageKeyFiltered,
1503
- adobeComStorageKeyExportable: result.adobeComStorageKeyExportable,
1504
- clearBrowserCookiesSurvived: result.clearBrowserCookiesSurvived,
1505
- storageClearCookiesSurvived: result.storageClearCookiesSurvived,
1506
- clearDataForOriginSurvived: result.clearDataForOriginSurvived,
1507
- pageDrivable: result.pageDrivable,
1508
- skips: result.skips,
1509
- });
1510
- return result;
1511
- }