@ai-ecoverse/slicc-browsers 1.29.1 → 1.30.1
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 +9 -8
- package/guard-driver.mjs +5 -1
- package/guard-runner.mjs +494 -9
- package/guard-vectors.json +704 -3
- package/package.json +3 -3
- package/schema/guard-vectors.schema.json +74 -1
package/guard-runner.mjs
CHANGED
|
@@ -51,6 +51,231 @@ import { canonicalURL, unparseableURLs } from './unparseable-url.mjs';
|
|
|
51
51
|
export { leftoverPersistentWorker, releasePersistentWorkerSessions, workerTypeForKind };
|
|
52
52
|
|
|
53
53
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
54
|
+
const explicitVector = (vector) => (vector.requires ?? []).includes('explicitAttach');
|
|
55
|
+
const discoveryMethods = [
|
|
56
|
+
'Target.targetCreated',
|
|
57
|
+
'Target.targetInfoChanged',
|
|
58
|
+
'Target.attachedToTarget',
|
|
59
|
+
];
|
|
60
|
+
const controlPremises = ['discovered', 'listed', 'attachSession', 'reachable'];
|
|
61
|
+
const exclusive = ['stockSetup', 'syntheticAutoAttach'];
|
|
62
|
+
|
|
63
|
+
const escapes = /(?:%[0-9a-f]{2})+/gi;
|
|
64
|
+
const bytes = (run) =>
|
|
65
|
+
run.replace(/%([0-9a-f]{2})/gi, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16)));
|
|
66
|
+
const decodedRun = (run) => {
|
|
67
|
+
try {
|
|
68
|
+
return decodeURIComponent(run);
|
|
69
|
+
} catch {
|
|
70
|
+
return bytes(run);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const unwrapped = (value) => {
|
|
74
|
+
let text = String(value ?? '').toLowerCase();
|
|
75
|
+
for (let next = text; ; text = next) {
|
|
76
|
+
next = text.replace(escapes, decodedRun).toLowerCase();
|
|
77
|
+
if (next === text) return text;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const wrappers = ['blob:', 'view-source:', 'filesystem:'];
|
|
82
|
+
const payloads = {
|
|
83
|
+
'data:': (rest) => rest.slice(rest.indexOf(',') + 1),
|
|
84
|
+
'javascript:': (rest) => rest,
|
|
85
|
+
};
|
|
86
|
+
const separators = /[\s"'`<>(){},;=\\]+/;
|
|
87
|
+
const mappedIPv4 = /^\[::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})\]$/;
|
|
88
|
+
const hostEnd = /[/?#\\\s]/;
|
|
89
|
+
const leadingHost = (text) => text.split(hostEnd)[0];
|
|
90
|
+
|
|
91
|
+
export function normalizeHost(host) {
|
|
92
|
+
const text = String(host ?? '');
|
|
93
|
+
const bare = text.slice(text.lastIndexOf('@') + 1);
|
|
94
|
+
if (!bare || hostEnd.test(text)) return '';
|
|
95
|
+
const name = (parseURL(`http://${bare}`)?.hostname ?? '').replace(/\.+$/, '');
|
|
96
|
+
const mapped = mappedIPv4.exec(name);
|
|
97
|
+
if (!mapped) return name;
|
|
98
|
+
const [high, low] = mapped.slice(1).map((part) => Number.parseInt(part, 16));
|
|
99
|
+
return [high >> 8, high & 255, low >> 8, low & 255].join('.');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const layers = (text, schemes = wrappers) => {
|
|
103
|
+
const url = parseURL(text);
|
|
104
|
+
if (!url) return [text];
|
|
105
|
+
const rest = url.href.slice(url.protocol.length).replace(escapes, decodedRun).toLowerCase();
|
|
106
|
+
if (schemes.includes(url.protocol)) return [text, ...layers(rest, schemes)];
|
|
107
|
+
const payload = payloads[url.protocol];
|
|
108
|
+
if (payload)
|
|
109
|
+
return [
|
|
110
|
+
text,
|
|
111
|
+
...payload(rest)
|
|
112
|
+
.split(separators)
|
|
113
|
+
.filter(Boolean)
|
|
114
|
+
.flatMap((part) => layers(part, schemes)),
|
|
115
|
+
];
|
|
116
|
+
return [text];
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const leadingMarks = /^[\s\p{Cc}\p{Cf}\p{Mn}\p{Me}]+/u;
|
|
120
|
+
const trimLead = (text) => text.replace(leadingMarks, '');
|
|
121
|
+
const foldNFKC = (text) => text.normalize('NFKC');
|
|
122
|
+
|
|
123
|
+
const embeddedStart = /(?:[a-z][a-z0-9+.-]*:)?\/\//g;
|
|
124
|
+
const embeddedEnd = /[\s"'`<>(){}|^,;&]/;
|
|
125
|
+
const asURL = (text) => parseURL(text.startsWith('//') ? `http:${text}` : text);
|
|
126
|
+
const embeddedURLs = (text, relative = true) =>
|
|
127
|
+
[...text.matchAll(embeddedStart)]
|
|
128
|
+
.filter((match) => relative || match[0] !== '//')
|
|
129
|
+
.map((match) => asURL(text.slice(match.index).split(embeddedEnd)[0]))
|
|
130
|
+
.filter(Boolean);
|
|
131
|
+
const hostOnly = (text) =>
|
|
132
|
+
text
|
|
133
|
+
.replace(/^\/\//, '')
|
|
134
|
+
.replace(/^[^@/?#\s]*@/, '')
|
|
135
|
+
.replace(/\/$/, '');
|
|
136
|
+
const beyondOrigin = (url) => !['', '/'].includes(url.pathname) || Boolean(url.search || url.hash);
|
|
137
|
+
|
|
138
|
+
const nonBlankAbout = (text) => parseURL(text)?.protocol === 'about:' && text !== 'about:blank';
|
|
139
|
+
const aboutParts = /[?#&=]+/;
|
|
140
|
+
const aboutName = /^[^/?#]*/;
|
|
141
|
+
const leadsWith = (text, path) => Boolean(path) && (text === path || text.startsWith(`${path}/`));
|
|
142
|
+
const aboutCarries = (text, check) => {
|
|
143
|
+
const rest = text.slice('about:'.length);
|
|
144
|
+
const [first, ...others] = rest.split(aboutParts);
|
|
145
|
+
const parts = [first, first.replace(aboutName, ''), ...others];
|
|
146
|
+
const bareName = (part) => part.replace(/^\/+/, '');
|
|
147
|
+
return (
|
|
148
|
+
Boolean(check.secret && rest.includes(check.secret)) ||
|
|
149
|
+
parts.some(
|
|
150
|
+
(part) =>
|
|
151
|
+
check.protectedHost(check.hostToken(bareName(part))) ||
|
|
152
|
+
(part.startsWith('/') && leadsWith(bareName(part), check.path))
|
|
153
|
+
)
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const layerRule = (text, check) => {
|
|
158
|
+
if (nonBlankAbout(text) && (!check.aboutContent || aboutCarries(text, check)))
|
|
159
|
+
return 'about: non-bare';
|
|
160
|
+
if (check.relative && text.startsWith('//') && check.protectedHost(asURL(text)?.host))
|
|
161
|
+
return 'scheme-relative url';
|
|
162
|
+
const urlHost = parseURL(text)?.host;
|
|
163
|
+
if (check.protectedHost(urlHost))
|
|
164
|
+
return urlHost === check.exact ? 'protected host' : 'normalised host';
|
|
165
|
+
return check.protectedHost(check.hostToken(text)) ? 'host token' : undefined;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const namingRule = (all, check) => {
|
|
169
|
+
for (const [index, text] of all.entries()) {
|
|
170
|
+
const rule = layerRule(text, check);
|
|
171
|
+
if (rule) return index > 0 ? `${parseURL(all[0])?.protocol} unwrapped` : rule;
|
|
172
|
+
}
|
|
173
|
+
return undefined;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export function redactionLeak(
|
|
177
|
+
info,
|
|
178
|
+
{ targetId, origin, path, tag },
|
|
179
|
+
{
|
|
180
|
+
normalize = normalizeHost,
|
|
181
|
+
hostToken = leadingHost,
|
|
182
|
+
trim = trimLead,
|
|
183
|
+
schemes = wrappers,
|
|
184
|
+
embedded = true,
|
|
185
|
+
relative = true,
|
|
186
|
+
fold = foldNFKC,
|
|
187
|
+
aboutContent = true,
|
|
188
|
+
} = {}
|
|
189
|
+
) {
|
|
190
|
+
const exact = parseURL(origin)?.host;
|
|
191
|
+
const host = normalize(exact ?? '');
|
|
192
|
+
const protectedHost = (candidate) => Boolean(host && candidate) && normalize(candidate) === host;
|
|
193
|
+
const prepared = (value) => fold(unwrapped(fold(String(value ?? ''))));
|
|
194
|
+
const secret = String(tag).toLowerCase();
|
|
195
|
+
const check = {
|
|
196
|
+
exact,
|
|
197
|
+
protectedHost,
|
|
198
|
+
hostToken,
|
|
199
|
+
relative,
|
|
200
|
+
aboutContent,
|
|
201
|
+
secret,
|
|
202
|
+
path: prepared(path).replace(/^\/+/, ''),
|
|
203
|
+
};
|
|
204
|
+
const texts = (value) => layers(prepared(value), schemes).map((text) => trim(fold(text)));
|
|
205
|
+
const embeds = (value) =>
|
|
206
|
+
embedded &&
|
|
207
|
+
texts(value).some((text) =>
|
|
208
|
+
embeddedURLs(text, relative).some((url) => protectedHost(url.host) && beyondOrigin(url))
|
|
209
|
+
);
|
|
210
|
+
const inner = (text) => {
|
|
211
|
+
const scheme = schemes.find((prefix) => text.startsWith(prefix));
|
|
212
|
+
return scheme ? inner(text.slice(scheme.length)) : text;
|
|
213
|
+
};
|
|
214
|
+
const bare = (value) =>
|
|
215
|
+
[undefined, '', 'about:blank', origin].includes(value) ||
|
|
216
|
+
inner(String(value ?? '')) === origin ||
|
|
217
|
+
protectedHost(hostOnly(trim(prepared(value))));
|
|
218
|
+
const fields = { url: info.url, title: info.title };
|
|
219
|
+
const names = Object.keys(fields);
|
|
220
|
+
const naming = names
|
|
221
|
+
.map((field) => [field, namingRule(texts(fields[field]), check)])
|
|
222
|
+
.find(([, rule]) => rule);
|
|
223
|
+
const exposed = names.find((field) => !bare(fields[field]));
|
|
224
|
+
if ((info.targetId === targetId || naming) && exposed) {
|
|
225
|
+
const [field, rule] = naming ?? [exposed, 'raw target id'];
|
|
226
|
+
return { field: exposed, rule, ...(field === exposed ? {} : { via: field }) };
|
|
227
|
+
}
|
|
228
|
+
const embedding = names.find((field) => embeds(fields[field]));
|
|
229
|
+
if (embedding) return { field: embedding, rule: 'embedded url with path' };
|
|
230
|
+
const tagged = names.find((field) => unwrapped(fields[field]).includes(secret));
|
|
231
|
+
return tagged ? { field: tagged, rule: 'tag' } : undefined;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export function redactedInfo(info, scope, options) {
|
|
235
|
+
return !redactionLeak(info, scope, options);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const shownParts = (text, host) => {
|
|
239
|
+
const url = parseURL(text);
|
|
240
|
+
if (url && url.origin !== 'null') {
|
|
241
|
+
const parts = [
|
|
242
|
+
['path', url.pathname === '/' ? '' : url.pathname],
|
|
243
|
+
['query', url.search],
|
|
244
|
+
['fragment', url.hash],
|
|
245
|
+
]
|
|
246
|
+
.filter(([, part]) => part)
|
|
247
|
+
.map(([name, part]) => `${name}(${part.length} chars)`);
|
|
248
|
+
return [url.origin, ...parts].join(' + ');
|
|
249
|
+
}
|
|
250
|
+
const token = leadingHost(trimLead(text));
|
|
251
|
+
if (host && normalizeHost(token) === host)
|
|
252
|
+
return `${token} + ${text.length - token.length} chars`;
|
|
253
|
+
return `${url?.protocol ?? 'text'}(${text.length} chars)`;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export function maskedId(targetId, tag) {
|
|
257
|
+
const text = String(targetId ?? '');
|
|
258
|
+
if (!text) return '(no id)';
|
|
259
|
+
return unwrapped(text).includes(String(tag).toLowerCase()) ? `(${text.length}-char id)` : text;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function maskedValue(value, tag, host) {
|
|
263
|
+
const text = String(value ?? '');
|
|
264
|
+
if (!text) return 'empty';
|
|
265
|
+
const shown = shownParts(text, host);
|
|
266
|
+
return unwrapped(shown).includes(String(tag).toLowerCase()) ? `(${text.length} chars)` : shown;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function pickRawTarget(infos, { type, openerId, urlPrefix, known = new Set() }) {
|
|
270
|
+
return (infos ?? []).find(
|
|
271
|
+
(info) =>
|
|
272
|
+
info.type === type &&
|
|
273
|
+
info.targetId &&
|
|
274
|
+
!known.has(info.targetId) &&
|
|
275
|
+
(openerId === undefined || info.openerId === openerId) &&
|
|
276
|
+
(urlPrefix === undefined || String(info.url ?? '').startsWith(urlPrefix))
|
|
277
|
+
);
|
|
278
|
+
}
|
|
54
279
|
const namedResultMs = 10000;
|
|
55
280
|
const observeMs = 5000;
|
|
56
281
|
const premises = { chainStarted: 'first hop not observed' };
|
|
@@ -242,6 +467,8 @@ class Execution {
|
|
|
242
467
|
this.cdpTrace = [];
|
|
243
468
|
this.cdpSessionTypes = new Map();
|
|
244
469
|
this.cdpTraceInstalled = false;
|
|
470
|
+
this.explicit = explicitVector(vector);
|
|
471
|
+
this.unanswered = new Set();
|
|
245
472
|
}
|
|
246
473
|
|
|
247
474
|
note(message) {
|
|
@@ -702,6 +929,7 @@ class Execution {
|
|
|
702
929
|
);
|
|
703
930
|
}
|
|
704
931
|
if (
|
|
932
|
+
!this.explicit &&
|
|
705
933
|
event.method === 'Target.attachedToTarget' &&
|
|
706
934
|
event.params.targetInfo?.targetId !== this.pageTarget &&
|
|
707
935
|
event.params.targetInfo?.targetId !== this.canaryTarget &&
|
|
@@ -905,7 +1133,7 @@ class Execution {
|
|
|
905
1133
|
});
|
|
906
1134
|
const unanswered =
|
|
907
1135
|
step.refusable &&
|
|
908
|
-
exitsClient(this.vector) &&
|
|
1136
|
+
(exitsClient(this.vector) || this.explicit) &&
|
|
909
1137
|
!out.ok &&
|
|
910
1138
|
!refused &&
|
|
911
1139
|
/timeout|timed out|no answer/i.test(String(out.error?.message ?? out.error));
|
|
@@ -1132,6 +1360,7 @@ class Execution {
|
|
|
1132
1360
|
castControls: (this.clients.castControls ??= {}),
|
|
1133
1361
|
})
|
|
1134
1362
|
);
|
|
1363
|
+
if (step.rawTarget) return outcome(this.rawTarget(step.rawTarget));
|
|
1135
1364
|
if (step.guess) return this.guess(step.guess, session);
|
|
1136
1365
|
if (step.isolatedWorld) return outcome(this.isolatedWorld(step));
|
|
1137
1366
|
if (step.observer) return outcome(this.watchPage(step));
|
|
@@ -1594,6 +1823,15 @@ class Execution {
|
|
|
1594
1823
|
);
|
|
1595
1824
|
}
|
|
1596
1825
|
|
|
1826
|
+
settleMissing(missing) {
|
|
1827
|
+
if (
|
|
1828
|
+
exitsClient(this.vector) ||
|
|
1829
|
+
(this.explicit && (this.unanswered.size || !this.sessions.child))
|
|
1830
|
+
)
|
|
1831
|
+
this.incomplete.push(missing);
|
|
1832
|
+
else this.errors.push(missing);
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1597
1835
|
async settle(settle) {
|
|
1598
1836
|
const refused = () => (settle.dependsOn ?? []).some((name) => this.refused[name]);
|
|
1599
1837
|
const skipped = () => {
|
|
@@ -1633,9 +1871,117 @@ class Execution {
|
|
|
1633
1871
|
if (refused() && !alt) return skipped();
|
|
1634
1872
|
if (settle.required && !met) {
|
|
1635
1873
|
const missing = `settle: no ${settle.beacon ? `beacon from ${settle.beacon}` : settle.served ? `request for ${settle.served}` : settle.title ? `title ${settle.title}` : 'load'} within ${this.bound(settle.ms ?? 1500)}ms`;
|
|
1636
|
-
|
|
1637
|
-
|
|
1874
|
+
this.settleMissing(missing);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
async rawTarget(spec) {
|
|
1879
|
+
const known = new Set([this.pageTarget, this.canaryTarget].filter(Boolean));
|
|
1880
|
+
const want = {
|
|
1881
|
+
type: spec.type,
|
|
1882
|
+
openerId: spec.openerId === 'page' ? this.pageTarget : undefined,
|
|
1883
|
+
urlPrefix: spec.urlPrefix,
|
|
1884
|
+
known,
|
|
1885
|
+
};
|
|
1886
|
+
let found;
|
|
1887
|
+
let listing = [];
|
|
1888
|
+
await this.poll(async () => {
|
|
1889
|
+
const listed = await outcome(this.reader.send('Target.getTargets', { filter: [{}] }));
|
|
1890
|
+
listing = listed.ok ? (listed.result?.targetInfos ?? []) : [];
|
|
1891
|
+
found = pickRawTarget(listing, want);
|
|
1892
|
+
return Boolean(found);
|
|
1893
|
+
}, spec.ms);
|
|
1894
|
+
if (!found) {
|
|
1895
|
+
this.incomplete.push(
|
|
1896
|
+
`rawTarget: the observer found no ${spec.type}${spec.openerId ? ' opened by the page' : ''}${spec.urlPrefix ? ` at ${spec.urlPrefix}` : ''} within ${this.bound(spec.ms)}ms`
|
|
1897
|
+
);
|
|
1898
|
+
return { found: false };
|
|
1899
|
+
}
|
|
1900
|
+
this.vars.rawTarget = found.targetId;
|
|
1901
|
+
this.vars.rawTargetUrl = found.url;
|
|
1902
|
+
this.targets.push(found.targetId);
|
|
1903
|
+
this.classifyFirstListing(listing, found, spec.urlPrefix);
|
|
1904
|
+
return { found: true, targetId: found.targetId, type: found.type };
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
classifyFirstListing(listing, found, urlPrefix) {
|
|
1908
|
+
const own = (info) =>
|
|
1909
|
+
info.targetId === found.targetId ||
|
|
1910
|
+
(urlPrefix !== undefined && String(info.url ?? '').startsWith(urlPrefix));
|
|
1911
|
+
this.ownTargets = new Set(listing.filter(own).map((info) => info.targetId));
|
|
1912
|
+
const foreign = listing.filter((info) => !own(info));
|
|
1913
|
+
this.foreignTargets = new Set(foreign.map((info) => info.targetId));
|
|
1914
|
+
const pages = foreign.filter((info) => info.type === 'page');
|
|
1915
|
+
const shown = pages.map(
|
|
1916
|
+
(info) => `${info.targetId} ${maskedValue(parseURL(info.url)?.origin ?? '', this.vars.tag)}`
|
|
1917
|
+
);
|
|
1918
|
+
this.note(
|
|
1919
|
+
`rawTarget: ${pages.length} foreign page target(s) at the first listing${shown.length ? `: ${shown.join(', ')}` : ''}`
|
|
1920
|
+
);
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
async targetClass(info, scope) {
|
|
1924
|
+
if (info.targetId === scope.targetId) return 'raw target';
|
|
1925
|
+
if (this.ownTargets?.has(info.targetId)) return 'own target';
|
|
1926
|
+
const context = this.vars.context;
|
|
1927
|
+
if (
|
|
1928
|
+
this.foreignTargets?.has(info.targetId) ||
|
|
1929
|
+
(context && info.browserContextId && info.browserContextId !== context)
|
|
1930
|
+
)
|
|
1931
|
+
return 'foreign target';
|
|
1932
|
+
if (!this.observerIds) {
|
|
1933
|
+
const out = await this.answered(this.reader.send('Target.getTargets', { filter: [{}] }));
|
|
1934
|
+
this.observerIds = new Set(
|
|
1935
|
+
(out.ok ? (out.result?.targetInfos ?? []) : []).map((i) => i.targetId)
|
|
1936
|
+
);
|
|
1638
1937
|
}
|
|
1938
|
+
return this.observerIds.has(info.targetId) ? 'foreign target' : 'id unknown to the observer';
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
async answered(pending) {
|
|
1942
|
+
let timer;
|
|
1943
|
+
const out = await Promise.race([
|
|
1944
|
+
outcome(pending),
|
|
1945
|
+
new Promise((resolve) => {
|
|
1946
|
+
timer = setTimeout(
|
|
1947
|
+
() => resolve({ ok: false, error: { message: 'no answer' } }),
|
|
1948
|
+
this.bound(this.options.namedResultMs ?? namedResultMs)
|
|
1949
|
+
);
|
|
1950
|
+
}),
|
|
1951
|
+
]);
|
|
1952
|
+
clearTimeout(timer);
|
|
1953
|
+
return out;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
noAnswer(step, message = 'no answer') {
|
|
1957
|
+
if (step.as) this.unanswered.add(step.as);
|
|
1958
|
+
if (!step.refusable) this.incomplete.push(`${step.as ?? step.cdp}: no answer`);
|
|
1959
|
+
return { ok: false, error: { message } };
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
async explicitCall(step, params, session) {
|
|
1963
|
+
if (q(params).includes('{rawTarget}'))
|
|
1964
|
+
return this.noAnswer(step, 'no answer: the observer found no raw target');
|
|
1965
|
+
if (step.session === 'child' && !this.sessions.child) {
|
|
1966
|
+
if (this.unanswered.has(this.bindName) && step.as) this.unanswered.add(step.as);
|
|
1967
|
+
return { ok: false, error: { message: 'no child session' } };
|
|
1968
|
+
}
|
|
1969
|
+
if (step.cdp === 'Target.setDiscoverTargets' && params.discover) {
|
|
1970
|
+
this.discovering = true;
|
|
1971
|
+
this.discoverName = step.as;
|
|
1972
|
+
}
|
|
1973
|
+
if (params.browserContextId === '{context}') delete params.browserContextId;
|
|
1974
|
+
const client = step.via === 'unguarded' ? this.reader : this.actor();
|
|
1975
|
+
const out = await this.answered(client.send(step.cdp, params, session));
|
|
1976
|
+
if (!out.ok && /timeout|timed out|no answer/i.test(String(out.error?.message ?? out.error)))
|
|
1977
|
+
this.noAnswer(step);
|
|
1978
|
+
if (step.bindSession) {
|
|
1979
|
+
this.bindName = step.as;
|
|
1980
|
+
if (out.ok && out.result?.sessionId) this.sessions.child = out.result.sessionId;
|
|
1981
|
+
}
|
|
1982
|
+
if (step.cdp === 'Target.createTarget' && out.ok && out.result?.targetId)
|
|
1983
|
+
this.targets.push(out.result.targetId);
|
|
1984
|
+
return out;
|
|
1639
1985
|
}
|
|
1640
1986
|
|
|
1641
1987
|
async guess(guess, session) {
|
|
@@ -1674,6 +2020,7 @@ class Execution {
|
|
|
1674
2020
|
} catch (error) {
|
|
1675
2021
|
return { ok: false, error: { message: error.message } };
|
|
1676
2022
|
}
|
|
2023
|
+
if (this.explicit) return this.explicitCall(step, params, sessionId);
|
|
1677
2024
|
const session =
|
|
1678
2025
|
step.session === 'page-or-browser' &&
|
|
1679
2026
|
supported(['browserSession'], this.options.capabilities) &&
|
|
@@ -1864,6 +2211,7 @@ class Execution {
|
|
|
1864
2211
|
}
|
|
1865
2212
|
|
|
1866
2213
|
observeEarly(name, check, want) {
|
|
2214
|
+
if (this.explicit && this.explicitIncomplete(check)) return 'incomplete';
|
|
1867
2215
|
if (name === 'workerReachable' && this.probeStep())
|
|
1868
2216
|
return this.observeProbeReachable(want, check);
|
|
1869
2217
|
if (check?.forwarded) return this.forwardedCheck(name, check, want);
|
|
@@ -2040,6 +2388,8 @@ class Execution {
|
|
|
2040
2388
|
}
|
|
2041
2389
|
|
|
2042
2390
|
async evidence(c) {
|
|
2391
|
+
if (c.redacted) return this.redactedCheck(c.redacted);
|
|
2392
|
+
if (c.detached && this.explicit) return this.explicitDetached();
|
|
2043
2393
|
if (c.filtered) {
|
|
2044
2394
|
const calls =
|
|
2045
2395
|
c.filtered.from === 'all'
|
|
@@ -2099,7 +2449,95 @@ class Execution {
|
|
|
2099
2449
|
);
|
|
2100
2450
|
}
|
|
2101
2451
|
|
|
2452
|
+
explicitDetached() {
|
|
2453
|
+
const session = this.sessions.child;
|
|
2454
|
+
return this.client.events
|
|
2455
|
+
.slice(this.eventStart, this.cleanupEventStart)
|
|
2456
|
+
.some(
|
|
2457
|
+
(event) =>
|
|
2458
|
+
event.method === 'Target.detachedFromTarget' &&
|
|
2459
|
+
((session && event.params?.sessionId === session) ||
|
|
2460
|
+
(this.vars.rawTarget && event.params?.targetId === this.vars.rawTarget))
|
|
2461
|
+
);
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
explicitAttached() {
|
|
2465
|
+
if (this.sessions.child) return true;
|
|
2466
|
+
return this.client.events
|
|
2467
|
+
.slice(this.eventStart, this.cleanupEventStart)
|
|
2468
|
+
.some(
|
|
2469
|
+
(event) =>
|
|
2470
|
+
event.method === 'Target.attachedToTarget' &&
|
|
2471
|
+
Boolean(this.vars.rawTarget) &&
|
|
2472
|
+
event.params?.targetInfo?.targetId === this.vars.rawTarget
|
|
2473
|
+
);
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
async redactedCheck(from) {
|
|
2477
|
+
const origin = parseURL(this.vars.rawTargetUrl)?.origin;
|
|
2478
|
+
if (!this.vars.rawTarget || !origin) return 'incomplete';
|
|
2479
|
+
const unread = from === 'events' ? undefined : from.find((name) => this.unread(name));
|
|
2480
|
+
if (unread) {
|
|
2481
|
+
const reason = `redacted: ${unread} gave no reply to read`;
|
|
2482
|
+
if (!this.incomplete.includes(reason)) this.incomplete.push(reason);
|
|
2483
|
+
return 'incomplete';
|
|
2484
|
+
}
|
|
2485
|
+
const entries =
|
|
2486
|
+
from === 'events'
|
|
2487
|
+
? this.client.events
|
|
2488
|
+
.slice(this.eventStart, this.cleanupEventStart)
|
|
2489
|
+
.filter((event) => discoveryMethods.includes(event.method))
|
|
2490
|
+
.map((event) => ({ info: event.params?.targetInfo, source: event.method }))
|
|
2491
|
+
: from.flatMap((name) => {
|
|
2492
|
+
const out = this.calls[name];
|
|
2493
|
+
return out?.ok
|
|
2494
|
+
? [out.result?.targetInfo, ...(out.result?.targetInfos ?? [])].map((info) => ({
|
|
2495
|
+
info,
|
|
2496
|
+
source: name,
|
|
2497
|
+
}))
|
|
2498
|
+
: [];
|
|
2499
|
+
});
|
|
2500
|
+
const scope = {
|
|
2501
|
+
targetId: this.vars.rawTarget,
|
|
2502
|
+
origin,
|
|
2503
|
+
path: parseURL(this.vars.rawTargetUrl)?.pathname,
|
|
2504
|
+
tag: this.vars.tag,
|
|
2505
|
+
};
|
|
2506
|
+
const leaks = entries
|
|
2507
|
+
.filter(({ info }) => info)
|
|
2508
|
+
.map((entry) => ({ ...entry, leak: redactionLeak(entry.info, scope) }))
|
|
2509
|
+
.filter(({ leak }) => leak);
|
|
2510
|
+
for (const { info, source, leak } of leaks.slice(0, 5)) {
|
|
2511
|
+
const id = maskedId(info.targetId, scope.tag);
|
|
2512
|
+
const value = maskedValue(info[leak.field], scope.tag, normalizeHost(parseURL(origin)?.host));
|
|
2513
|
+
const via = leak.via ? ` via ${leak.via}` : '';
|
|
2514
|
+
const note = `${this.observing ?? 'redacted'}: ${source} entry ${id} (${await this.targetClass(info, scope)}) ${leak.field} ${value} fails redaction: ${leak.rule}${via}`;
|
|
2515
|
+
if (!this.notes.includes(note)) this.note(note);
|
|
2516
|
+
}
|
|
2517
|
+
return leaks.length === 0;
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
unread(name) {
|
|
2521
|
+
const out = this.calls[name];
|
|
2522
|
+
return !out || (!out.ok && this.refused[name] !== true);
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
explicitIncomplete(check) {
|
|
2526
|
+
const names = (c) => [
|
|
2527
|
+
...resultNames(c),
|
|
2528
|
+
...(Array.isArray(c?.refused) ? c.refused : []),
|
|
2529
|
+
...(Array.isArray(c?.redacted) ? c.redacted : []),
|
|
2530
|
+
...(c?.attached !== undefined || c?.detached || c?.session === 'child'
|
|
2531
|
+
? [this.bindName]
|
|
2532
|
+
: []),
|
|
2533
|
+
...(c?.event || c?.redacted === 'events' ? [this.discoverName] : []),
|
|
2534
|
+
...[...(c?.all ?? []), ...(c?.any ?? []), ...(c?.not ? [c.not] : [])].flatMap(names),
|
|
2535
|
+
];
|
|
2536
|
+
return names(check).some((name) => this.unanswered.has(name));
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2102
2539
|
attachedCheck(c) {
|
|
2540
|
+
if (this.explicit) return this.explicitAttached();
|
|
2103
2541
|
const session = this.sessions[c.session ?? 'page'];
|
|
2104
2542
|
const events = this.client.events.slice(this.eventStart, this.cleanupEventStart);
|
|
2105
2543
|
if (
|
|
@@ -2161,12 +2599,16 @@ class Execution {
|
|
|
2161
2599
|
}
|
|
2162
2600
|
|
|
2163
2601
|
async readCheck(c) {
|
|
2164
|
-
const
|
|
2602
|
+
const child = this.explicit ? this.vars.rawTarget : this.targets.at(-1);
|
|
2603
|
+
const targetId = c.session === 'child' ? child : this.pageTarget;
|
|
2165
2604
|
if (!targetId) return false;
|
|
2166
|
-
const
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2605
|
+
const attach = this.reader.send('Target.attachToTarget', { targetId, flatten: true });
|
|
2606
|
+
const attached = this.explicit ? await outcome(attach) : { ok: true, result: await attach };
|
|
2607
|
+
if (!attached.ok) {
|
|
2608
|
+
this.incomplete.push(`read: the observer could not attach to ${targetId}`);
|
|
2609
|
+
return 'incomplete';
|
|
2610
|
+
}
|
|
2611
|
+
const { sessionId } = attached.result;
|
|
2170
2612
|
try {
|
|
2171
2613
|
const out = await this.evaluate(c.expression ?? 'document.title', sessionId, this.reader);
|
|
2172
2614
|
return matches(observedValue(out, 'result.result.value'), c.title ?? c.equals);
|
|
@@ -2178,6 +2620,10 @@ class Execution {
|
|
|
2178
2620
|
async observeAll(unseen) {
|
|
2179
2621
|
const observed = { ...this.refused };
|
|
2180
2622
|
const incomplete = [];
|
|
2623
|
+
if (await this.explicitLost()) {
|
|
2624
|
+
for (const name of Object.keys(this.vector.observe ?? {})) observed[name] = 'incomplete';
|
|
2625
|
+
return { observed, incomplete };
|
|
2626
|
+
}
|
|
2181
2627
|
const capabilities = withCookiePlantCaps(this.options.capabilities, this.calls.probe?.result);
|
|
2182
2628
|
let measured = 0;
|
|
2183
2629
|
let excused = 0;
|
|
@@ -2196,6 +2642,7 @@ class Execution {
|
|
|
2196
2642
|
continue;
|
|
2197
2643
|
}
|
|
2198
2644
|
measured++;
|
|
2645
|
+
this.observing = name;
|
|
2199
2646
|
observed[name] = await this.observe(name, observation.check);
|
|
2200
2647
|
if (observed[name] === 'unwatched') {
|
|
2201
2648
|
observed[name] = 'incomplete';
|
|
@@ -2211,6 +2658,7 @@ class Execution {
|
|
|
2211
2658
|
if (holds === 'incomplete') incomplete.push(name);
|
|
2212
2659
|
}
|
|
2213
2660
|
this.premises(observed);
|
|
2661
|
+
this.explicitPremises(observed);
|
|
2214
2662
|
if (this.side === 'control' && excused && !measured) this.incomplete.push('measured nothing');
|
|
2215
2663
|
return { observed, incomplete };
|
|
2216
2664
|
}
|
|
@@ -2231,6 +2679,37 @@ class Execution {
|
|
|
2231
2679
|
if (want?.[name] === true && observed[name] === false) observed[name] = 'incomplete';
|
|
2232
2680
|
}
|
|
2233
2681
|
|
|
2682
|
+
async explicitLost() {
|
|
2683
|
+
if (!this.explicit || !this.vars.rawTarget) return false;
|
|
2684
|
+
const targetId = this.vars.rawTarget;
|
|
2685
|
+
const read = await outcome(this.reader.send('Target.getTargetInfo', { targetId }));
|
|
2686
|
+
if (read.ok && read.result?.targetInfo) return false;
|
|
2687
|
+
this.incomplete.push(
|
|
2688
|
+
`rawTarget: the observer lost ${targetId} before the guarded probes ended`
|
|
2689
|
+
);
|
|
2690
|
+
this.unrun();
|
|
2691
|
+
return true;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
unrun() {
|
|
2695
|
+
const unrun = this.errors.filter((error) => / failed without a refusal: /.test(error));
|
|
2696
|
+
this.errors = this.errors.filter((error) => !unrun.includes(error));
|
|
2697
|
+
this.incomplete.push(...unrun);
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
explicitPremises(observed) {
|
|
2701
|
+
if (!this.explicit || this.side !== 'control') return;
|
|
2702
|
+
this.unrun();
|
|
2703
|
+
const observe = this.vector.observe ?? {};
|
|
2704
|
+
const missing = controlPremises.filter(
|
|
2705
|
+
(name) => Object.hasOwn(observe, name) && observed[name] !== true
|
|
2706
|
+
);
|
|
2707
|
+
for (const name of missing)
|
|
2708
|
+
if (observed[name] !== 'incomplete')
|
|
2709
|
+
this.incomplete.push(`${name}: the unguarded control did not show it`);
|
|
2710
|
+
if (missing.length) for (const name of Object.keys(observe)) observed[name] = 'incomplete';
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2234
2713
|
async either(check, value, name, unseen) {
|
|
2235
2714
|
const holds = () => this.check(check);
|
|
2236
2715
|
if (await holds()) return true;
|
|
@@ -2308,6 +2787,8 @@ class Execution {
|
|
|
2308
2787
|
}
|
|
2309
2788
|
|
|
2310
2789
|
async cleanupLeg() {
|
|
2790
|
+
if (this.discovering)
|
|
2791
|
+
await this.answered(this.client.send('Target.setDiscoverTargets', { discover: false }));
|
|
2311
2792
|
if (this.watch)
|
|
2312
2793
|
await outcome(
|
|
2313
2794
|
this.reader.send('Target.detachFromTarget', { sessionId: this.watch.sessionId })
|
|
@@ -2393,7 +2874,8 @@ const needsObserver = (vector) =>
|
|
|
2393
2874
|
step.protectedParentIframes ||
|
|
2394
2875
|
step.credentialExport ||
|
|
2395
2876
|
step.signInHold ||
|
|
2396
|
-
step.cookiePlant
|
|
2877
|
+
step.cookiePlant ||
|
|
2878
|
+
step.rawTarget
|
|
2397
2879
|
) ||
|
|
2398
2880
|
vector.control.via === 'unguarded' ||
|
|
2399
2881
|
observerRequired(vector.liveCheck) ||
|
|
@@ -2900,6 +3382,9 @@ function validateScales(opts) {
|
|
|
2900
3382
|
function validate(set, opts) {
|
|
2901
3383
|
if (!opts.fixture?.log) throw new TypeError('fixture.log is required');
|
|
2902
3384
|
validateScales(opts);
|
|
3385
|
+
const both = exclusive.filter((capability) => declared(capability, opts.capabilities));
|
|
3386
|
+
if (declared('explicitAttach', opts.capabilities) && both.length)
|
|
3387
|
+
throw new TypeError(`explicitAttach excludes ${both.join(' and ')} in one run`);
|
|
2903
3388
|
for (const vector of set.vectors)
|
|
2904
3389
|
for (const [name, observation] of Object.entries(vector.observe ?? {}))
|
|
2905
3390
|
if (!observation.check) throw new TypeError(`${vector.id}: ${name} lacks a check`);
|