cfsolve 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +26 -6
- data/UPSTREAM.md +23 -8
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +805 -797
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
- data/lib/cfsolve/version.rb +2 -2
- data/lib/cfsolve.rb +22 -11
- data/vendor/cfsolve/README.md +5 -53
- data/vendor/cfsolve/examples/listing_dump.rs +24 -0
- data/vendor/cfsolve/examples/probe_similarity.rs +37 -0
- data/vendor/cfsolve/examples/rebase_reference.rs +96 -0
- data/vendor/cfsolve/examples/reread_capture.rs +31 -0
- data/vendor/cfsolve/examples/turnstile_smoke.rs +24 -3
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +805 -797
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +909 -899
- data/vendor/cfsolve/src/capture/sessions.rs +88 -4
- data/vendor/cfsolve/src/capture.rs +1 -0
- data/vendor/cfsolve/src/deobfuscate/ast.rs +16 -0
- data/vendor/cfsolve/src/deobfuscate/control_flow.rs +1 -1
- data/vendor/cfsolve/src/deobfuscate/dead_branches.rs +33 -0
- data/vendor/cfsolve/src/deobfuscate/merged_functions.rs +24 -4
- data/vendor/cfsolve/src/embedding_page/extra_params.rs +10 -113
- data/vendor/cfsolve/src/embedding_page/page.rs +70 -99
- data/vendor/cfsolve/src/session/initial.rs +6 -7
- data/vendor/cfsolve/src/session/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/analysis/analyze.rs +4 -33
- data/vendor/cfsolve/src/stage2/analysis/discovery.rs +9 -17
- data/vendor/cfsolve/src/stage2/benchmark.rs +42 -62
- data/vendor/cfsolve/src/stage2/call_stack.rs +133 -227
- data/vendor/cfsolve/src/stage2/challenge_page.rs +10 -3
- data/vendor/cfsolve/src/stage2/probes/dates.rs +0 -44
- data/vendor/cfsolve/src/stage2/probes/parent_info.rs +345 -61
- data/vendor/cfsolve/src/stage2/probes/performance.rs +42 -5
- data/vendor/cfsolve/src/stage2/probes/stack.rs +45 -117
- data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +7 -76
- data/vendor/cfsolve/src/stage2/probes.rs +0 -1
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +70 -115
- data/vendor/cfsolve/src/stage2/registry.rs +6 -11
- data/vendor/cfsolve/src/stage2/replay.rs +3 -34
- data/vendor/cfsolve/src/stage2/stylesheets.rs +0 -35
- data/vendor/cfsolve/src/stage2/trace.rs +1 -1
- data/vendor/cfsolve/src/stage2/vocabulary.rs +6 -111
- data/vendor/cfsolve/src/stage2.rs +0 -1
- data/vendor/cfsolve/src/vm/dataflow.rs +15 -6
- data/vendor/cfsolve/src/vm/disassemble.rs +5 -68
- data/vendor/cfsolve/src/vm/encoded_strings.rs +1553 -0
- data/vendor/cfsolve/src/vm/extract.rs +193 -343
- data/vendor/cfsolve/src/vm/interpret/access.rs +2 -10
- data/vendor/cfsolve/src/vm/interpret/builtin.rs +0 -13
- data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +28 -43
- data/vendor/cfsolve/src/vm/interpret/mix32.rs +216 -86
- data/vendor/cfsolve/src/vm/interpret/native_dispatch.rs +42 -21
- data/vendor/cfsolve/src/vm/interpret/pattern.rs +272 -100
- data/vendor/cfsolve/src/vm/interpret/register_helpers.rs +259 -36
- data/vendor/cfsolve/src/vm/interpret/run.rs +0 -4
- data/vendor/cfsolve/src/vm/machine.rs +14 -70
- data/vendor/cfsolve/src/vm/output.rs +3 -5
- data/vendor/cfsolve/src/vm/registers.rs +26 -46
- data/vendor/cfsolve/src/vm/session.rs +11 -9
- data/vendor/cfsolve/src/vm.rs +1 -1
- metadata +6 -12
- data/lib/cfsolve/profiles/chrome-157-macos/answers.json +0 -4777
- data/lib/cfsolve/profiles/chrome-157-macos.json +0 -613
- data/vendor/cfsolve/profiles/chrome-157-macos/answers.json +0 -4777
- data/vendor/cfsolve/profiles/chrome-157-macos.json +0 -613
- data/vendor/cfsolve/src/stage2/fixtures/encoded_benchmark_worker.js +0 -1
- data/vendor/cfsolve/src/stage2/probes/parent_info_array.rs +0 -326
- data/vendor/cfsolve/src/stage2/value_labels.rs +0 -185
- data/vendor/cfsolve/src/vm/encoded_names.rs +0 -635
- data/vendor/cfsolve/src/vm/fixtures/free_functions/README.md +0 -9
- data/vendor/cfsolve/src/vm/fixtures/free_functions/machine.js +0 -7438
- data/vendor/cfsolve/src/vm/fixtures/free_functions/program.base64 +0 -1
|
@@ -8,21 +8,21 @@
|
|
|
8
8
|
//! Each session directory holds the original and rewritten HTML, the full log `session.json`,
|
|
9
9
|
//! and `capture.json`, which `cargo run --example build_profile` turns into `answers.json`.
|
|
10
10
|
|
|
11
|
-
use std::fs;
|
|
12
11
|
use std::path::{Path, PathBuf};
|
|
13
12
|
use std::sync::{Arc, Mutex, MutexGuard};
|
|
13
|
+
use std::{fs, str};
|
|
14
14
|
|
|
15
|
-
use anyhow::{Context, Result};
|
|
15
|
+
use anyhow::{Context, Result, ensure};
|
|
16
16
|
use num_bigint::BigUint;
|
|
17
17
|
use oxc::ast::ast::Program;
|
|
18
18
|
use oxc::ast_visit::Visit;
|
|
19
19
|
use serde::{Serialize, Serializer};
|
|
20
|
-
use serde_json::Value;
|
|
20
|
+
use serde_json::{Value, json};
|
|
21
21
|
use tokio::task::JoinSet;
|
|
22
22
|
use url::Url;
|
|
23
23
|
|
|
24
24
|
use super::rsa::{ProxyKey, Rewrapped};
|
|
25
|
-
use crate::challenge::codec::{Codec, KEY_LENGTH};
|
|
25
|
+
use crate::challenge::codec::{Codec, Envelope, KEY_LENGTH, SEED_LENGTH};
|
|
26
26
|
use crate::challenge::program::{self, PreparedSession};
|
|
27
27
|
use crate::deobfuscate::Encoded;
|
|
28
28
|
use crate::js::ast;
|
|
@@ -355,3 +355,87 @@ pub(super) fn scan_alphabet(program: &Program<'_>, strings: &[Encoded]) -> Resul
|
|
|
355
355
|
candidates.extend(strings.iter().map(|string| string.decoded.clone()));
|
|
356
356
|
program::base64_alphabet(candidates)
|
|
357
357
|
}
|
|
358
|
+
|
|
359
|
+
/// Reads the payloads of a session the proxy logged without them, as when extraction failed
|
|
360
|
+
/// during capture, using each POST's logged seed and the parameters extraction recovers from
|
|
361
|
+
/// `original.html`. Writes the completed session to `out_dir` and returns how many payloads were
|
|
362
|
+
/// read.
|
|
363
|
+
pub fn reread(session_dir: &Path, out_dir: &Path) -> Result<usize> {
|
|
364
|
+
let read = |name: &str| {
|
|
365
|
+
let path = session_dir.join(name);
|
|
366
|
+
fs::read_to_string(&path).with_context(|| format!("reading {}", path.display()))
|
|
367
|
+
};
|
|
368
|
+
let original = read("original.html")?;
|
|
369
|
+
let mut log: Value = serde_json::from_str(&read("session.json")?)?;
|
|
370
|
+
let mut capture: Value = serde_json::from_str(&read("capture.json")?)?;
|
|
371
|
+
let codec = extract_codec(&original)?;
|
|
372
|
+
let logged_modulus = log["realModulus"]
|
|
373
|
+
.as_str()
|
|
374
|
+
.context("the log has no real modulus")?;
|
|
375
|
+
ensure!(
|
|
376
|
+
format!("{:x}", codec.modulus) == logged_modulus,
|
|
377
|
+
"extraction finds another modulus than the one the proxy swapped"
|
|
378
|
+
);
|
|
379
|
+
let engine = challenge::codec::engine(&codec.alphabet_text)?;
|
|
380
|
+
let mut payloads = Vec::new();
|
|
381
|
+
let mut notes = Vec::new();
|
|
382
|
+
for post in log["posts"]
|
|
383
|
+
.as_array_mut()
|
|
384
|
+
.context("the log has no posts")?
|
|
385
|
+
{
|
|
386
|
+
let url = post["url"].as_str().unwrap_or_default().to_owned();
|
|
387
|
+
let read_post = || -> Result<Value> {
|
|
388
|
+
let seed = post["seed"]
|
|
389
|
+
.as_str()
|
|
390
|
+
.context("the POST has no logged seed")?;
|
|
391
|
+
let body = post["encryptedBody"]
|
|
392
|
+
.as_str()
|
|
393
|
+
.context("the POST has no body")?;
|
|
394
|
+
Envelope::decode(body, &engine)?.payload(&seed_bytes(seed)?, &codec.secret)
|
|
395
|
+
};
|
|
396
|
+
match read_post() {
|
|
397
|
+
Ok(payload) => {
|
|
398
|
+
post["payload"] = payload.clone();
|
|
399
|
+
payloads.push(json!({"url": url, "payload": payload}));
|
|
400
|
+
}
|
|
401
|
+
Err(error) => notes.push(format!("POST {url}: {error:#}")),
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
let count = payloads.len();
|
|
405
|
+
log["alphabet"] = Value::from(codec.alphabet_text);
|
|
406
|
+
log["secret"] = Value::from(String::from_iter(codec.secret.map(char::from)));
|
|
407
|
+
log["complete"] = Value::from(notes.is_empty());
|
|
408
|
+
log["notes"] = Value::from(notes);
|
|
409
|
+
capture["payloads"] = Value::from(payloads);
|
|
410
|
+
fs::create_dir_all(out_dir).with_context(|| format!("creating {}", out_dir.display()))?;
|
|
411
|
+
for name in ["original.html", "rewritten.html"] {
|
|
412
|
+
let from = session_dir.join(name);
|
|
413
|
+
if from.exists() {
|
|
414
|
+
fs::copy(&from, out_dir.join(name))
|
|
415
|
+
.with_context(|| format!("copying {}", from.display()))?;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
write_file(
|
|
419
|
+
&out_dir.join("session.json"),
|
|
420
|
+
serde_json::to_string_pretty(&log)?,
|
|
421
|
+
)?;
|
|
422
|
+
write_file(
|
|
423
|
+
&out_dir.join("capture.json"),
|
|
424
|
+
serde_json::to_string_pretty(&capture)?,
|
|
425
|
+
)?;
|
|
426
|
+
Ok(count)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/// Parses a seed the log holds as lowercase hex.
|
|
430
|
+
fn seed_bytes(hex: &str) -> Result<[u8; SEED_LENGTH]> {
|
|
431
|
+
ensure!(
|
|
432
|
+
hex.len() == 2 * SEED_LENGTH,
|
|
433
|
+
"a {SEED_LENGTH}-byte value needs {} hex digits",
|
|
434
|
+
2 * SEED_LENGTH
|
|
435
|
+
);
|
|
436
|
+
let mut seed = [0; SEED_LENGTH];
|
|
437
|
+
for (byte, pair) in seed.iter_mut().zip(hex.as_bytes().chunks(2)) {
|
|
438
|
+
*byte = u8::from_str_radix(str::from_utf8(pair)?, 16)?;
|
|
439
|
+
}
|
|
440
|
+
Ok(seed)
|
|
441
|
+
}
|
|
@@ -19,4 +19,5 @@ pub use ca::CertificateAuthority;
|
|
|
19
19
|
pub use profile::fill as fill_profile;
|
|
20
20
|
pub use proxy::{CA_HOST, CA_PATH, CHALLENGE_HOST, CaptureProxy, Config};
|
|
21
21
|
pub use recorded::{CapturedSession, Recording};
|
|
22
|
+
pub use sessions::reread as reread_session;
|
|
22
23
|
pub use upstream::{Credentials, UpstreamProxy};
|
|
@@ -266,6 +266,22 @@ pub(super) enum LabeledContinue {
|
|
|
266
266
|
Inner,
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
/// Checks whether `statement` always ends with `return` or `throw`, or, with `jumps`, also with
|
|
270
|
+
/// `break` or `continue`. A labeled statement may be the target of its own `break`, so it never
|
|
271
|
+
/// counts.
|
|
272
|
+
pub(super) fn abrupt(statement: &Statement<'_>, jumps: bool) -> bool {
|
|
273
|
+
match statement {
|
|
274
|
+
Statement::ReturnStatement(_) | Statement::ThrowStatement(_) => true,
|
|
275
|
+
Statement::BreakStatement(_) | Statement::ContinueStatement(_) => jumps,
|
|
276
|
+
Statement::BlockStatement(block) => block.body.iter().any(|inner| abrupt(inner, jumps)),
|
|
277
|
+
Statement::IfStatement(branch) => {
|
|
278
|
+
abrupt(&branch.consequent, jumps)
|
|
279
|
+
&& (branch.alternate.as_ref()).is_some_and(|alternate| abrupt(alternate, jumps))
|
|
280
|
+
}
|
|
281
|
+
_ => false,
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
269
285
|
/// Detects jumps whose loop or switch target would be removed when `statements` are copied out
|
|
270
286
|
/// of a case. Labeled breaks keep their explicit target, which still encloses the copy.
|
|
271
287
|
pub(super) fn escapes(statements: &[Statement<'_>], labeled_continue: LabeledContinue) -> bool {
|
|
@@ -136,7 +136,7 @@ fn flatten<'a>(
|
|
|
136
136
|
Some(Statement::ContinueStatement(jump)) if jump.label.is_none() => {
|
|
137
137
|
body.pop();
|
|
138
138
|
}
|
|
139
|
-
Some(
|
|
139
|
+
Some(last) if ast::abrupt(last, false) => {}
|
|
140
140
|
_ => return None,
|
|
141
141
|
}
|
|
142
142
|
if ast::escapes(&body, LabeledContinue::Inner) || cases.insert(label, body).is_some() {
|
|
@@ -58,6 +58,18 @@ impl<'a> VisitMut<'a> for Dead<'_, 'a> {
|
|
|
58
58
|
fn visit_statements(&mut self, statements: &mut Vec<'a, Statement<'a>>) {
|
|
59
59
|
walk_mut::walk_statements(self, statements);
|
|
60
60
|
let before = statements.len();
|
|
61
|
+
// Statements after one that always completes abruptly never run. Declarations stay:
|
|
62
|
+
// `var` and functions hoist, and `let`, `const`, and classes shadow outer bindings.
|
|
63
|
+
if let Some(end) = statements
|
|
64
|
+
.iter()
|
|
65
|
+
.position(|statement| ast::abrupt(statement, true))
|
|
66
|
+
{
|
|
67
|
+
let mut index = 0;
|
|
68
|
+
statements.retain(|statement| {
|
|
69
|
+
index += 1;
|
|
70
|
+
index <= end + 1 || statement.is_declaration() || declares(statement)
|
|
71
|
+
});
|
|
72
|
+
}
|
|
61
73
|
statements.retain(|statement| match statement {
|
|
62
74
|
Statement::EmptyStatement(_) => false,
|
|
63
75
|
Statement::ExpressionStatement(statement) => match &statement.expression {
|
|
@@ -114,4 +126,25 @@ mod tests {
|
|
|
114
126
|
);
|
|
115
127
|
testing::assert_contains(&output, &["var x", "function g"]);
|
|
116
128
|
}
|
|
129
|
+
|
|
130
|
+
#[test]
|
|
131
|
+
fn removes_statements_after_abrupt_completions() {
|
|
132
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
133
|
+
// A split merged function keeps its case's trailing `return;`.
|
|
134
|
+
let output = transform(
|
|
135
|
+
"function f(r, i) { if (r.J[i] === -4) { return r.H[i]; } else { return g(r, i); } return; }",
|
|
136
|
+
);
|
|
137
|
+
testing::assert_contains(&output, &["return r.H[i]", "return g(r, i)"]);
|
|
138
|
+
testing::assert_lacks(&output, &["return;"]);
|
|
139
|
+
let output = transform(
|
|
140
|
+
"function f() { { throw e; } a(); var x = b(); function g() {} let y; return x + y; }",
|
|
141
|
+
);
|
|
142
|
+
testing::assert_lacks(&output, &["a()", "return x"]);
|
|
143
|
+
testing::assert_contains(&output, &["var x = b()", "function g", "let y"]);
|
|
144
|
+
// Code after a one-armed `if` or a labeled block that breaks itself still runs.
|
|
145
|
+
let output = transform("function f() { if (c) return; a(); l: { break l; } b(); }");
|
|
146
|
+
testing::assert_contains(&output, &["a()", "b()"]);
|
|
147
|
+
let output = transform("function f() { while (c) { if (d) break; else continue; a(); } }");
|
|
148
|
+
testing::assert_lacks(&output, &["a()"]);
|
|
149
|
+
}
|
|
117
150
|
}
|
|
@@ -126,10 +126,12 @@ fn selection<'a>(function: &'a Function<'a>, analysis: &Analysis<'a>) -> Option<
|
|
|
126
126
|
.collect::<Option<_>>()?;
|
|
127
127
|
let mut declarations = vec![];
|
|
128
128
|
for case in &switch.cases {
|
|
129
|
-
if
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
// Dead branch removal drops a trailing `return;` after an `if` whose branches return.
|
|
130
|
+
if !case
|
|
131
|
+
.consequent
|
|
132
|
+
.last()
|
|
133
|
+
.is_some_and(|last| ast::abrupt(last, false))
|
|
134
|
+
|| ast::escapes(&case.consequent, LabeledContinue::Any)
|
|
133
135
|
{
|
|
134
136
|
return None;
|
|
135
137
|
}
|
|
@@ -395,4 +397,22 @@ mod tests {
|
|
|
395
397
|
assert!(output.contains("switch"), "{output}");
|
|
396
398
|
}
|
|
397
399
|
}
|
|
400
|
+
|
|
401
|
+
#[test]
|
|
402
|
+
fn splits_cases_ending_in_branches_that_return() {
|
|
403
|
+
// Dead branch removal leaves no `return;` after the `if`.
|
|
404
|
+
let transform = |source: &str| testing::rewrite(source, super::run);
|
|
405
|
+
let output = transform(
|
|
406
|
+
"function m(s, a) { switch (s) { case 1: if (a) { return 1; } else { return 2; } \
|
|
407
|
+
case 2: throw a; } } h(m(1, p), m(2, q));",
|
|
408
|
+
);
|
|
409
|
+
testing::assert_contains(&output, &["function m_0(a) {", "h(m_0(p), m_1(q));"]);
|
|
410
|
+
testing::assert_lacks(&output, &["switch"]);
|
|
411
|
+
// A branch that breaks out of the switch falls out of the case.
|
|
412
|
+
let output = transform(
|
|
413
|
+
"function m(s, a) { switch (s) { case 1: if (a) { return 1; } else { break; } \
|
|
414
|
+
case 2: return; } } h(m(1, p), m(2, q));",
|
|
415
|
+
);
|
|
416
|
+
testing::assert_contains(&output, &["switch"]);
|
|
417
|
+
}
|
|
398
418
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
//! Builds the `extraParams` reply `api.js` sends to the iframe's `requestExtraParams`: widget
|
|
2
2
|
//! configuration, elapsed times, loader resource timing, and the page summary.
|
|
3
3
|
|
|
4
|
-
use anyhow::{Context, Result
|
|
5
|
-
use oxc::ast::AstKind;
|
|
4
|
+
use anyhow::{Context, Result};
|
|
6
5
|
use oxc::ast::ast::{CallExpression, Expression, ObjectPropertyKind};
|
|
7
6
|
use oxc::ast_visit::{Visit, walk};
|
|
8
7
|
use serde::{Deserialize, Serialize};
|
|
9
8
|
use url::Url;
|
|
10
9
|
|
|
11
10
|
use crate::challenge::reduced_timing::{Entry, ResourceTiming};
|
|
12
|
-
use crate::embedding_page::page::{PageSignals, RenderedPage};
|
|
11
|
+
use crate::embedding_page::page::{Layout, PageSignals, RenderedPage};
|
|
13
12
|
use crate::embedding_page::render_sample::RenderSample;
|
|
14
13
|
use crate::engine::Engine;
|
|
15
|
-
use crate::js::ast::{self, ParsedScript
|
|
14
|
+
use crate::js::ast::{self, ParsedScript};
|
|
16
15
|
use crate::js::{JsValue, json};
|
|
17
16
|
use crate::resource_timing::{NEXT_HOP_PROTOCOL, Phases, ResourceMeasurement};
|
|
18
17
|
use crate::{candidates, random_id};
|
|
@@ -56,7 +55,6 @@ pub(crate) struct ApiScript {
|
|
|
56
55
|
pub render_sample: RenderSample,
|
|
57
56
|
/// The loader's source, for [`RenderSample::explicit`] once a render's caller is known.
|
|
58
57
|
pub source: String,
|
|
59
|
-
positional_signals: bool,
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
/// Resource timing information for the loader response.
|
|
@@ -109,7 +107,6 @@ impl ApiScript {
|
|
|
109
107
|
.context("loader script names no challenge-platform route")?;
|
|
110
108
|
let render_sample =
|
|
111
109
|
RenderSample::from_script(script, stack_url(&url, &response, engine), engine)?;
|
|
112
|
-
let positional_signals = positional_signals(script)?;
|
|
113
110
|
Ok(Self {
|
|
114
111
|
url,
|
|
115
112
|
build,
|
|
@@ -118,18 +115,9 @@ impl ApiScript {
|
|
|
118
115
|
response,
|
|
119
116
|
render_sample,
|
|
120
117
|
source: source.to_owned(),
|
|
121
|
-
positional_signals,
|
|
122
118
|
})
|
|
123
119
|
}
|
|
124
120
|
|
|
125
|
-
fn signals(&self, signals: &PageSignals) -> JsValue {
|
|
126
|
-
if self.positional_signals {
|
|
127
|
-
signals.positional()
|
|
128
|
-
} else {
|
|
129
|
-
json!(signals)
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
121
|
/// The loader's URL as `engine` names it in stacks.
|
|
134
122
|
#[must_use]
|
|
135
123
|
pub(crate) fn stack_url(&self, engine: Engine) -> &Url {
|
|
@@ -213,70 +201,6 @@ impl ApiScript {
|
|
|
213
201
|
}
|
|
214
202
|
}
|
|
215
203
|
|
|
216
|
-
/// Identify the value actually sent as `wPr`, following its declaration by semantic binding.
|
|
217
|
-
/// Reject unknown array layouts rather than silently submitting an incorrectly ordered record.
|
|
218
|
-
fn positional_signals(script: Script<'_>) -> Result<bool> {
|
|
219
|
-
for node in script.nodes.iter() {
|
|
220
|
-
let AstKind::ObjectProperty(property) = node.kind() else {
|
|
221
|
-
continue;
|
|
222
|
-
};
|
|
223
|
-
if ast::key_str(&property.key, property.computed) != Some("wPr") {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
let mut value = property.value.without_parentheses();
|
|
227
|
-
if let Expression::Identifier(reference) = value
|
|
228
|
-
&& let Some(symbol) = script.symbol(reference)
|
|
229
|
-
{
|
|
230
|
-
value = script
|
|
231
|
-
.nodes
|
|
232
|
-
.iter()
|
|
233
|
-
.find_map(|node| {
|
|
234
|
-
let AstKind::VariableDeclarator(declaration) = node.kind() else {
|
|
235
|
-
return None;
|
|
236
|
-
};
|
|
237
|
-
let oxc::ast::ast::BindingPattern::BindingIdentifier(identifier) =
|
|
238
|
-
&declaration.id
|
|
239
|
-
else {
|
|
240
|
-
return None;
|
|
241
|
-
};
|
|
242
|
-
(identifier.symbol_id.get() == Some(symbol))
|
|
243
|
-
.then_some(declaration.init.as_ref())
|
|
244
|
-
.flatten()
|
|
245
|
-
})
|
|
246
|
-
.context("the loader's wPr value has no initializer")?
|
|
247
|
-
.without_parentheses();
|
|
248
|
-
}
|
|
249
|
-
if let Expression::ArrayExpression(array) = value {
|
|
250
|
-
let property_at = |index: usize, name: &str| {
|
|
251
|
-
array
|
|
252
|
-
.elements
|
|
253
|
-
.get(index)
|
|
254
|
-
.and_then(|element| element.as_expression())
|
|
255
|
-
.and_then(Expression::as_member_expression)
|
|
256
|
-
.and_then(ast::member_str)
|
|
257
|
-
== Some(name)
|
|
258
|
-
};
|
|
259
|
-
ensure!(
|
|
260
|
-
array.elements.len() == 30
|
|
261
|
-
&& property_at(2, "referrer")
|
|
262
|
-
&& property_at(5, "href")
|
|
263
|
-
&& property_at(23, "unexpectedHidden")
|
|
264
|
-
&& property_at(25, "visibilityState")
|
|
265
|
-
&& property_at(29, "innerWidth"),
|
|
266
|
-
"the loader uses an unsupported positional page-signals layout"
|
|
267
|
-
);
|
|
268
|
-
return Ok(true);
|
|
269
|
-
}
|
|
270
|
-
ensure!(
|
|
271
|
-
matches!(value, Expression::ObjectExpression(_)),
|
|
272
|
-
"the loader's page-signals format is unknown"
|
|
273
|
-
);
|
|
274
|
-
return Ok(false);
|
|
275
|
-
}
|
|
276
|
-
// Older test loaders omit page signals entirely.
|
|
277
|
-
Ok(false)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
204
|
/// V8 names the loader in stacks by the URL requested, JavaScriptCore by the final response URL.
|
|
281
205
|
fn stack_url<'u>(requested: &'u Url, response: &'u LoaderResponse, engine: Engine) -> &'u Url {
|
|
282
206
|
match engine {
|
|
@@ -367,17 +291,17 @@ pub(crate) struct ExtraParams<'page> {
|
|
|
367
291
|
pub retry_interval: i64,
|
|
368
292
|
/// Both sides check this before reading a message.
|
|
369
293
|
pub source: &'static str,
|
|
294
|
+
#[serde(flatten)]
|
|
295
|
+
pub times: ElapsedTimes,
|
|
370
296
|
pub upgrade_attempts: u32,
|
|
371
297
|
pub upgrade_completed_count: u32,
|
|
372
298
|
pub url: &'page str,
|
|
373
299
|
#[serde(rename = "wPr")]
|
|
374
|
-
pub signals:
|
|
300
|
+
pub signals: PageSignals,
|
|
375
301
|
pub widget_id: &'page str,
|
|
376
|
-
#[serde(flatten)]
|
|
377
|
-
pub times: ElapsedTimes,
|
|
378
302
|
}
|
|
379
303
|
|
|
380
|
-
/// Elapsed loader times reported
|
|
304
|
+
/// Elapsed loader times reported in [`ExtraParams`], in milliseconds.
|
|
381
305
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
382
306
|
#[serde(rename_all = "camelCase")]
|
|
383
307
|
pub(crate) struct ElapsedTimes {
|
|
@@ -435,9 +359,10 @@ impl Timeline {
|
|
|
435
359
|
#[must_use]
|
|
436
360
|
pub(crate) fn collect<'page>(
|
|
437
361
|
page: &'page RenderedPage,
|
|
438
|
-
|
|
362
|
+
layout: &Layout,
|
|
439
363
|
timeline: &Timeline,
|
|
440
364
|
script: &'page ApiScript,
|
|
365
|
+
mode: Option<&str>,
|
|
441
366
|
) -> ExtraParams<'page> {
|
|
442
367
|
let params = &page.params;
|
|
443
368
|
ExtraParams {
|
|
@@ -469,7 +394,7 @@ pub(crate) fn collect<'page>(
|
|
|
469
394
|
upgrade_attempts: 0,
|
|
470
395
|
upgrade_completed_count: 0,
|
|
471
396
|
url: page.url.as_str(),
|
|
472
|
-
signals:
|
|
397
|
+
signals: page.signals(layout, mode),
|
|
473
398
|
widget_id: &page.widget_id,
|
|
474
399
|
times: timeline.times(),
|
|
475
400
|
}
|
|
@@ -515,34 +440,6 @@ pub(crate) fn widget_id() -> String {
|
|
|
515
440
|
mod tests {
|
|
516
441
|
use super::*;
|
|
517
442
|
|
|
518
|
-
#[test]
|
|
519
|
-
fn page_signals_follow_the_sent_binding_and_reject_unknown_array_layouts() {
|
|
520
|
-
let source = |fields: &[String]| {
|
|
521
|
-
format!(
|
|
522
|
-
"function collect() {{ let data=[{}]; function unrelated() {{ let data={{}}; }}; send({{wPr:data}}); }}",
|
|
523
|
-
fields.join(",")
|
|
524
|
-
)
|
|
525
|
-
};
|
|
526
|
-
let mut fields = vec!["null".to_owned(); 30];
|
|
527
|
-
for (index, value) in [
|
|
528
|
-
(2, "document.referrer"),
|
|
529
|
-
(5, "window.location.href"),
|
|
530
|
-
(23, "state.unexpectedHidden"),
|
|
531
|
-
(25, "state.viewport.visibilityState"),
|
|
532
|
-
(29, "window.innerWidth"),
|
|
533
|
-
] {
|
|
534
|
-
fields[index] = value.to_owned();
|
|
535
|
-
}
|
|
536
|
-
let parsed = ParsedScript::parse("loader", &source(&fields)).unwrap();
|
|
537
|
-
assert!(positional_signals(parsed.script()).unwrap());
|
|
538
|
-
fields.swap(23, 24);
|
|
539
|
-
let parsed = ParsedScript::parse("loader", &source(&fields)).unwrap();
|
|
540
|
-
assert!(positional_signals(parsed.script()).is_err());
|
|
541
|
-
let parsed =
|
|
542
|
-
ParsedScript::parse("legacy", "let data = {pi:{}}; send({wPr:data});").unwrap();
|
|
543
|
-
assert!(!positional_signals(parsed.script()).unwrap());
|
|
544
|
-
}
|
|
545
|
-
|
|
546
443
|
#[test]
|
|
547
444
|
fn finds_build_hashes_and_routes_only_where_the_loader_keeps_them() {
|
|
548
445
|
let literals = |source: &str| {
|