guise 0.1.8

Canonical browser fingerprint bundles, human-behavior timing, and TLS profile re-exports
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
use super::classify::*;
use super::*;

#[test]
fn catalogue_has_at_least_probe_count_floor_entries() {
    let list = probes();
    assert!(
        list.len() >= PROBE_COUNT_FLOOR,
        "probe catalogue has {} entries; floor is {}",
        list.len(),
        PROBE_COUNT_FLOOR
    );
}

#[test]
fn probe_names_are_unique() {
    let list = probes();
    let mut seen = std::collections::HashSet::new();
    for p in &list {
        assert!(seen.insert(p.name), "duplicate probe name: {}", p.name);
    }
}

#[test]
fn probe_severities_distributed() {
    let list = probes();
    let high = list.iter().filter(|p| p.severity == Severity::High).count();
    let medium = list
        .iter()
        .filter(|p| p.severity == Severity::Medium)
        .count();
    let low = list.iter().filter(|p| p.severity == Severity::Low).count();
    assert!(
        high >= 4,
        "expected at least 4 High-severity probes; got {high}"
    );
    assert!(
        medium >= 5,
        "expected at least 5 Medium-severity probes; got {medium}"
    );
    assert!(
        low >= 20,
        "expected at least 20 Low-severity probes; got {low}"
    );
}

#[test]
fn classify_webdriver_ok_pass_on_false_critical_on_true() {
    // A real browser reports navigator.webdriver === false (present, false).
    assert_eq!(
        classify_webdriver_ok(&serde_json::json!(false)),
        ProbeOutcome::Pass
    );
    // null (hidden) is leniently accepted...
    assert_eq!(
        classify_webdriver_ok(&serde_json::Value::Null),
        ProbeOutcome::Pass
    );
    // ...but true is the automation leak.
    match classify_webdriver_ok(&serde_json::json!(true)) {
        ProbeOutcome::Critical(_) => {}
        other => panic!("expected Critical for webdriver===true, got {other:?}"),
    }
}

#[test]
fn classify_must_be_undefined_pass_on_null() {
    assert_eq!(
        classify_must_be_undefined(&serde_json::Value::Null),
        ProbeOutcome::Pass
    );
}

#[test]
fn classify_must_be_undefined_critical_on_value() {
    match classify_must_be_undefined(&serde_json::json!(true)) {
        ProbeOutcome::Critical(_) => {}
        other => panic!("expected Critical, got {other:?}"),
    }
}

#[test]
fn classify_must_be_true_pass_on_true() {
    assert_eq!(
        classify_must_be_true(&serde_json::json!(true)),
        ProbeOutcome::Pass
    );
}

#[test]
fn classify_must_be_true_critical_on_false() {
    match classify_must_be_true(&serde_json::json!(false)) {
        ProbeOutcome::Critical(_) => {}
        other => panic!("expected Critical, got {other:?}"),
    }
}

#[test]
fn classify_must_be_chromium_ua_pass_on_real_chrome() {
    assert_eq!(
        classify_must_be_chromium_ua(&serde_json::json!(
            "Mozilla/5.0 (X11; Linux x86_64) Chrome/134.0.0.0 Safari/537.36"
        )),
        ProbeOutcome::Pass
    );
}

#[test]
fn classify_must_be_chromium_ua_passes_chromium_vendor_profiles() {
    for ua in [
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 \
         (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0",
        "Mozilla/5.0 (Linux; Android 14; SM-S928B) AppleWebKit/537.36 \
         (KHTML, like Gecko) SamsungBrowser/26.0 Chrome/126.0.0.0 Mobile Safari/537.36",
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 \
         (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 OPR/116.0.0.0",
    ] {
        assert_eq!(
            classify_must_be_chromium_ua(&serde_json::json!(ua)),
            ProbeOutcome::Pass,
            "{ua}"
        );
    }
}

#[test]
fn classify_must_be_chromium_ua_critical_on_headless() {
    match classify_must_be_chromium_ua(&serde_json::json!("HeadlessChrome/134")) {
        ProbeOutcome::Critical(_) => {}
        other => panic!("expected Critical, got {other:?}"),
    }
}

#[test]
fn classify_must_be_chromium_ua_drifts_on_non_chromium_browser() {
    for ua in [
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_5) AppleWebKit/605.1.15 \
         (KHTML, like Gecko) Version/17.5 Safari/605.1.15",
    ] {
        match classify_must_be_chromium_ua(&serde_json::json!(ua)) {
            ProbeOutcome::Drift(message) => assert!(
                message.contains("non-Chromium"),
                "unexpected drift message: {message}"
            ),
            other => panic!("expected Drift, got {other:?}"),
        }
    }
}

// ─── Family-aware catalogue (Lane B) ─────────────────────────────────────
// Two-pair: the Chromium catalogue measures against Chrome truth; the Firefox
// catalogue drops the Chromium-only surfaces (which a real Firefox legitimately
// lacks) and substitutes the matching Firefox truths.

#[test]
fn chromium_catalogue_keeps_chrome_only_surfaces() {
    let names: std::collections::HashSet<&str> = probes_for(UserAgentBrowser::Chrome)
        .iter()
        .map(|p| p.name)
        .collect();
    // Chrome truths are present...
    assert!(names.contains("window.chrome.runtime exists"));
    assert!(names.contains("navigator.vendor non-empty"));
    assert!(names.contains("navigator.usb exists"));
    assert!(names.contains("navigator.productSub equals '20030107'"));
    // ...and the Firefox-specific truths are NOT (Chrome would fail them).
    assert!(!names.contains("window.chrome absent (Firefox)"));
    assert!(!names.contains("navigator.vendor is empty (Firefox)"));
    // `probes()` is the back-compatible Chromium default.
    assert_eq!(probes().len(), probes_for(UserAgentBrowser::Chrome).len());
}

#[test]
fn firefox_catalogue_drops_chrome_only_and_adds_firefox_truths() {
    let names: std::collections::HashSet<&str> = probes_for(UserAgentBrowser::Firefox)
        .iter()
        .map(|p| p.name)
        .collect();
    // EVERY Chromium-only surface is dropped (none may survive for Firefox).
    for chrome_only in super::catalogue::CHROMIUM_ONLY_PROBES {
        assert!(
            !names.contains(chrome_only),
            "Firefox catalogue must not probe Chromium-only surface {chrome_only:?}"
        );
    }
    // The Firefox truths replace them.
    assert!(names.contains("window.chrome absent (Firefox)"));
    assert!(names.contains("navigator.vendor is empty (Firefox)"));
    assert!(names.contains("navigator.userAgent is Gecko/Firefox"));
    assert!(names.contains("navigator.usb absent (Firefox)"));
    assert!(names.contains("navigator.oscpu is a string (Firefox-only surface)"));
    // The extended-catalogue Chromium-only surfaces are dropped AND their inverse
    // "absent (Firefox)" assertions are present, a Firefox persona leaking a
    // Blink-only API (performance.memory et al.) is a Chromium-engine tell.
    assert!(!names.contains("memory jsHeapSizeLimit plausible"));
    assert!(!names.contains("navigator.keyboard exists"));
    assert!(!names.contains("EyeDropper exists"));
    assert!(names.contains("performance.memory absent (Firefox)"));
    assert!(names.contains("navigator.keyboard absent (Firefox)"));
    assert!(names.contains("window.EyeDropper absent (Firefox)"));
}

/// Durable guard for the WIRING bug class behind the extended-catalogue leak: a
/// probe that asserts the PRESENCE of a Chromium-only surface
/// (`classify_must_be_true`) must never survive into the Firefox catalogue, where
/// it would Critical on every real Gecko build. The earlier
/// `firefox_catalogue_drops_chrome_only_and_adds_firefox_truths` check could not
/// catch this: it only re-checks names ALREADY in `CHROMIUM_ONLY_PROBES`, so a
/// Chromium-only surface that was never registered there (exactly how the extended
/// catalogue's `performance.memory`/`navigator.keyboard`/… leaked) passed
/// vacuously. This guard inspects the actual Firefox catalogue: any presence-probe
/// whose JS references a known Blink-only global is a regression.
#[test]
fn firefox_catalogue_has_no_chromium_only_presence_probe() {
    // Blink/Chromium-only globals a real Gecko build never exposes. A
    // `classify_must_be_true` probe testing one of these is a false-Critical on
    // Firefox. (The inverse `… absent (Firefox)` probes also name these tokens but
    // classify with `classify_must_be_undefined`, so the classifier filter below
    // excludes them.)
    const CHROMIUM_ONLY_GLOBAL_TOKENS: &[&str] = &[
        "performance.memory",
        "navigator.keyboard",
        "navigator.presentation",
        "navigator.scheduling",
        "setAppBadge",
        "clearAppBadge",
        // NB: `documentPictureInPicture` is intentionally NOT here. Firefox 151
        // ships it in a secure context (verified live), so it is not a
        // Chromium-only global. WebGPU (`navigator.gpu`) is likewise omitted: it is
        // engine-conditional (Firefox Windows has it), not Chromium-only. Both are
        // dropped for the Firefox gate via CHROMIUM_ONLY_PROBES category 2 instead.
        "EyeDropper",
        "BarcodeDetector",
        "FaceDetector",
        "AbsoluteOrientationSensor",
        "window.chrome",
        "navigator.usb",
        "navigator.hid",
        "ReportingObserver",
    ];
    for p in probes_for(UserAgentBrowser::Firefox) {
        if !std::ptr::fn_addr_eq(
            p.classifier,
            classify_must_be_true as fn(&serde_json::Value) -> ProbeOutcome,
        ) {
            continue; // only PRESENCE assertions can false-Critical on absence
        }
        for token in CHROMIUM_ONLY_GLOBAL_TOKENS {
            assert!(
                !p.js.contains(token),
                "Firefox catalogue presence-probe {:?} tests Chromium-only global {token:?} \
It will report Critical on every real Gecko build. Drop it via \
                 CHROMIUM_ONLY_PROBES and add an inverse `… absent (Firefox)` probe.",
                p.name
            );
        }
    }
}

/// Engine-conditional surfaces (WebGPU, Document Picture-in-Picture) must be
/// DROPPED for the Firefox gate, verified live (tests/surface_truth_live.rs) that
/// FF-151-Linux lacks WebGPU yet ships Document PiP, so a `classify_must_be_true`
/// presence check false-Criticals guise's OWN browser and an "absent" inverse
/// false-Criticals Firefox Windows. They must still be present in the Chrome
/// reference catalogue (modern desktop Chrome exposes the API surface), so this is
/// a family-aware drop, not a deletion.
#[test]
fn engine_conditional_surfaces_dropped_for_firefox_kept_for_chrome() {
    const CONDITIONAL: &[&str] = &[
        "navigator.gpu exists",
        "navigator.gpu.requestAdapter is function",
        "GPUAdapter.limits is object",
        "GPUBufferUsage exists",
        "navigator.gpu.getPreferredCanvasFormat exists",
        "DocumentPictureInPicture exists",
        // OS/environment-conditional (headless/Linux Firefox legitimately has 0 TTS
        // voices); dropped for the Firefox gate, kept in the Chrome reference.
        "speechSynthesis.getVoices returns >=16 voices",
    ];
    let chrome: std::collections::HashSet<&str> = probes().iter().map(|p| p.name).collect();
    let firefox: std::collections::HashSet<&str> = probes_for(UserAgentBrowser::Firefox)
        .iter()
        .map(|p| p.name)
        .collect();

    for name in CONDITIONAL {
        assert!(
            chrome.contains(name),
            "conditional surface {name:?} must stay in the Chrome reference catalogue"
        );
        assert!(
            !firefox.contains(name),
            "conditional surface {name:?} must be DROPPED for the Firefox gate \
             (it false-Criticals guise's own Firefox)"
        );
    }

    // No probe of ANY kind may assert a WebGPU or Document-PiP truth for Firefox
    // neither a presence check nor a stray "absent" inverse, because the surface
    // is engine-conditional in BOTH directions on Firefox.
    for p in probes_for(UserAgentBrowser::Firefox) {
        let n = p.name;
        assert!(
            !n.contains("gpu") && !n.contains("GPU") && !n.contains("DocumentPictureInPicture"),
            "Firefox catalogue must not assert engine-conditional surface {n:?}"
        );
    }
}

#[test]
fn firefox_catalogue_probe_names_unique() {
    let list = probes_for(UserAgentBrowser::Firefox);
    let mut seen = std::collections::HashSet::new();
    for p in &list {
        assert!(
            seen.insert(p.name),
            "duplicate probe name in firefox catalogue: {}",
            p.name
        );
    }
}

#[test]
fn classify_empty_string_pass_on_empty_critical_on_value() {
    assert_eq!(
        classify_must_be_empty_string(&serde_json::json!("")),
        ProbeOutcome::Pass
    );
    match classify_must_be_empty_string(&serde_json::json!("Google Inc.")) {
        ProbeOutcome::Critical(_) => {}
        other => panic!("expected Critical for non-empty vendor, got {other:?}"),
    }
}

#[test]
fn classify_nonzero_int_boundary_at_zero_and_one() {
    assert_eq!(
        classify_must_be_nonzero_int(&serde_json::json!(1)),
        ProbeOutcome::Pass
    );
    match classify_must_be_nonzero_int(&serde_json::json!(0)) {
        ProbeOutcome::Critical(_) => {}
        other => panic!("expected Critical for 0, got {other:?}"),
    }
    match classify_must_be_nonzero_int(&serde_json::Value::Null) {
        ProbeOutcome::Drift(_) => {}
        other => panic!("expected Drift for null, got {other:?}"),
    }
}

#[test]
fn classify_firefox_ua_pass_on_gecko_critical_on_chrome() {
    assert_eq!(
        classify_must_be_firefox_ua(&serde_json::json!(
            "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0"
        )),
        ProbeOutcome::Pass
    );
    match classify_must_be_firefox_ua(&serde_json::json!(
        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36"
    )) {
        ProbeOutcome::Critical(_) => {}
        other => panic!("expected Critical for a Chrome UA, got {other:?}"),
    }
}

#[test]
fn classify_iana_timezone_pass_on_real_zones() {
    for tz in [
        "America/Phoenix",
        "Europe/London",
        "Etc/GMT+5",
        "America/Argentina/Buenos_Aires",
        "UTC",
    ] {
        assert_eq!(
            classify_iana_timezone(&serde_json::json!(tz)),
            ProbeOutcome::Pass,
            "{tz}"
        );
    }
}

#[test]
fn classify_iana_timezone_critical_on_empty_drift_on_garbage() {
    // An empty resolved zone is the stripped-ICU / headless tell → Critical.
    match classify_iana_timezone(&serde_json::json!("")) {
        ProbeOutcome::Critical(m) => assert!(m.contains("EMPTY")),
        other => panic!("expected Critical for empty tz, got {other:?}"),
    }
    // A non-IANA-shaped string is unusual but not a definitive bot → Drift. We do
    // NOT pin a specific zone (the persona has no timezone field), so a bareword
    // without a region is malformed, not "wrong zone".
    for bad in ["notazone", "America/", "/Phoenix", "Foo//Bar", "Etc/GMT 5"] {
        match classify_iana_timezone(&serde_json::json!(bad)) {
            ProbeOutcome::Drift(_) => {}
            other => panic!("expected Drift for {bad:?}, got {other:?}"),
        }
    }
    // Non-string → Drift, never a silent pass.
    match classify_iana_timezone(&serde_json::Value::Null) {
        ProbeOutcome::Drift(_) => {}
        other => panic!("expected Drift for null tz, got {other:?}"),
    }
}

#[test]
fn classify_must_not_contain_swiftshader_critical_on_match() {
    match classify_must_not_contain_swiftshader(&serde_json::json!("Google Inc. (SwiftShader)")) {
        ProbeOutcome::Critical(_) => {}
        other => panic!("expected Critical, got {other:?}"),
    }
}

#[test]
fn drift_report_is_green_when_passed_meets_floor() {
    let report = DriftReport {
        probed: 100,
        passed: 95,
        drift: 5,
        critical: 0,
        probe_errors: 0,
        per_probe: vec![],
    };
    assert!(report.is_green());
}

#[test]
fn drift_report_is_not_green_with_critical() {
    let report = DriftReport {
        probed: 100,
        passed: 99,
        drift: 0,
        critical: 1,
        probe_errors: 0,
        per_probe: vec![],
    };
    assert!(!report.is_green());
}

#[test]
fn drift_report_is_not_green_when_passed_under_floor() {
    let report = DriftReport {
        probed: 100,
        passed: 80,
        drift: 20,
        critical: 0,
        probe_errors: 0,
        per_probe: vec![],
    };
    assert!(!report.is_green());
}

#[test]
fn classify_user_agent_data_empty_or_absent_passes_for_firefox_truth() {
    use super::classify::classify_user_agent_data_empty_or_absent;
    assert_eq!(
        classify_user_agent_data_empty_or_absent(&serde_json::Value::Null),
        ProbeOutcome::Pass
    );
    assert_eq!(
        classify_user_agent_data_empty_or_absent(&serde_json::json!([])),
        ProbeOutcome::Pass
    );
}

#[test]
fn classify_user_agent_data_empty_or_absent_critical_on_chromium_brands() {
    use super::classify::classify_user_agent_data_empty_or_absent;
    match classify_user_agent_data_empty_or_absent(&serde_json::json!([
        {"brand": "Chromium", "version": "131"},
        {"brand": "Google Chrome", "version": "131"}
    ])) {
        ProbeOutcome::Critical(m) => assert!(m.contains("Client Hints brands")),
        other => panic!("expected Critical, got {other:?}"),
    }
}

#[test]
fn hardware_concurrency_probe_catches_gap_values_from_tests_gap_rs() {
    // G211: the static validate_overrides gap says out-of-range values pass
    // validation, but the runtime catalogue probe continuously catches them.
    assert!(!classify_hardware_concurrency(&serde_json::json!(0)).is_pass());
    assert!(!classify_hardware_concurrency(&serde_json::json!(10000)).is_pass());
}

#[test]
fn firefox_catalogue_has_user_agent_data_probe() {
    let names: std::collections::HashSet<&str> = probes_for(UserAgentBrowser::Firefox)
        .iter()
        .map(|p| p.name)
        .collect();
    assert!(
        names.contains("navigator.userAgentData absent or brands empty (Firefox)"),
        "G211 gap converted to a Firefox-family catalogue probe"
    );
}

#[test]
fn render_report_includes_summary() {
    let report = DriftReport {
        probed: 5,
        passed: 5,
        drift: 0,
        critical: 0,
        probe_errors: 0,
        per_probe: vec![ProbeReport {
            name: "test_probe".to_string(),
            severity: "Low".to_string(),
            outcome: ProbeOutcome::Pass,
        }],
    };
    let rendered = render_report(&report);
    assert!(rendered.contains("STEALTH PROBE"));
    assert!(rendered.contains("test_probe"));
}

proptest::proptest! {
    #![proptest_config(proptest::test_runner::Config {
        cases: 10_000, .. proptest::test_runner::Config::default()
    })]

    #[test]
    fn prop_classify_in_range_consistent(
        n in 0u64..1_000_000,
        min in 0u64..1000,
        max in 1000u64..10_000,
    ) {
        let outcome = classify_in_range(&serde_json::json!(n), min, max);
        if (min..=max).contains(&n) {
            assert_eq!(outcome, ProbeOutcome::Pass);
        } else {
            match outcome {
                ProbeOutcome::Drift(_) => {},
                other => panic!("expected Drift, got {other:?}"),
            }
        }
    }

    #[test]
    fn prop_render_report_does_not_panic(probed in 0usize..1000, passed in 0usize..1000) {
        let report = DriftReport {
            probed,
            passed: passed.min(probed),
            drift: 0,
            critical: 0,
            probe_errors: 0,
            per_probe: vec![],
        };
        let _ = render_report(&report);
    }
}