cfsolve 0.1.5 → 0.1.6
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 +11 -0
- data/UPSTREAM.md +9 -14
- data/lib/cfsolve/profiles/safari-26-ios/answers.json +827 -822
- data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +852 -848
- data/lib/cfsolve/profiles/safari-26-ios.json +10 -0
- data/lib/cfsolve/version.rb +2 -2
- data/vendor/cfsolve/profiles/safari-26-ios/answers.json +827 -822
- data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +852 -848
- data/vendor/cfsolve/profiles/safari-26-ios.json +10 -0
- data/vendor/cfsolve/src/browser.rs +20 -2
- data/vendor/cfsolve/src/capture/profile.rs +40 -17
- data/vendor/cfsolve/src/embedding_page/render_sample.rs +6 -54
- data/vendor/cfsolve/src/session/challenge_page.rs +17 -12
- data/vendor/cfsolve/src/session/initial.rs +13 -2
- data/vendor/cfsolve/src/session/tests/challenge_page.rs +65 -0
- data/vendor/cfsolve/src/session.rs +1 -1
- data/vendor/cfsolve/src/stage2/call_stack.rs +204 -20
- data/vendor/cfsolve/src/stage2/challenge_page.rs +0 -7
- data/vendor/cfsolve/src/stage2/reference.json +1 -1
- data/vendor/cfsolve/src/stage2/reference.rs +70 -70
- metadata +1 -2
- data/vendor/cfsolve/examples/turnstile_smoke.rs +0 -79
|
@@ -197,6 +197,16 @@
|
|
|
197
197
|
"collect_start": 498,
|
|
198
198
|
"sent": 500
|
|
199
199
|
},
|
|
200
|
+
"challenge_page_timeline": {
|
|
201
|
+
"script_fetch": 90.0,
|
|
202
|
+
"implicit_render": 117,
|
|
203
|
+
"render_start": 118,
|
|
204
|
+
"render_end": 124,
|
|
205
|
+
"init_start": 449,
|
|
206
|
+
"params_start": 449,
|
|
207
|
+
"collect_start": 449,
|
|
208
|
+
"sent": 455
|
|
209
|
+
},
|
|
200
210
|
"intervals": {
|
|
201
211
|
"initialise": 7,
|
|
202
212
|
"handoff": 8,
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
//!
|
|
4
4
|
//! Fingerprint files use JSON and ignore unknown keys. The engine, transport, request headers,
|
|
5
5
|
//! page and orchestrator timelines, resource timing, interaction, probe timings, and navigator
|
|
6
|
-
//! are required. Errors identify missing fields. The
|
|
7
|
-
//! defaults when absent, but rejects invalid values,
|
|
6
|
+
//! are required. The challenge-page timeline is optional. Errors identify missing fields. The
|
|
7
|
+
//! `browser` page layout section uses defaults when absent, but rejects invalid values,
|
|
8
|
+
//! including `null`.
|
|
8
9
|
|
|
9
10
|
use std::collections::BTreeMap;
|
|
10
11
|
use std::path::{Path, PathBuf};
|
|
@@ -23,6 +24,7 @@ use crate::error::Error;
|
|
|
23
24
|
use crate::fingerprint::{self, Transport, TransportSection};
|
|
24
25
|
use crate::js::{JsObject, JsValue, Window};
|
|
25
26
|
use crate::resource_timing::Reporting;
|
|
27
|
+
use crate::session::Embedding;
|
|
26
28
|
use crate::stage2::interaction::native::Viewport;
|
|
27
29
|
use crate::stage2::payload::Document;
|
|
28
30
|
use crate::stage2::registry::Facts;
|
|
@@ -39,12 +41,26 @@ pub struct Browser {
|
|
|
39
41
|
pub(crate) struct Page {
|
|
40
42
|
pub layout: Layout,
|
|
41
43
|
pub timeline: Timeline,
|
|
44
|
+
/// Loader timestamps for widgets a challenge page's orchestrator renders, if the fingerprint
|
|
45
|
+
/// has them. The orchestrator renders once its first response arrives, later than sites do.
|
|
46
|
+
pub challenge_page_timeline: Option<Timeline>,
|
|
42
47
|
pub intervals: Intervals,
|
|
43
48
|
pub orchestrator_pacing: OrchestratorPacing,
|
|
44
49
|
/// Resource timing for fetches whose total duration is the only measurement available.
|
|
45
50
|
pub resource_timing: Reporting,
|
|
46
51
|
}
|
|
47
52
|
|
|
53
|
+
impl Page {
|
|
54
|
+
/// The loader timestamps for a widget embedded as `embedding`. Challenge-page widgets use
|
|
55
|
+
/// the challenge-page timeline when the fingerprint has one, else the site timeline.
|
|
56
|
+
pub(crate) fn loader_timeline(&self, embedding: Embedding) -> &Timeline {
|
|
57
|
+
match (embedding, &self.challenge_page_timeline) {
|
|
58
|
+
(Embedding::ChallengePage, Some(timeline)) => timeline,
|
|
59
|
+
_ => &self.timeline,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
48
64
|
/// Timing settings from the fingerprint's `orchestrator` section. Required even for ordinary
|
|
49
65
|
/// pages, since the response determines whether a challenge is needed. Durations must be
|
|
50
66
|
/// nonnegative.
|
|
@@ -108,6 +124,7 @@ struct Fingerprint {
|
|
|
108
124
|
#[serde(default)]
|
|
109
125
|
browser: Layout,
|
|
110
126
|
timeline: Timeline,
|
|
127
|
+
challenge_page_timeline: Option<Timeline>,
|
|
111
128
|
intervals: Intervals,
|
|
112
129
|
orchestrator: OrchestratorPacing,
|
|
113
130
|
resource_timing: Reporting,
|
|
@@ -160,6 +177,7 @@ impl Browser {
|
|
|
160
177
|
let page = Page {
|
|
161
178
|
layout: fingerprint.browser,
|
|
162
179
|
timeline: fingerprint.timeline,
|
|
180
|
+
challenge_page_timeline: fingerprint.challenge_page_timeline,
|
|
163
181
|
intervals: fingerprint.intervals,
|
|
164
182
|
orchestrator_pacing: fingerprint.orchestrator,
|
|
165
183
|
resource_timing: fingerprint.resource_timing,
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
//!
|
|
3
3
|
//! `traffic.json` provides the user agent, client hints, and header order for each request type.
|
|
4
4
|
//! Session payloads provide probe durations, startup and pending times, benchmark speeds, media
|
|
5
|
-
//! observations, first-payload intervals, and loader timestamps
|
|
6
|
-
//!
|
|
7
|
-
//! remain consistent.
|
|
5
|
+
//! observations, first-payload intervals, and loader timestamps, kept apart for sites and
|
|
6
|
+
//! challenge pages. Most values use the median across sessions. Loader timestamps come from a
|
|
7
|
+
//! single session chosen by median send time, so they remain consistent.
|
|
8
8
|
//!
|
|
9
9
|
//! Values that captures cannot provide stay unchanged: engine, TLS and HTTP/2 settings, request
|
|
10
10
|
//! priorities, page layout, interaction, resource timing phases, orchestrator pacing, and navigator
|
|
@@ -131,9 +131,11 @@ struct Reported {
|
|
|
131
131
|
/// The first session's media observations.
|
|
132
132
|
media: Option<Measurement>,
|
|
133
133
|
intervals: Vec<Intervals>,
|
|
134
|
-
/// Loader timestamps from ordinary sites.
|
|
135
|
-
/// uses the timestamps from ordinary sites.
|
|
134
|
+
/// Loader timestamps from ordinary sites.
|
|
136
135
|
timelines: Vec<Timeline>,
|
|
136
|
+
/// Loader timestamps from challenge pages, whose orchestrator renders once its first
|
|
137
|
+
/// response arrives.
|
|
138
|
+
challenge_page_timelines: Vec<Timeline>,
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
impl Reported {
|
|
@@ -191,15 +193,17 @@ impl Reported {
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
// The orchestrator passes its page data only to widgets on challenge pages.
|
|
194
|
-
|
|
195
|
-
return Ok(());
|
|
196
|
-
}
|
|
196
|
+
let challenge_page = message.get("chlPageData").is_some_and(js::truthy);
|
|
197
197
|
let times: ElapsedTimes = js::from_value(JsValue::Object(message))
|
|
198
198
|
.context("the first payload lacks the loader's elapsed times")?;
|
|
199
199
|
let implicit_render =
|
|
200
200
|
implicit_render.context("the first payload lacks the loader's stack sample")?;
|
|
201
201
|
let timeline = Timeline::from_times(×, implicit_render, self.script_fetch);
|
|
202
|
-
|
|
202
|
+
if challenge_page {
|
|
203
|
+
self.challenge_page_timelines.push(timeline);
|
|
204
|
+
} else {
|
|
205
|
+
self.timelines.push(timeline);
|
|
206
|
+
}
|
|
203
207
|
Ok(())
|
|
204
208
|
}
|
|
205
209
|
|
|
@@ -273,7 +277,16 @@ impl Reported {
|
|
|
273
277
|
Ok(())
|
|
274
278
|
}
|
|
275
279
|
|
|
276
|
-
fn fill(
|
|
280
|
+
fn fill(self, profile: &mut Value, notes: &mut Vec<String>) -> Result<()> {
|
|
281
|
+
// The challenge-page timeline is optional, so a profile may not have one to replace.
|
|
282
|
+
if !self.challenge_page_timelines.is_empty() {
|
|
283
|
+
let profile = profile
|
|
284
|
+
.as_object_mut()
|
|
285
|
+
.context("the profile is not an object")?;
|
|
286
|
+
profile
|
|
287
|
+
.entry("challenge_page_timeline")
|
|
288
|
+
.or_insert(Value::Null);
|
|
289
|
+
}
|
|
277
290
|
let mut filled = |pointer: &str, value: Option<Value>, source: &str| -> Result<()> {
|
|
278
291
|
let name = pointer.trim_start_matches('/').replace('/', ".");
|
|
279
292
|
match value {
|
|
@@ -334,13 +347,23 @@ impl Reported {
|
|
|
334
347
|
|
|
335
348
|
// Use one session to keep timestamps consistent. Choose the session with the median loader
|
|
336
349
|
// send time.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
350
|
+
for (pointer, mut timelines, kind) in [
|
|
351
|
+
("/timeline", self.timelines, "site"),
|
|
352
|
+
(
|
|
353
|
+
"/challenge_page_timeline",
|
|
354
|
+
self.challenge_page_timelines,
|
|
355
|
+
"challenge-page",
|
|
356
|
+
),
|
|
357
|
+
] {
|
|
358
|
+
let count = timelines.len();
|
|
359
|
+
timelines.sort_by_key(|timeline| timeline.sent);
|
|
360
|
+
let source = format!(
|
|
361
|
+
"the median of {count} {kind} widget sessions by send time; script_fetch kept, as \
|
|
362
|
+
no payload reports it"
|
|
363
|
+
);
|
|
364
|
+
filled(pointer, json(timelines.get(count / 2))?, &source)?;
|
|
365
|
+
}
|
|
366
|
+
Ok(())
|
|
344
367
|
}
|
|
345
368
|
}
|
|
346
369
|
|
|
@@ -16,14 +16,12 @@ use std::mem;
|
|
|
16
16
|
|
|
17
17
|
use anyhow::{Context, Result};
|
|
18
18
|
use oxc::ast::ast::{
|
|
19
|
-
Argument, BindingPattern, CallExpression,
|
|
20
|
-
|
|
21
|
-
VariableDeclarator,
|
|
19
|
+
Argument, BindingPattern, CallExpression, Expression, Function, MemberExpression,
|
|
20
|
+
ObjectPropertyKind, PropertyKey, ReturnStatement, TryStatement, VariableDeclarator,
|
|
22
21
|
};
|
|
23
22
|
use oxc::ast_visit::{Visit, walk};
|
|
24
23
|
use oxc::semantic::{ScopeFlags, SymbolId};
|
|
25
24
|
use oxc::span::GetSpan;
|
|
26
|
-
use oxc::syntax::operator::{BinaryOperator, UnaryOperator};
|
|
27
25
|
use url::Url;
|
|
28
26
|
|
|
29
27
|
use crate::candidates;
|
|
@@ -71,9 +69,8 @@ impl RenderSample {
|
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
/// Rebuilds the stack for a page script calling `turnstile.render` in the loader fetched
|
|
74
|
-
/// from `url`. `caller` supplies script frames from innermost to outermost,
|
|
75
|
-
///
|
|
76
|
-
/// inside the script; JavaScriptCore also includes the timer.
|
|
72
|
+
/// from `url`. `caller` supplies the script's frames from innermost to outermost, through
|
|
73
|
+
/// its outermost one. V8's ten-frame limit ends the stack inside the script.
|
|
77
74
|
pub(crate) fn explicit<'caller>(
|
|
78
75
|
source: &str,
|
|
79
76
|
url: &Url,
|
|
@@ -84,21 +81,14 @@ impl RenderSample {
|
|
|
84
81
|
let script = parsed.script();
|
|
85
82
|
let loader = Loader::read(script);
|
|
86
83
|
let (method, frames) = loader.sampled(EXPLICIT_RENDER, engine)?;
|
|
84
|
+
// Shorten the caller frames' lifetime to the loader frames'.
|
|
87
85
|
let caller = caller.into_iter().map(|frame| StackFrame { ..frame });
|
|
88
86
|
let frames = placed(script, url, &frames, engine)
|
|
89
87
|
.into_iter()
|
|
90
88
|
.chain(caller);
|
|
91
89
|
let stack = match engine {
|
|
92
90
|
Engine::Chromium => engine.error_stack(frames.take(V8_STACK_LIMIT)),
|
|
93
|
-
Engine::WebKit =>
|
|
94
|
-
let onload = candidates::at_most_one_distinct(
|
|
95
|
-
&loader.onload_calls,
|
|
96
|
-
"onload callback calls",
|
|
97
|
-
)?
|
|
98
|
-
.context("loader never calls an onload callback")?;
|
|
99
|
-
let timer = [(String::new(), onload)];
|
|
100
|
-
engine.error_stack(frames.chain(placed(script, url, &timer, engine)))
|
|
101
|
-
}
|
|
91
|
+
Engine::WebKit => engine.error_stack(frames),
|
|
102
92
|
};
|
|
103
93
|
Ok(Self { method, stack })
|
|
104
94
|
}
|
|
@@ -180,11 +170,6 @@ struct Loader<'a> {
|
|
|
180
170
|
numbers: HashMap<SymbolId, f64>,
|
|
181
171
|
/// The functions handed to `addEventListener("DOMContentLoaded", ...)`.
|
|
182
172
|
ready: Vec<Binding<'a>>,
|
|
183
|
-
/// Delay of the timer whose callback is currently being visited.
|
|
184
|
-
timer_delay: Option<f64>,
|
|
185
|
-
/// Calls to the page's defined `onload` callback from a timer with no delay. Another timer
|
|
186
|
-
/// retries after one second if the callback is not yet defined.
|
|
187
|
-
onload_calls: Vec<Site>,
|
|
188
173
|
}
|
|
189
174
|
|
|
190
175
|
impl<'a> Loader<'a> {
|
|
@@ -200,8 +185,6 @@ impl<'a> Loader<'a> {
|
|
|
200
185
|
properties: HashMap::new(),
|
|
201
186
|
numbers: HashMap::new(),
|
|
202
187
|
ready: Vec::new(),
|
|
203
|
-
timer_delay: None,
|
|
204
|
-
onload_calls: Vec::new(),
|
|
205
188
|
};
|
|
206
189
|
loader.visit_program(script.program);
|
|
207
190
|
loader
|
|
@@ -324,39 +307,9 @@ impl<'a> Visit<'a> for Loader<'a> {
|
|
|
324
307
|
walk::walk_member_expression(self, member);
|
|
325
308
|
}
|
|
326
309
|
|
|
327
|
-
/// `found === void 0 ? report() : found()`: the call of a callback once it is defined.
|
|
328
|
-
fn visit_conditional_expression(&mut self, conditional: &ConditionalExpression<'a>) {
|
|
329
|
-
if self.timer_delay == Some(0.0)
|
|
330
|
-
&& let Expression::BinaryExpression(test) = &conditional.test
|
|
331
|
-
&& test.operator == BinaryOperator::StrictEquality
|
|
332
|
-
&& let Expression::Identifier(tested) = &test.left
|
|
333
|
-
&& matches!(&test.right, Expression::UnaryExpression(unary)
|
|
334
|
-
if unary.operator == UnaryOperator::Void)
|
|
335
|
-
&& let Expression::CallExpression(call) = &conditional.alternate
|
|
336
|
-
&& call.arguments.is_empty()
|
|
337
|
-
&& let Expression::Identifier(callee) = &call.callee
|
|
338
|
-
&& self.script.binding(callee) == self.script.binding(tested)
|
|
339
|
-
{
|
|
340
|
-
let site = self.site(call, callee.span.start, callee.span.end);
|
|
341
|
-
self.onload_calls.push(site);
|
|
342
|
-
}
|
|
343
|
-
walk::walk_conditional_expression(self, conditional);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
310
|
fn visit_call_expression(&mut self, call: &CallExpression<'a>) {
|
|
347
|
-
let outer_delay = self.timer_delay;
|
|
348
311
|
match &call.callee {
|
|
349
312
|
Expression::Identifier(callee) => {
|
|
350
|
-
// `setTimeout(function () { ... }, delay)`: the callback runs from a timer.
|
|
351
|
-
if self.script.is_global(&call.callee, "setTimeout")
|
|
352
|
-
&& let [callback, delay] = &call.arguments[..]
|
|
353
|
-
&& matches!(
|
|
354
|
-
callback.as_expression(),
|
|
355
|
-
Some(Expression::FunctionExpression(_))
|
|
356
|
-
)
|
|
357
|
-
{
|
|
358
|
-
self.timer_delay = delay.as_expression().and_then(ast::number);
|
|
359
|
-
}
|
|
360
313
|
self.calls.push(Call {
|
|
361
314
|
scope: self.scope,
|
|
362
315
|
callee: self.script.binding(callee),
|
|
@@ -388,7 +341,6 @@ impl<'a> Visit<'a> for Loader<'a> {
|
|
|
388
341
|
}
|
|
389
342
|
}
|
|
390
343
|
walk::walk_call_expression(self, call);
|
|
391
|
-
self.timer_delay = outer_delay;
|
|
392
344
|
}
|
|
393
345
|
|
|
394
346
|
/// A directly returned call is in tail position unless an enclosing `try` requires work
|
|
@@ -20,7 +20,7 @@ use crate::challenge::reduced_timing::{Entry, ResourceTiming};
|
|
|
20
20
|
use crate::challenge::source::InitialRequest;
|
|
21
21
|
use crate::challenge::state::{Intervals, ScriptState};
|
|
22
22
|
use crate::embedding_page::challenge_page::WIDGET_HOST;
|
|
23
|
-
use crate::embedding_page::extra_params
|
|
23
|
+
use crate::embedding_page::extra_params;
|
|
24
24
|
use crate::embedding_page::page::{Params, RenderedPage};
|
|
25
25
|
use crate::embedding_page::render_sample::RenderSample;
|
|
26
26
|
use crate::engine::{self, Engine, Lines};
|
|
@@ -90,14 +90,17 @@ pub(crate) fn first_payload(
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/// Rebuilds the stack sampled by the loader during the orchestrator's `turnstile.render` call.
|
|
93
|
-
/// Includes loader frames and session-script frames from the VM call to the
|
|
94
|
-
/// the widget program
|
|
93
|
+
/// Includes loader frames and session-script frames from the VM's method call out to the
|
|
94
|
+
/// orchestrator's response handler, which starts the widget program.
|
|
95
95
|
///
|
|
96
|
-
///
|
|
97
|
-
///
|
|
98
|
-
///
|
|
96
|
+
/// The orchestrator requests the loader before its first POST, so the loader is ready when the
|
|
97
|
+
/// widget program arrives. The program then renders as it starts, under its own exception
|
|
98
|
+
/// handler, as Chrome and iOS Safari captures both show. Chrome's stack ends inside the VM, at
|
|
99
|
+
/// V8's frame limit; Safari's continues through the program's listener and the forwarder the
|
|
100
|
+
/// response handler calls it through.
|
|
99
101
|
pub(super) fn render_sample(
|
|
100
|
-
|
|
102
|
+
loader: &str,
|
|
103
|
+
loader_url: &Url,
|
|
101
104
|
challenge: &ChallengePage,
|
|
102
105
|
javascript: &str,
|
|
103
106
|
cases: &CaseOpcodes,
|
|
@@ -106,8 +109,7 @@ pub(super) fn render_sample(
|
|
|
106
109
|
) -> Result<RenderSample> {
|
|
107
110
|
// The session script puts the page's inline script before the orchestrator.
|
|
108
111
|
let (inline_lines, _) = engine::line_and_column(&challenge.javascript(""), Lines::Script);
|
|
109
|
-
let
|
|
110
|
-
let geometry = call_stack::recover_method_call(javascript, cases, widget.render_call, guarded)?
|
|
112
|
+
let geometry = call_stack::recover_program_call(javascript, cases, widget.render_call)?
|
|
111
113
|
.rebased(inline_lines);
|
|
112
114
|
let origin = ScriptPosition {
|
|
113
115
|
url: challenge.orchestrator.to_string(),
|
|
@@ -115,7 +117,7 @@ pub(super) fn render_sample(
|
|
|
115
117
|
column: 0,
|
|
116
118
|
};
|
|
117
119
|
let frames = geometry.placed(&origin, engine);
|
|
118
|
-
RenderSample::explicit(
|
|
120
|
+
RenderSample::explicit(loader, loader_url, frames, engine)
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
/// Runs the orchestrator through widget creation and reconstructs the page around the widget.
|
|
@@ -202,15 +204,18 @@ pub(crate) async fn begin(
|
|
|
202
204
|
&challenge.url,
|
|
203
205
|
referrer_policy,
|
|
204
206
|
page,
|
|
207
|
+
Embedding::ChallengePage,
|
|
205
208
|
)
|
|
206
209
|
.await?;
|
|
210
|
+
let engine = client.engine();
|
|
207
211
|
match render_sample(
|
|
208
|
-
&api,
|
|
212
|
+
&api.source,
|
|
213
|
+
api.stack_url(engine),
|
|
209
214
|
&challenge,
|
|
210
215
|
&javascript,
|
|
211
216
|
&cases,
|
|
212
217
|
&widget,
|
|
213
|
-
|
|
218
|
+
engine,
|
|
214
219
|
) {
|
|
215
220
|
Ok(sample) => api.render_sample = sample,
|
|
216
221
|
Err(error) => sink.progress(&format!(
|
|
@@ -215,6 +215,7 @@ pub(crate) async fn render_page(
|
|
|
215
215
|
&document.url,
|
|
216
216
|
document.referrer_policy,
|
|
217
217
|
page,
|
|
218
|
+
Embedding::Site,
|
|
218
219
|
)
|
|
219
220
|
.await?;
|
|
220
221
|
Ok(EmbeddingPage::new(
|
|
@@ -237,6 +238,7 @@ pub(crate) async fn fetch_loader(
|
|
|
237
238
|
page: &Url,
|
|
238
239
|
policy: ReferrerPolicy,
|
|
239
240
|
facts: &Page,
|
|
241
|
+
embedding: Embedding,
|
|
240
242
|
) -> Result<(ApiScript, LoadTiming)> {
|
|
241
243
|
let referer = policy.referrer(page, &url);
|
|
242
244
|
let timer = Timer::start();
|
|
@@ -263,7 +265,8 @@ pub(crate) async fn fetch_loader(
|
|
|
263
265
|
sizes_exposed: timing_exposed && facts.resource_timing.sizes_exposed,
|
|
264
266
|
phases: facts.resource_timing.phases,
|
|
265
267
|
};
|
|
266
|
-
let
|
|
268
|
+
let timeline = facts.loader_timeline(embedding);
|
|
269
|
+
let script = ApiScript::from_source(url, &source, response, timeline, client.engine())?;
|
|
267
270
|
Ok((script, timing))
|
|
268
271
|
}
|
|
269
272
|
|
|
@@ -338,10 +341,18 @@ pub(crate) fn merge(
|
|
|
338
341
|
embedding_page.script.build
|
|
339
342
|
));
|
|
340
343
|
}
|
|
344
|
+
if embedding_page.embedding == Embedding::ChallengePage
|
|
345
|
+
&& page.challenge_page_timeline.is_none()
|
|
346
|
+
{
|
|
347
|
+
sink.progress(
|
|
348
|
+
"Warning: the fingerprint has no `challenge_page_timeline`, so this challenge-page \
|
|
349
|
+
widget reports a site's loader timestamps",
|
|
350
|
+
);
|
|
351
|
+
}
|
|
341
352
|
let message = extra_params::collect(
|
|
342
353
|
&embedding_page.page,
|
|
343
354
|
&embedding_page.layout,
|
|
344
|
-
|
|
355
|
+
page.loader_timeline(embedding_page.embedding),
|
|
345
356
|
&embedding_page.script,
|
|
346
357
|
source::mode(&program.request.options),
|
|
347
358
|
);
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
//! Regression tests for a challenge-page session.
|
|
2
2
|
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
use std::{env, fs};
|
|
5
|
+
|
|
6
|
+
use base64::Engine as _;
|
|
7
|
+
use base64::engine::general_purpose::STANDARD;
|
|
8
|
+
use url::Url;
|
|
3
9
|
use wreq::StatusCode;
|
|
4
10
|
|
|
5
11
|
use crate::Error;
|
|
12
|
+
use crate::challenge::codec;
|
|
13
|
+
use crate::challenge::orchestrator::ChallengePage;
|
|
6
14
|
use crate::challenge::reduced_timing::{Measure, ResourceTiming};
|
|
15
|
+
use crate::engine::Engine;
|
|
7
16
|
use crate::js::json;
|
|
8
17
|
use crate::resource_timing::{LoadTiming, Phases};
|
|
18
|
+
use crate::script::Source;
|
|
9
19
|
use crate::session::{Stage, challenge_page};
|
|
20
|
+
use crate::stage2::call_stack;
|
|
21
|
+
use crate::stage2::challenge_page::WidgetProgram;
|
|
10
22
|
|
|
11
23
|
/// A load measured only as a whole.
|
|
12
24
|
fn fetch(url: &str, started_ms: i64, duration_ms: f64) -> LoadTiming {
|
|
@@ -96,3 +108,56 @@ fn the_clearance_form_passes_when_it_sets_the_cookie_whatever_the_pages_status()
|
|
|
96
108
|
assert!(refused(StatusCode::TOO_MANY_REQUESTS, false, None));
|
|
97
109
|
assert!(!refused(StatusCode::OK, false, None));
|
|
98
110
|
}
|
|
111
|
+
|
|
112
|
+
/// Rebuilds the loader's render stack from a challenge-page capture named by
|
|
113
|
+
/// `CFSOLVE_CHALLENGE_CAPTURE` and compares it with the stack the browser reported. The
|
|
114
|
+
/// directory holds `page-url.txt`, `page.html`, `orchestrator.js`, the orchestrator's first
|
|
115
|
+
/// `orchestrator-response.txt`, `loader-url.txt` (the loader URL its stack names), `api.js`,
|
|
116
|
+
/// `engine.txt` (`chromium` or `webkit`), and, optionally, the browser's `render-stack.txt`.
|
|
117
|
+
#[test]
|
|
118
|
+
fn rebuilds_the_render_stack_of_a_capture() {
|
|
119
|
+
let Some(dir) = env::var_os("CFSOLVE_CHALLENGE_CAPTURE") else {
|
|
120
|
+
return;
|
|
121
|
+
};
|
|
122
|
+
let dir = Path::new(&dir);
|
|
123
|
+
let read = |name: &str| {
|
|
124
|
+
fs::read_to_string(dir.join(name)).unwrap_or_else(|error| panic!("{name}: {error}"))
|
|
125
|
+
};
|
|
126
|
+
let page_url = Url::parse(read("page-url.txt").trim()).unwrap();
|
|
127
|
+
let challenge = ChallengePage::parse(&read("page.html"), &page_url)
|
|
128
|
+
.unwrap()
|
|
129
|
+
.expect("the page is a challenge page");
|
|
130
|
+
let ray = challenge
|
|
131
|
+
.orchestrator
|
|
132
|
+
.query_pairs()
|
|
133
|
+
.find(|(key, _)| key == "ray")
|
|
134
|
+
.map(|(_, ray)| ray.into_owned())
|
|
135
|
+
.expect("the orchestrator URL names the ray");
|
|
136
|
+
let javascript = challenge.javascript(&read("orchestrator.js"));
|
|
137
|
+
let (deobfuscated, cases) = call_stack::deobfuscate_with_cases(javascript.clone()).unwrap();
|
|
138
|
+
let source = Source::try_new(&deobfuscated.text).unwrap();
|
|
139
|
+
let text =
|
|
140
|
+
codec::decode_response(read("orchestrator-response.txt").trim().as_bytes(), &ray).unwrap();
|
|
141
|
+
let program = STANDARD.decode(text).unwrap();
|
|
142
|
+
let widget = WidgetProgram::recover(&source.disassemble(&program).unwrap()).unwrap();
|
|
143
|
+
let engine = match read("engine.txt").trim() {
|
|
144
|
+
"chromium" => Engine::Chromium,
|
|
145
|
+
"webkit" => Engine::WebKit,
|
|
146
|
+
other => panic!("unknown engine {other}"),
|
|
147
|
+
};
|
|
148
|
+
let loader_url = Url::parse(read("loader-url.txt").trim()).unwrap();
|
|
149
|
+
let sample = challenge_page::render_sample(
|
|
150
|
+
&read("api.js"),
|
|
151
|
+
&loader_url,
|
|
152
|
+
&challenge,
|
|
153
|
+
&javascript,
|
|
154
|
+
&cases,
|
|
155
|
+
&widget,
|
|
156
|
+
engine,
|
|
157
|
+
)
|
|
158
|
+
.unwrap();
|
|
159
|
+
// Without the browser's stack, check only that recovery succeeds.
|
|
160
|
+
if let Ok(expected) = fs::read_to_string(dir.join("render-stack.txt")) {
|
|
161
|
+
assert_eq!(sample.stack, expected.trim_end_matches('\n'));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -19,7 +19,7 @@ pub use channel::Stage;
|
|
|
19
19
|
pub use sink::Sink;
|
|
20
20
|
pub(crate) use sink::{Discard, SinkFailed};
|
|
21
21
|
pub use widget::{Clearance, Outcome};
|
|
22
|
-
pub(crate) use widget::{Expect, native, navigate, prepare, send_first_payload};
|
|
22
|
+
pub(crate) use widget::{Embedding, Expect, native, navigate, prepare, send_first_payload};
|
|
23
23
|
|
|
24
24
|
#[cfg(test)]
|
|
25
25
|
mod tests {
|