cfsolve 0.1.0 → 0.1.2

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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +10 -9
  4. data/UPSTREAM.md +6 -6
  5. data/lib/cfsolve/profiles/safari-26-ios/answers.json +2562 -1887
  6. data/lib/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1873 -1198
  7. data/lib/cfsolve/profiles/safari-26-ios.json +0 -8
  8. data/lib/cfsolve/version.rb +2 -2
  9. data/vendor/cfsolve/README.md +0 -35
  10. data/vendor/cfsolve/examples/build_profile.rs +17 -15
  11. data/vendor/cfsolve/examples/capture_session.rs +37 -0
  12. data/vendor/cfsolve/examples/check_answers.rs +66 -0
  13. data/vendor/cfsolve/examples/compare_session.rs +190 -0
  14. data/vendor/cfsolve/examples/stage2_snapshot.rs +4 -1
  15. data/vendor/cfsolve/profiles/safari-26-ios/answers.json +2562 -1887
  16. data/vendor/cfsolve/profiles/safari-26-ios/challenge-page-answers.json +1873 -1198
  17. data/vendor/cfsolve/profiles/safari-26-ios.json +0 -8
  18. data/vendor/cfsolve/scripts/capture_cssom.mjs +42 -0
  19. data/vendor/cfsolve/scripts/serve_cssom.py +111 -0
  20. data/vendor/cfsolve/src/capture/profile.rs +7 -18
  21. data/vendor/cfsolve/src/capture/recorded.rs +42 -7
  22. data/vendor/cfsolve/src/challenge/installed/audit.rs +131 -0
  23. data/vendor/cfsolve/src/challenge/installed.rs +122 -271
  24. data/vendor/cfsolve/src/challenge/merge.rs +30 -85
  25. data/vendor/cfsolve/src/challenge/payload.rs +107 -5
  26. data/vendor/cfsolve/src/challenge/state.rs +98 -16
  27. data/vendor/cfsolve/src/deobfuscate/encoded_strings.rs +3 -2
  28. data/vendor/cfsolve/src/deobfuscate/helper_objects.rs +17 -32
  29. data/vendor/cfsolve/src/deobfuscate/register_arrays.rs +18 -5
  30. data/vendor/cfsolve/src/embedding_page/extra_params.rs +0 -14
  31. data/vendor/cfsolve/src/embedding_page/page.rs +28 -2
  32. data/vendor/cfsolve/src/http/client.rs +11 -0
  33. data/vendor/cfsolve/src/js/ast.rs +12 -3
  34. data/vendor/cfsolve/src/js/objects.rs +9 -2
  35. data/vendor/cfsolve/src/listing/fold.rs +0 -83
  36. data/vendor/cfsolve/src/listing/query.rs +25 -244
  37. data/vendor/cfsolve/src/listing.rs +0 -1
  38. data/vendor/cfsolve/src/session/initial.rs +14 -5
  39. data/vendor/cfsolve/src/session/probes.rs +160 -125
  40. data/vendor/cfsolve/src/session/timing.rs +58 -53
  41. data/vendor/cfsolve/src/session/widget.rs +5 -6
  42. data/vendor/cfsolve/src/stage2/analysis/analyze.rs +50 -33
  43. data/vendor/cfsolve/src/stage2/analysis/discovery.rs +61 -66
  44. data/vendor/cfsolve/src/stage2/analysis/envelope.rs +31 -21
  45. data/vendor/cfsolve/src/stage2/analysis/recognize.rs +3 -5
  46. data/vendor/cfsolve/src/stage2/analysis.rs +0 -1
  47. data/vendor/cfsolve/src/stage2/audit_globals.rs +310 -0
  48. data/vendor/cfsolve/src/stage2/benchmark.rs +5 -8
  49. data/vendor/cfsolve/src/stage2/call_stack.rs +72 -16
  50. data/vendor/cfsolve/src/stage2/interaction/native.rs +2 -1
  51. data/vendor/cfsolve/src/stage2/interaction/plan.rs +0 -3
  52. data/vendor/cfsolve/src/stage2/payload/recover.rs +54 -23
  53. data/vendor/cfsolve/src/stage2/probes/ice.rs +11 -10
  54. data/vendor/cfsolve/src/stage2/probes/media.rs +47 -33
  55. data/vendor/cfsolve/src/stage2/probes/performance.rs +1 -0
  56. data/vendor/cfsolve/src/stage2/probes/rects.rs +12 -17
  57. data/vendor/cfsolve/src/stage2/probes/stack.rs +50 -103
  58. data/vendor/cfsolve/src/stage2/probes/websocket_echo.rs +17 -86
  59. data/vendor/cfsolve/src/stage2/probes/worker_fetch.rs +30 -138
  60. data/vendor/cfsolve/src/stage2/probes.rs +0 -1
  61. data/vendor/cfsolve/src/stage2/records.rs +4 -13
  62. data/vendor/cfsolve/src/stage2/reference.json +1 -1
  63. data/vendor/cfsolve/src/stage2/reference.rs +98 -100
  64. data/vendor/cfsolve/src/stage2/registry.rs +41 -34
  65. data/vendor/cfsolve/src/stage2/replay.rs +182 -254
  66. data/vendor/cfsolve/src/stage2/stylesheets.rs +176 -0
  67. data/vendor/cfsolve/src/stage2/trace.rs +18 -0
  68. data/vendor/cfsolve/src/stage2/vocabulary.rs +135 -403
  69. data/vendor/cfsolve/src/stage2.rs +2 -1
  70. data/vendor/cfsolve/src/vm/disassemble.rs +39 -10
  71. data/vendor/cfsolve/src/vm/interpret/access.rs +5 -21
  72. data/vendor/cfsolve/src/vm/interpret/builtin.rs +6 -53
  73. data/vendor/cfsolve/src/vm/interpret/call.rs +86 -9
  74. data/vendor/cfsolve/src/vm/interpret/compile.rs +626 -0
  75. data/vendor/cfsolve/src/vm/interpret/copies.rs +232 -120
  76. data/vendor/cfsolve/src/vm/interpret/evaluate/tests.rs +96 -8
  77. data/vendor/cfsolve/src/vm/interpret/evaluate.rs +219 -92
  78. data/vendor/cfsolve/src/vm/interpret/explore.rs +155 -39
  79. data/vendor/cfsolve/src/vm/interpret/frozen.rs +171 -0
  80. data/vendor/cfsolve/src/vm/interpret/intrinsic.rs +350 -0
  81. data/vendor/cfsolve/src/vm/interpret/plan.rs +71 -44
  82. data/vendor/cfsolve/src/vm/interpret/run.rs +202 -13
  83. data/vendor/cfsolve/src/vm/interpret.rs +7 -2
  84. data/vendor/cfsolve/src/vm/machine.rs +6 -2
  85. data/vendor/cfsolve/src/vm/packed_names.rs +307 -0
  86. data/vendor/cfsolve/src/vm/session.rs +36 -14
  87. data/vendor/cfsolve/src/vm/value.rs +13 -0
  88. data/vendor/cfsolve/src/vm.rs +1 -0
  89. data/vendor/cfsolve/vendor/btls-sys/src/lib.rs +3 -0
  90. metadata +13 -6
  91. data/vendor/cfsolve/src/listing/normalize.rs +0 -264
  92. data/vendor/cfsolve/src/stage2/analysis/outputs.rs +0 -327
  93. data/vendor/cfsolve/src/stage2/probes/stylesheets.rs +0 -249
  94. data/vendor/cfsolve/src/stage2/reference-expanded.json +0 -42
  95. data/vendor/cfsolve/src/stage2/session_names.rs +0 -470
@@ -7,7 +7,6 @@ use url::Url;
7
7
  use crate::js::{self, JsObject, Options, json};
8
8
  use crate::stage2::analysis::recognize::ProbeView;
9
9
  use crate::stage2::reference;
10
- use crate::{candidates, listing};
11
10
 
12
11
  pub(crate) const OUTPUTS: [&str; 2] = [
13
12
  reference::WORKER_FETCH_STATUS,
@@ -16,11 +15,14 @@ pub(crate) const OUTPUTS: [&str; 2] = [
16
15
 
17
16
  /// The response header whose value the probe reports as its token.
18
17
  const HEADER: &str = "cf-chl-peek";
19
- /// The worker endpoint's protocol path. The host comes from the current program:
20
- /// Cloudflare rotates it independently of the iframe's host.
18
+ /// Explicit host and path prefix for the worker fetch. Builds may store them as one string or two.
19
+ /// The host's first label varies by region, such as `brunhild` or `hagen`.
20
+ /// [`super::platform::url`] builds URLs relative to the iframe instead.
21
+ const HOST_SUFFIX: &str = ".challenges.cloudflare.com";
21
22
  const PATH: &str = "/cdn-cgi/challenge-platform/h/";
22
23
 
23
- /// The worker's host and session options naming its platform segment, ray and nonce.
24
+ /// The fetched host and the session's options naming the request path's platform segment, ray
25
+ /// and nonce.
24
26
  #[derive(Clone, Debug, Deserialize, Serialize)]
25
27
  pub struct Fields {
26
28
  pub host: String,
@@ -90,154 +92,44 @@ pub(crate) fn recognize(probe: &ProbeView<'_>) -> Option<Fields> {
90
92
  "omit",
91
93
  "no-store",
92
94
  ];
93
- if !(strings.stores_all(&OUTPUTS) && strings.has_all(&markers)) {
94
- return None;
95
- }
96
- Some(Fields {
97
- host: request_host(probe.session_features, probe.pool)?,
95
+ let features = strings.features();
96
+ let host = features.iter().find_map(|text| host(text))?;
97
+ let path = features.iter().any(|text| text.contains(PATH));
98
+ (strings.stores_all(&OUTPUTS) && strings.has_all(&markers) && path).then(|| Fields {
99
+ host: host.to_owned(),
98
100
  platform_property: probe.session_name(reference::PLATFORM_OPTION),
99
101
  ray_property: probe.session_name(reference::RAY_OPTION),
100
102
  nonce_property: probe.session_name(reference::NONCE_OPTION),
101
103
  })
102
104
  }
103
105
 
104
- /// Recovers a unique endpoint from a complete URL or adjacent scheme, host and path
105
- /// fragments. Malformed descriptors remain in place so they cannot join unrelated fragments.
106
- fn request_host(features: &[String], pool: &str) -> Option<String> {
107
- let strings: Vec<String> = features
108
- .iter()
109
- .map(|text| {
110
- if text.starts_with('\0') || text.starts_with("ÿÿ") {
111
- listing::decode_string(text, pool).unwrap_or_else(|_| text.clone())
112
- } else {
113
- text.clone()
114
- }
115
- })
116
- .collect();
117
- let hosts = strings.iter().enumerate().filter_map(|(start, text)| {
118
- if !text.starts_with("https://") {
119
- return None;
120
- }
121
- let mut candidate = String::new();
122
- strings[start..].iter().take(3).find_map(|part| {
123
- candidate.push_str(part);
124
- let url = Url::parse(&candidate).ok()?;
125
- let host = url.host_str()?;
126
- // Require the bare HTTPS endpoint, without credentials or extra URL components.
127
- (host.ends_with(".challenges.cloudflare.com")
128
- && url.as_str() == format!("https://{host}{PATH}"))
129
- .then(|| host.to_owned())
130
- })
131
- });
132
- candidates::at_most_one_distinct(hosts, "worker fetch host").ok()?
106
+ /// Finds the challenge host in `text`, which may be a full URL or a host after a length prefix.
107
+ fn host(text: &str) -> Option<&str> {
108
+ let suffix = text.find(HOST_SUFFIX)?;
109
+ let start = text[..suffix]
110
+ .rfind(|c: char| !(c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-'))
111
+ .map_or(0, |index| index + 1);
112
+ (start < suffix).then(|| &text[start..suffix + HOST_SUFFIX.len()])
133
113
  }
134
114
 
135
115
  #[cfg(test)]
136
116
  mod tests {
137
- use std::collections::BTreeSet;
138
-
139
- use super::*;
140
- use crate::listing::Index;
141
- use crate::stage2::analysis::recognize::Strings;
142
- use crate::stage2::records::WriteOrder;
143
- use crate::stage2::registry::Kind;
144
- use crate::stage2::vocabulary::Vocabulary;
145
- use crate::vm::Listing;
146
-
147
- fn strings(parts: &[&str]) -> Vec<String> {
148
- parts.iter().map(|part| (*part).to_owned()).collect()
149
- }
150
-
151
- #[test]
152
- fn reads_current_hosts_from_complete_split_and_encoded_urls() {
153
- for host in ["brunhild", "hagen", "future-worker"] {
154
- let host = format!("{host}.challenges.cloudflare.com");
155
- let full = format!("https://{host}{PATH}");
156
- let encoded = format!("\0{}{host}\0padding", char::from(host.len() as u8));
157
- for features in [
158
- strings(&[&full]),
159
- strings(&[&full, &full]),
160
- strings(&["https://", &host, PATH]),
161
- strings(&["https://", &format!("{host}{PATH}")]),
162
- strings(&["https://", &encoded, PATH]),
163
- strings(&[&format!("https://{host}"), PATH]),
164
- ] {
165
- assert_eq!(request_host(&features, ""), Some(host.clone()));
166
- }
167
- }
168
- }
169
-
170
- #[test]
171
- fn recognizes_the_session_host_without_rewriting_it_to_the_reference() {
172
- let reference = &reference::REFERENCE.probes[Kind::WorkerFetch.references()[0] - 1];
173
- let session: Vec<String> = reference
174
- .iter()
175
- .map(|text| text.replace("brunhild.", "current-worker."))
176
- .collect();
177
- let listing = Listing::default();
178
- let index = Index::new(&listing);
179
- let vocabulary = Vocabulary::infer(&[&session]);
180
- let empty = BTreeSet::new();
181
- let outputs = OUTPUTS.map(str::to_owned).into_iter().collect();
182
- let fields = recognize(&ProbeView {
183
- index: &index,
184
- vocabulary: &vocabulary,
185
- position: 0,
186
- header: &empty,
187
- wrapper: &empty,
188
- pool: "",
189
- entry: 0,
190
- session_features: &session,
191
- writes: &WriteOrder::default(),
192
- strings: Strings::new(reference, &outputs),
193
- })
194
- .unwrap();
195
- assert_eq!(fields.host, "current-worker.challenges.cloudflare.com");
196
- }
197
-
198
- #[test]
199
- fn reads_pooled_hosts_and_builds_the_current_request() {
200
- let host = "hagen.challenges.cloudflare.com";
201
- let pool = format!("\0\0{host}");
202
- let descriptor = format!("ÿÿ\0\0\0\0\0\0\0\0\0{}", char::from(host.len() as u8));
203
- let host = request_host(&strings(&["https://", &descriptor, PATH]), &pool).unwrap();
204
- let fields = Fields {
205
- host,
206
- platform_property: "platform".into(),
207
- ray_property: "ray".into(),
208
- nonce_property: "nonce".into(),
209
- };
210
- let options =
211
- serde_json::from_str(r#"{"platform":"g","ray":"fresh-ray","nonce":"fresh-nonce"}"#)
212
- .unwrap();
213
- assert_eq!(
214
- fields.url(&options).unwrap().as_str(),
215
- "https://hagen.challenges.cloudflare.com/cdn-cgi/challenge-platform/h/g/i/fresh-ray/fresh-nonce"
216
- );
217
- }
117
+ use super::host;
218
118
 
219
119
  #[test]
220
- fn rejects_missing_ambiguous_and_unrelated_endpoints() {
221
- for parts in [
222
- vec![],
223
- vec!["http://hagen.challenges.cloudflare.com/cdn-cgi/challenge-platform/h/"],
224
- vec!["https://hagen.challenges.cloudflare.com/other/"],
225
- vec![
226
- "https://hagen.challenges.cloudflare.com.evil.example/cdn-cgi/challenge-platform/h/",
227
- ],
228
- vec!["https://user@hagen.challenges.cloudflare.com/cdn-cgi/challenge-platform/h/"],
229
- vec!["https://hagen.challenges.cloudflare.com:8443/cdn-cgi/challenge-platform/h/"],
230
- vec!["https://", "\0", PATH],
231
- vec!["https://hagen.challenges.cloudflare.com", "\0", PATH],
232
- vec!["https://hagen.challenges.cloudflare.com", "ÿÿ\0", PATH],
233
- vec!["https://hagen.challenges.cloudflare.com/cdn-cgi/challenge-platform/h/?extra"],
234
- vec!["https://hagen.challenges.cloudflare.com/cdn-cgi/challenge-platform/h/#extra"],
235
- vec![
236
- "https://hagen.challenges.cloudflare.com/cdn-cgi/challenge-platform/h/",
120
+ fn finds_regional_hosts_in_urls_and_prefixed_strings() {
121
+ for (text, expected) in [
122
+ (
237
123
  "https://brunhild.challenges.cloudflare.com/cdn-cgi/challenge-platform/h/",
238
- ],
124
+ Some("brunhild.challenges.cloudflare.com"),
125
+ ),
126
+ (
127
+ "\0\u{1f}hagen.challenges.cloudflare.com\0\0",
128
+ Some("hagen.challenges.cloudflare.com"),
129
+ ),
130
+ ("https://.challenges.cloudflare.com", None),
239
131
  ] {
240
- assert_eq!(request_host(&strings(&parts), ""), None, "{parts:?}");
132
+ assert_eq!(host(text), expected, "{text:?}");
241
133
  }
242
134
  }
243
135
  }
@@ -17,7 +17,6 @@ mod platform;
17
17
  pub(crate) mod private_token;
18
18
  pub(super) mod rects;
19
19
  pub(super) mod stack;
20
- pub(crate) mod stylesheets;
21
20
  pub(crate) mod websocket_echo;
22
21
  pub(crate) mod worker_fetch;
23
22
  pub(super) mod worker_navigator;
@@ -124,13 +124,13 @@ pub struct Probe {
124
124
  pub operation: Option<Operation>,
125
125
  /// The strings the probe's collection function uses, in order.
126
126
  pub features: Vec<String>,
127
- /// Collection strings including uses of constants held in registers.
128
- #[serde(default)]
129
- pub expanded_features: Vec<String>,
130
127
  /// Recovered write order used to arrange computed fields. Replayed answers retain the
131
128
  /// browser's recorded order.
132
129
  #[serde(default)]
133
130
  pub writes: WriteOrder,
131
+ /// Session literals recovered from result writes that cannot be replayed unchanged.
132
+ #[serde(default)]
133
+ pub replay_literals: JsObject,
134
134
  }
135
135
 
136
136
  impl Probe {
@@ -144,8 +144,6 @@ impl Probe {
144
144
  /// The order in which a probe's collection function writes its record's fields.
145
145
  #[derive(Clone, Debug, Default, Deserialize, Serialize)]
146
146
  pub struct WriteOrder {
147
- #[serde(default)]
148
- pub internal: Vec<String>,
149
147
  /// Stored names in execution order: the synchronous body first, then its callbacks.
150
148
  pub fields: Vec<String>,
151
149
  /// Fields that only callbacks write after the probe has finished. They follow the clock
@@ -207,14 +205,7 @@ impl ProbePlan {
207
205
  .iter()
208
206
  .map(|probe| probe.features.as_slice())
209
207
  .collect();
210
- let mut vocabulary = Vocabulary::infer(&features);
211
- let expanded: Vec<&[String]> = self
212
- .probes
213
- .iter()
214
- .map(|probe| probe.expanded_features.as_slice())
215
- .collect();
216
- vocabulary.extend_expanded(&expanded);
217
- vocabulary
208
+ Vocabulary::infer(&features)
218
209
  })
219
210
  }
220
211