mirror of
https://github.com/daijro/camoufox.git
synced 2026-11-19 00:07:28 +00:00
Launcher-side fixes found by comparing camoufox against stock Firefox 152.0.4 on Linux, Windows 11 and macOS hosts: - DNT / GPC: BrowserForge draws doNotTrack "1" on most Firefox samples, but a stock Firefox 152 reports "unspecified" and globalPrivacyControl false; the stock defaults are used unless the caller sets them, and both are applied as prefs so the API, the worker and the DNT / Sec-GPC headers agree (#760). - Timezone and geolocation: the timezone is passed to the browser, and a configured position sets permissions.default.geo so permissions.query agrees with the auto-grant (#769, #773). - hardwareConcurrency: the reported count is the fingerprint's and the browser is pinned to that many cores (cpu_affinity.py, Linux/Windows), so worker timing agrees with it; otherwise the host count snapped into the core counts real machines ship with (never 2, Firefox's resistFingerprinting value). - Fonts: the OS base is always present in full, OS-version variants are drawn all-or-nothing, co-shipped groups stay together, Cascadia is never claimed off Windows, a native macOS/Windows identity claims only the real OS base, and gfx.font_rendering.fallback.async is off on Linux so per-character fallback does not depend on cmap-load timing. - Speech voices: a per-OS installed-voice model (voice-manifests.json) with the voiceURI formats each backend really produces (voice-uris.json); no default voice where stock has none. - WebGL: extensions a release Firefox never exposes are filtered, but OVR_multiview2 stays for Windows D3D11 renderers, which expose it. - Media devices: a seeded draw of common per-OS devices with OS-style labels. - Windows scrollbars follow the drawn Windows version (overlay on 11). - Glyph-advance perturbation (fonts:spacing_seed) defaults to off: it moved every measureText width off the value the same font gives on a real machine. - Launcher prefs are also exported as CAMOU_PREFS_1..N so camoufox.cfg applies them at startup, and the browser UI locale follows the spoofed locale. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
153 lines
5.6 KiB
Python
153 lines
5.6 KiB
Python
import sqlite3
|
|
from pathlib import Path
|
|
from typing import Dict, List, Optional, Tuple
|
|
|
|
import numpy as np
|
|
import orjson
|
|
|
|
from camoufox.pkgman import OS_ARCH_MATRIX
|
|
|
|
# Get database path relative to this file
|
|
DB_PATH = Path(__file__).parent / 'webgl_data.db'
|
|
|
|
# Extensions a release Firefox never exposes (draft extensions behind
|
|
# webgl.enable-draft-extensions, or mobile-only): some database rows carry
|
|
# them, and a spoofed list that names one is a tell on its own. Measured on
|
|
# stock Firefox 152.0.4 on real Windows 11 (ANGLE D3D11) 2026-09-16: none of
|
|
# these four are exposed. WEBGL_provoking_vertex is NOT in this set: stock
|
|
# Firefox on Apple GPUs and on Windows does expose it.
|
|
_NEVER_EXPOSED_EXTENSIONS = frozenset(
|
|
{
|
|
'WEBGL_multi_draw',
|
|
'WEBGL_clip_cull_distance',
|
|
'EXT_texture_norm16',
|
|
'WEBGL_compressed_texture_etc1',
|
|
}
|
|
)
|
|
|
|
# OVR_multiview2 is a RELEASE extension whose availability depends on the
|
|
# graphics backend. On Windows, Firefox renders WebGL through ANGLE's D3D11
|
|
# backend, which implements multiview on every D3D11 GPU: stock 152.0.4 on
|
|
# a Windows 11 host exposes it on WebGL2 (MAX_VIEWS_OVR=4, headless and headed), and the
|
|
# recorded corpus has it on 13 of the 15 Windows rows with WebGL2 (never on
|
|
# WebGL1) -- filtering it there was a leak. On Linux it depends on
|
|
# the host GL driver (stock on an NVIDIA box does not expose it), and
|
|
# ClientWebGLContext::IsSupported answers from the spoofed list without asking
|
|
# the host, so a Linux identity could advertise an extension the GPU cannot
|
|
# back; it stays filtered off Windows.
|
|
_HOST_DEPENDENT_EXTENSIONS = frozenset({'OVR_multiview2'})
|
|
|
|
|
|
def _filtered_extensions(os: str) -> frozenset:
|
|
if os == 'win':
|
|
return _NEVER_EXPOSED_EXTENSIONS
|
|
return _NEVER_EXPOSED_EXTENSIONS | _HOST_DEPENDENT_EXTENSIONS
|
|
|
|
|
|
def _load_webgl_data(data_str: str, os: str) -> Dict[str, str]:
|
|
data = orjson.loads(data_str)
|
|
blocked = _filtered_extensions(os)
|
|
for key in ('webGl:supportedExtensions', 'webGl2:supportedExtensions'):
|
|
exts = data.get(key)
|
|
if isinstance(exts, list):
|
|
data[key] = [e for e in exts if e not in blocked]
|
|
return data
|
|
|
|
|
|
def sample_webgl(
|
|
os: str, vendor: Optional[str] = None, renderer: Optional[str] = None, seed: Optional[int] = None
|
|
) -> Dict[str, str]:
|
|
"""
|
|
Sample a random WebGL vendor/renderer combination and its data based on OS probabilities.
|
|
Optionally use a specific vendor/renderer pair.
|
|
|
|
Args:
|
|
os: Operating system ('win', 'mac', or 'lin')
|
|
vendor: Optional specific vendor to use
|
|
renderer: Optional specific renderer to use (requires vendor to be set)
|
|
|
|
Returns:
|
|
Dict containing WebGL data including vendor, renderer and additional parameters
|
|
|
|
Raises:
|
|
ValueError: If invalid OS provided or no data found for OS/vendor/renderer
|
|
"""
|
|
# Check that the OS is valid (avoid SQL injection)
|
|
if os not in OS_ARCH_MATRIX:
|
|
raise ValueError(f'Invalid OS: {os}. Must be one of: win, mac, lin')
|
|
|
|
# Connect to database
|
|
conn = sqlite3.connect(DB_PATH)
|
|
cursor = conn.cursor()
|
|
|
|
if vendor and renderer:
|
|
# Get specific vendor/renderer pair and verify it exists for this OS
|
|
cursor.execute(
|
|
f'SELECT vendor, renderer, data, {os} FROM webgl_fingerprints ' # nosec
|
|
'WHERE vendor = ? AND renderer = ?',
|
|
(vendor, renderer),
|
|
)
|
|
result = cursor.fetchone()
|
|
|
|
if not result:
|
|
raise ValueError(f'No WebGL data found for vendor "{vendor}" and renderer "{renderer}"')
|
|
|
|
if result[3] <= 0: # Check OS-specific probability
|
|
# Get a list of possible (vendor, renderer) pairs for this OS
|
|
cursor.execute(
|
|
f'SELECT DISTINCT vendor, renderer FROM webgl_fingerprints WHERE {os} > 0' # nosec
|
|
)
|
|
possible_pairs = cursor.fetchall()
|
|
raise ValueError(
|
|
f'Vendor "{vendor}" and renderer "{renderer}" combination not valid for {os.title()}.\n'
|
|
f'Possible pairs: {", ".join(str(pair) for pair in possible_pairs)}'
|
|
)
|
|
|
|
conn.close()
|
|
return _load_webgl_data(result[2], os)
|
|
|
|
# Get all vendor/renderer pairs and their probabilities for this OS
|
|
cursor.execute(
|
|
f'SELECT vendor, renderer, data, {os} FROM webgl_fingerprints WHERE {os} > 0' # nosec
|
|
)
|
|
results = cursor.fetchall()
|
|
conn.close()
|
|
|
|
if not results:
|
|
raise ValueError(f'No WebGL data found for OS: {os}')
|
|
|
|
# Split into separate arrays
|
|
_, _, data_strs, probs = map(list, zip(*results))
|
|
|
|
# Convert probabilities to numpy array and normalize
|
|
probs_array = np.array(probs, dtype=np.float64)
|
|
probs_array = probs_array / probs_array.sum()
|
|
|
|
# Sample based on probabilities
|
|
# Seeded so the same identity always draws the same device (#442/#765).
|
|
idx = np.random.default_rng(seed).choice(len(probs_array), p=probs_array)
|
|
|
|
# Parse the JSON data string
|
|
return _load_webgl_data(data_strs[idx], os)
|
|
|
|
|
|
def get_possible_pairs() -> Dict[str, List[Tuple[str, str]]]:
|
|
"""
|
|
Get all possible (vendor, renderer) pairs for all OS, where the probability is greater than 0.
|
|
"""
|
|
# Connect to database
|
|
conn = sqlite3.connect(DB_PATH)
|
|
cursor = conn.cursor()
|
|
|
|
# Get all vendor/renderer pairs for each OS where probability > 0
|
|
result: Dict[str, List[Tuple[str, str]]] = {}
|
|
for os_type in OS_ARCH_MATRIX:
|
|
cursor.execute(
|
|
'SELECT DISTINCT vendor, renderer FROM webgl_fingerprints '
|
|
f'WHERE {os_type} > 0 ORDER BY {os_type} DESC', # nosec
|
|
)
|
|
result[os_type] = cursor.fetchall()
|
|
|
|
conn.close()
|
|
return result
|