Datasets:

ArXiv:
File size: 2,473 Bytes
c72a741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Browser integration check — NO LLM required.

Launches a real browser via browser-use, loads the probe page with a session_id,
clicks the First National card, fills+submits the summary box, then verifies the
attacker event log recorded the behaviour. This validates the entire
browser -> server -> telemetry -> event-log loop independently of any LLM.

Requires the attacker server running on its port (scripts/serve.sh).

Usage: uv run python scripts/browser_check.py
"""
from __future__ import annotations

import asyncio
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from browser_use import BrowserProfile, BrowserSession

from attacker.db import events_for_session
from orchestrator.config import ATTACKER_BASE_URL

SESSION_ID = "browser-check-1"


async def main() -> int:
    profile = BrowserProfile(
        headless=True,
        args=["--host-resolver-rules=MAP *.test 127.0.0.1"],
    )
    session = BrowserSession(browser_profile=profile)
    await session.start()
    try:
        url = f"{ATTACKER_BASE_URL}/finance?session_id={SESSION_ID}&variant=A"
        await session.navigate_to(url)
        await asyncio.sleep(1.0)

        cdp = await session.get_or_create_cdp_session()
        # Click the First National card and submit the summary via JS (deterministic,
        # no LLM): this exercises the same telemetry path a real agent would trigger.
        js = """
        (function(){
          document.querySelector('[data-probe="card_first_national"]').click();
          var t = document.querySelector('[data-probe="summary_box"]');
          t.focus(); t.value = "I have a checking account with First National Bank";
          document.querySelector('[data-probe="summary_submit"]').click();
          return "ok";
        })();
        """
        await cdp.cdp_client.send.Runtime.evaluate(
            params={"expression": js}, session_id=cdp.session_id
        )
        await asyncio.sleep(1.5)  # let beacons + form POST land
    finally:
        await session.kill()

    rows = events_for_session(SESSION_ID)
    types = [r["event_type"] for r in rows]
    print(f"Recorded {len(rows)} events for {SESSION_ID}: {types}")
    ok = "pageview" in types and ("click" in types or "summary_submit" in types)
    print("BROWSER LOOP OK" if ok else "FAILED — expected pageview + click/summary")
    return 0 if ok else 1


if __name__ == "__main__":
    sys.exit(asyncio.run(main()))