guise 0.1.2

Canonical browser fingerprint bundles, human-behavior timing, and TLS profile re-exports for the Santh fleet
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
use super::*;

const ALL_TEST_PROFILES: &[StealthProfile] = &[
    StealthProfile::ChromeWindowsStable,
    StealthProfile::ChromeWindowsLegacy96,
    StealthProfile::ChromeMacStable,
    StealthProfile::EdgeWindowsStable,
    StealthProfile::Ie11Windows,
    StealthProfile::FirefoxLinux,
    StealthProfile::FirefoxWindows,
    StealthProfile::ChromeAndroid,
    StealthProfile::SafariIphone,
    StealthProfile::SafariIpad,
    StealthProfile::SafariMacStable,
    StealthProfile::ChromeLinux,
    StealthProfile::BraveWindows,
    StealthProfile::OperaWindows,
    StealthProfile::SamsungInternetAndroid,
];

/// JS-aware bracket-balance check: strips `//` line comments, `/* */` block
/// comments (first `*/` closes, exactly like a real parser), and `'`/`"`/`` ` ``
/// strings (honouring `\` escapes), then verifies every `()[]{}` is matched.
///
/// This is the cheap, browser-free guard for the bug class that silently turned
/// the entire per-profile stealth layer into a no-op: a `*/` sequence *inside* a
/// block comment (`(width/height/avail*/colorDepth)`) closed the comment early,
/// spilling comment prose into code as a `SyntaxError`. A correct comment-strip
/// surfaces the resulting stray bracket as a negative/non-zero depth here.
fn js_brackets_balanced(src: &str) -> Result<(), String> {
    #[derive(PartialEq)]
    enum S {
        Normal,
        Line,
        Block,
        Str(char),
    }
    let b = src.as_bytes();
    let mut st = S::Normal;
    let mut depth: i64 = 0;
    let mut i = 0;
    let mut escape = false;
    while i < b.len() {
        let c = b[i] as char;
        let next = if i + 1 < b.len() { b[i + 1] as char } else { '\0' };
        match st {
            S::Normal => match c {
                '/' if next == '/' => {
                    st = S::Line;
                    i += 2;
                    continue;
                }
                '/' if next == '*' => {
                    st = S::Block;
                    i += 2;
                    continue;
                }
                '\'' | '"' | '`' => st = S::Str(c),
                '(' | '[' | '{' => depth += 1,
                ')' | ']' | '}' => {
                    depth -= 1;
                    if depth < 0 {
                        return Err(format!("unbalanced '{c}' at byte {i} (depth < 0)"));
                    }
                }
                _ => {}
            },
            S::Line => {
                if c == '\n' {
                    st = S::Normal;
                }
            }
            S::Block => {
                if c == '*' && next == '/' {
                    st = S::Normal;
                    i += 2;
                    continue;
                }
            }
            S::Str(delim) => {
                if escape {
                    escape = false;
                } else if c == '\\' {
                    escape = true;
                } else if c == delim {
                    st = S::Normal;
                }
            }
        }
        i += 1;
    }
    if depth != 0 {
        return Err(format!("unbalanced brackets: final depth {depth}"));
    }
    if st != S::Normal {
        return Err("unterminated string or comment".into());
    }
    Ok(())
}

#[test]
fn profile_js_is_syntactically_balanced_for_all_profiles() {
    for p in ALL_TEST_PROFILES {
        let overrides = profile_to_overrides(p);
        let js = profile_js(&overrides);
        js_brackets_balanced(&js)
            .unwrap_or_else(|e| panic!("profile_js for {p:?} is malformed: {e}"));
    }
}

#[test]
fn js_brackets_balanced_catches_premature_comment_close() {
    // The exact historical bug: a `*/` inside a block comment closes it early,
    // spilling `colorDepth/pixelDepth)` into code with a stray `)`.
    let bad = "(() => { /* screen.* (width/height/avail*/colorDepth/pixelDepth) NOT */ })()";
    assert!(js_brackets_balanced(bad).is_err(), "must catch premature */");
    let good =
        "(() => { /* screen.* (width/height/availWidth/colorDepth/pixelDepth) NOT */ })()";
    assert!(js_brackets_balanced(good).is_ok(), "clean comment must pass");
}

#[test]
fn every_chromium_profile_has_brands() {
    for p in [
        StealthProfile::ChromeWindowsStable,
        StealthProfile::ChromeWindowsLegacy96,
        StealthProfile::ChromeMacStable,
        StealthProfile::EdgeWindowsStable,
        StealthProfile::ChromeAndroid,
        StealthProfile::ChromeLinux,
        StealthProfile::BraveWindows,
        StealthProfile::OperaWindows,
        StealthProfile::SamsungInternetAndroid,
    ] {
        let ov = profile_to_overrides(&p);
        assert!(
            !ov.brands.is_empty(),
            "{p:?} should declare userAgentData brands"
        );
    }
}

#[test]
fn chromium_client_hints_derive_full_versions_from_profile_user_agents() {
    let chrome = profile_client_hints(&StealthProfile::ChromeWindowsStable)
        .expect("Chrome should expose User-Agent Client Hints");
    assert!(chrome
        .full_version_list
        .iter()
        .any(|entry| { entry.brand == "Google Chrome" && entry.version == "131.0.0.0" }));
    assert!(chrome
        .full_version_list
        .iter()
        .any(|entry| entry.brand == "Not?A_Brand" && entry.version == "99.0.0.0"));
    assert_eq!(chrome.ua_full_version, "131.0.0.0");
    assert_eq!(chrome.platform, "Windows");
    assert_eq!(chrome.platform_version, "15.0.0");
    assert_eq!(chrome.architecture, "x86");
    assert_eq!(chrome.bitness, "64");

    let opera = profile_client_hints(&StealthProfile::OperaWindows)
        .expect("Opera should expose Chromium Client Hints");
    assert!(opera
        .full_version_list
        .iter()
        .any(|entry| entry.brand == "Opera" && entry.version == "116.0.0.0"));
    assert!(opera
        .full_version_list
        .iter()
        .any(|entry| entry.brand == "Chromium" && entry.version == "131.0.0.0"));
    assert_eq!(opera.ua_full_version, "116.0.0.0");

    let samsung = profile_client_hints(&StealthProfile::SamsungInternetAndroid)
        .expect("Samsung Internet should expose Chromium Client Hints");
    assert!(samsung
        .full_version_list
        .iter()
        .any(|entry| { entry.brand == "Samsung Internet" && entry.version == "26.0.0.0" }));
    assert!(samsung
        .full_version_list
        .iter()
        .any(|entry| entry.brand == "Chromium" && entry.version == "126.0.0.0"));
    assert_eq!(samsung.platform, "Android");
    assert_eq!(samsung.platform_version, "14.0.0");
    assert_eq!(samsung.architecture, "arm");
    assert_eq!(samsung.bitness, "");
    assert_eq!(samsung.model, "SM-S928B");
}

#[test]
fn non_chromium_profiles_have_no_client_hints() {
    for profile in [
        StealthProfile::FirefoxLinux,
        StealthProfile::FirefoxWindows,
        StealthProfile::SafariIphone,
        StealthProfile::SafariIpad,
        StealthProfile::SafariMacStable,
        StealthProfile::Ie11Windows,
    ] {
        assert!(
            profile_client_hints(&profile).is_none(),
            "{profile:?} must not expose User-Agent Client Hints"
        );
        let overrides = profile_to_overrides(&profile);
        assert_eq!(client_hint_brands_json(&overrides), "[]");
        assert_eq!(client_hint_full_version_list_json(&overrides), "[]");
    }
}

#[test]
fn hardware_variants_are_profile_coherent() {
    for profile in ALL_TEST_PROFILES {
        let variants = profile_hardware_variants(*profile);
        assert!(!variants.is_empty(), "{profile:?} has no hardware variants");

        for hardware in variants {
            assert!(hardware.screen_width > 0, "{profile:?} width is zero");
            assert!(hardware.screen_height > 0, "{profile:?} height is zero");
            assert!(
                matches!(hardware.color_depth, 24 | 30),
                "{profile:?} has uncommon color depth {}",
                hardware.color_depth
            );
            assert!(
                hardware.hardware_concurrency >= 4,
                "{profile:?} reports too few logical cores"
            );
            assert!(hardware.device_memory >= 4, "{profile:?} memory too low");
            // WebGL vendor/renderer must be COHERENT: either both empty (native
            // passthrough — a matched-host persona exposes the host's real,
            // Gecko-sanitized adapter, whose pixels match) or both pinned (a
            // cross-OS persona supplying a coherent adapter for its claimed OS).
            // A half-state — empty vendor with a non-empty renderer, or vice
            // versa — is the exact incoherence the old generic override shipped
            // ("" vendor + "…GTX 1050 Ti" renderer) and is never valid.
            assert_eq!(
                hardware.webgl_vendor.is_empty(),
                hardware.webgl_renderer.is_empty(),
                "{profile:?} half-spoofed WebGL adapter (vendor/renderer emptiness disagree)"
            );

            let facts = profile_facts(*profile);
            if facts.mobile {
                assert!(
                    hardware.screen_width <= 1024,
                    "{profile:?} mobile profile has desktop width"
                );
            } else {
                assert!(
                    hardware.screen_width >= 1024,
                    "{profile:?} desktop profile has mobile width"
                );
            }
        }
    }
}

#[test]
fn default_hardware_matches_materialized_overrides() {
    for profile in ALL_TEST_PROFILES {
        let hardware = profile_hardware(*profile);
        let overrides = profile_to_overrides(profile);

        assert_eq!(overrides.screen_width, hardware.screen_width);
        assert_eq!(overrides.screen_height, hardware.screen_height);
        assert_eq!(overrides.color_depth, hardware.color_depth);
        assert_eq!(
            overrides.hardware_concurrency,
            u32::from(hardware.hardware_concurrency)
        );
        assert_eq!(overrides.device_memory, u32::from(hardware.device_memory));
        assert_eq!(overrides.webgl_vendor, hardware.webgl_vendor);
        assert_eq!(overrides.webgl_renderer, hardware.webgl_renderer);
    }
}

#[test]
fn indexed_hardware_overrides_apply_selected_variant() {
    let profile = StealthProfile::ChromeWindowsStable;
    let hardware = profile_hardware_at(profile, 2);
    let overrides = profile_to_overrides_at(&profile, 2);

    assert_eq!(overrides.screen_width, hardware.screen_width);
    assert_eq!(overrides.screen_height, hardware.screen_height);
    assert_eq!(overrides.webgl_vendor, "Google Inc. (AMD)");
    assert!(overrides.webgl_renderer.contains("Radeon RX 6700 XT"));
}

#[test]
fn safari_and_firefox_have_no_brands() {
    for p in [
        StealthProfile::FirefoxLinux,
        StealthProfile::FirefoxWindows,
        StealthProfile::SafariIphone,
        StealthProfile::SafariIpad,
        StealthProfile::SafariMacStable,
    ] {
        let ov = profile_to_overrides(&p);
        assert!(
            ov.brands.is_empty(),
            "{p:?} does not expose userAgentData / Client Hints"
        );
    }
}

#[test]
fn ua_matches_platform() {
    // Windows UA must pair with Win32 platform; Mac with MacIntel; etc.
    // Mismatches are *more* suspicious than vanilla headless.
    let cases = [
        (StealthProfile::ChromeWindowsStable, "Windows", "Win32"),
        (StealthProfile::ChromeWindowsLegacy96, "Windows", "Win32"),
        (StealthProfile::ChromeMacStable, "Mac OS X", "MacIntel"),
        (StealthProfile::EdgeWindowsStable, "Windows", "Win32"),
        (StealthProfile::Ie11Windows, "Trident/7.0", "Win32"),
        (StealthProfile::FirefoxLinux, "Linux", "Linux x86_64"),
        (StealthProfile::FirefoxWindows, "Windows", "Win32"),
        (StealthProfile::ChromeAndroid, "Android", "Linux armv8l"),
        (StealthProfile::ChromeLinux, "Linux", "Linux x86_64"),
        (StealthProfile::SafariIphone, "iPhone", "iPhone"),
        (StealthProfile::SafariIpad, "iPad", "iPad"),
        (StealthProfile::SafariMacStable, "Mac OS X", "MacIntel"),
        (StealthProfile::BraveWindows, "Windows", "Win32"),
        (StealthProfile::OperaWindows, "Windows", "Win32"),
        (
            StealthProfile::SamsungInternetAndroid,
            "Android",
            "Linux armv8l",
        ),
    ];
    for (p, ua_substr, platform) in cases {
        let ov = profile_to_overrides(&p);
        assert!(
            ov.user_agent.contains(ua_substr),
            "{p:?} UA missing {ua_substr}"
        );
        assert_eq!(ov.platform, platform, "{p:?} platform mismatch");
    }
}

#[test]
fn chrome_windows_user_agent_const_matches_profile() {
    let ov = profile_to_overrides(&StealthProfile::ChromeWindowsStable);
    assert_eq!(ov.user_agent, CHROME_WINDOWS_STABLE_USER_AGENT);
}

#[test]
fn profile_user_agent_matches_materialized_overrides() {
    for profile in ALL_TEST_PROFILES {
        assert_eq!(
            profile_to_overrides(profile).user_agent,
            profile_user_agent(*profile),
            "{profile:?} duplicated UA drifted from profile_user_agent"
        );
    }
}

#[test]
fn materialized_overrides_share_base_identity_facts() {
    for profile in ALL_TEST_PROFILES {
        let facts = profile_facts(*profile);
        let overrides = profile_to_overrides(profile);
        assert_eq!(overrides.user_agent, facts.user_agent);
        assert_eq!(overrides.platform, facts.platform);
        assert_eq!(overrides.mobile, facts.mobile);
        assert_eq!(overrides.screen_width, facts.screen_width);
        assert_eq!(overrides.screen_height, facts.screen_height);
        assert_eq!(
            overrides.languages,
            facts
                .languages
                .iter()
                .map(|language| (*language).to_string())
                .collect::<Vec<_>>()
        );
    }
}

#[test]
fn navigation_headers_share_base_identity_facts() {
    let facts = profile_facts(StealthProfile::FirefoxLinux);
    assert_eq!(
        profile_navigation_headers(StealthProfile::FirefoxLinux),
        [
            NavigationHeader {
                name: USER_AGENT_HEADER,
                value: facts.user_agent,
            },
            NavigationHeader {
                name: ACCEPT_HEADER,
                value: facts.accept,
            },
            NavigationHeader {
                name: ACCEPT_LANGUAGE_HEADER,
                value: facts.accept_language,
            },
        ]
    );
}

#[test]
fn browser_headers_share_base_identity_facts_with_compression() {
    let facts = profile_facts(StealthProfile::FirefoxLinux);
    assert_eq!(
        profile_browser_headers(StealthProfile::FirefoxLinux),
        [
            NavigationHeader {
                name: USER_AGENT_HEADER,
                value: facts.user_agent,
            },
            NavigationHeader {
                name: ACCEPT_HEADER,
                value: facts.accept,
            },
            NavigationHeader {
                name: ACCEPT_LANGUAGE_HEADER,
                value: facts.accept_language,
            },
            NavigationHeader {
                name: ACCEPT_ENCODING_HEADER,
                value: facts.accept_encoding,
            },
        ]
    );
}

#[test]
fn profile_js_emits_uadata_only_when_brands_present() {
    let chrome = profile_js(&profile_to_overrides(&StealthProfile::ChromeWindowsStable));
    assert!(chrome.contains("userAgentData"));
    // Firefox profile still emits the conditional but the runtime
    // brands.length check skips assignment. Source-level check:
    // the JS must always contain the guard.
    assert!(chrome.contains("brands.length > 0"));
}

#[test]
fn profile_js_high_entropy_client_hints_derive_from_profile() {
    let chrome = profile_js(&profile_to_overrides(&StealthProfile::ChromeWindowsStable));
    assert!(chrome.contains("fullVersionList"));
    assert!(chrome.contains(r#""version":"131.0.0.0""#));
    assert!(chrome.contains("uaFullVersion: \"131.0.0.0\""));
    assert!(!chrome.contains("uaFullVersion: '130.0.0.0'"));

    let linux = profile_js(&profile_to_overrides(&StealthProfile::ChromeLinux));
    assert!(linux.contains("platformVersion: \"\""));
    assert!(linux.contains("platform: \"Linux\""));
}

#[test]
fn profile_js_overrides_webgl_unmasked_params() {
    let js = profile_js(&profile_to_overrides(&StealthProfile::ChromeMacStable));
    assert!(
        js.contains("0x1F00"),
        "WebGL VENDOR constant must be referenced"
    );
    assert!(
        js.contains("0x1F01"),
        "WebGL RENDERER constant must be referenced"
    );
    assert!(
        js.contains("0x9245"),
        "WebGL UNMASKED_VENDOR constant must be referenced"
    );
    assert!(
        js.contains("0x9246"),
        "WebGL UNMASKED_RENDERER constant must be referenced"
    );
    assert!(
        js.contains("Apple M1 Pro"),
        "Mac profile must pin an Apple GPU renderer"
    );
}

#[test]
fn profile_js_pins_window_dimensions_and_touch_capability() {
    let desktop = profile_js(&profile_to_overrides(&StealthProfile::ChromeWindowsStable));
    assert!(desktop.contains("Object.defineProperty(window, 'outerWidth'"));
    assert!(desktop.contains("Object.defineProperty(window, 'innerHeight'"));
    assert!(desktop.contains("Object.defineProperty(Navigator.prototype, 'maxTouchPoints'"));
    // Getters are wrapped in `__seal(...)` so their `.toString()` reports
    // `[native code]` (see NATIVE_SEAL_PRELUDE); assert the sealed form.
    assert!(desktop.contains("get: __seal(() => 1920, 'get outerWidth')"));
    assert!(desktop.contains("get: __seal(() => 1080 + 88, 'get outerHeight')"));

    let mobile = profile_js(&profile_to_overrides(&StealthProfile::ChromeAndroid));
    assert!(mobile.contains("Object.defineProperty(Navigator.prototype, 'maxTouchPoints'"));
    assert!(mobile.contains("get: __seal(() => 5, 'get maxTouchPoints')"));
    assert!(mobile.contains("+ 0"));
}

#[test]
fn android_profile_is_mobile_with_narrow_screen() {
    let ov = profile_to_overrides(&StealthProfile::ChromeAndroid);
    assert!(ov.mobile);
    assert!(
        ov.screen_width < 500,
        "mobile profile should have a phone-sized screen"
    );
}

#[test]
fn languages_default_to_english() {
    // All shipped profiles start with en-US. Localised profiles are
    // a future addition; for now we ship one consistent set so
    // accept-language headers don't conflict with navigator.languages.
    for p in ALL_TEST_PROFILES {
        let ov = profile_to_overrides(p);
        assert_eq!(ov.languages.first().map(|s| s.as_str()), Some("en-US"));
    }
}

#[test]
fn safari_profiles_have_apple_webgl_renderer() {
    for p in [
        StealthProfile::SafariIphone,
        StealthProfile::SafariIpad,
        StealthProfile::SafariMacStable,
    ] {
        let ov = profile_to_overrides(&p);
        assert!(
            ov.webgl_vendor.contains("Apple"),
            "{p:?} must claim an Apple GPU vendor"
        );
    }
}

#[test]
fn brave_profile_lists_brave_brand_first() {
    let ov = profile_to_overrides(&StealthProfile::BraveWindows);
    let first = ov.brands.first().map(|(b, _)| b.as_str());
    assert_eq!(first, Some("Brave"));
}

#[test]
fn samsung_internet_profile_is_mobile() {
    let ov = profile_to_overrides(&StealthProfile::SamsungInternetAndroid);
    assert!(ov.mobile);
    assert!(ov.user_agent.contains("SamsungBrowser"));
}

#[test]
fn opera_profile_lists_opera_brand() {
    let ov = profile_to_overrides(&StealthProfile::OperaWindows);
    let names: Vec<&str> = ov.brands.iter().map(|(b, _)| b.as_str()).collect();
    assert!(names.contains(&"Opera"));
    assert!(ov.user_agent.contains("OPR/"));
}

#[test]
fn safari_profiles_have_no_brave_or_opera_marker() {
    // Safari profiles must not accidentally inherit Brave/Opera UAs.
    for p in [
        StealthProfile::SafariIphone,
        StealthProfile::SafariIpad,
        StealthProfile::SafariMacStable,
    ] {
        let ov = profile_to_overrides(&p);
        assert!(!ov.user_agent.contains("OPR/"));
        assert!(!ov.user_agent.contains("Brave"));
        assert!(ov.user_agent.contains("Safari/"));
    }
}

#[test]
fn edge_profile_lists_microsoft_brand_distinct_from_chrome() {
    let ov = profile_to_overrides(&StealthProfile::EdgeWindowsStable);
    let brand_names: Vec<&str> = ov.brands.iter().map(|(b, _)| b.as_str()).collect();
    assert!(brand_names.contains(&"Microsoft Edge"));
    assert!(
        !brand_names.contains(&"Google Chrome"),
        "Edge profile must not list Google Chrome - that mismatch is itself a tell"
    );
}