Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions app/dataplane/proxy/adapters/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


from app.platform.logging.logger import logger
from app.platform.config.snapshot import get_config
from app.control.proxy.models import ProxyLease
from app.dataplane.proxy.adapters.profile import ProxyProfile, resolve_proxy_profile

Expand Down Expand Up @@ -64,24 +65,19 @@ def _sanitize(value: Optional[str], *, field: str, strip_spaces: bool = False) -


def _statsig_id() -> str:
"""Generate a Statsig evaluation fallback ID.

The real browser's fetch interceptor tries to evaluate Statsig gates for
each request. When the Statsig SDK is not yet initialised (headless,
first paint, etc.) it catches the error and falls back to::

btoa("x1:" + error.toString())

The server accepts this fallback. We reproduce the exact format with
varied error messages to avoid a static fingerprint.
"""
if random.choice((True, False)):
rand = "".join(random.choices(string.ascii_lowercase + string.digits, k=5))
msg = f"x1:TypeError: Cannot read properties of null (reading 'children[\\'{rand}\\']')"
else:
rand = "".join(random.choices(string.ascii_lowercase, k=10))
msg = f"x1:TypeError: Cannot read properties of undefined (reading '{rand}')"
return base64.b64encode(msg.encode()).decode()
cfg = get_config()
if cfg.get_bool("features.dynamic_statsig", False):
if random.choice((True, False)):
rand = "".join(random.choices(string.ascii_lowercase + string.digits, k=5))
msg = f"x1:TypeError: Cannot read properties of null (reading 'children['{rand}']')"
else:
rand = "".join(random.choices(string.ascii_lowercase, k=10))
msg = f"x1:TypeError: Cannot read properties of undefined (reading '{rand}')"
return base64.b64encode(msg.encode()).decode()
return (
"ZTpUeXBlRXJyb3I6IENhbm5vdCByZWFkIHByb3BlcnRpZXMgb2YgdW5kZWZpbmVkIChyZWFkaW5nICdjaGls"
"ZE5vZGVzJyk="
)


# ---------------------------------------------------------------------------
Expand Down