# LX AI v2.2 — Security & data flow

Browser `lx-ai.js` → same-origin POST `/api/lx/chat` → Pages advanced Worker `_worker.js` → opt-in Workers AI binding `env.AI`.

- OFF by default, requires binding and `LX_AI_ENABLED=true`.
- Uses at most 700 characters of user input, 6 bounded historic messages; context and current prompt processed by Workers AI. Chat is in page memory only.
- On-chain tools execute only allowlisted RPC methods via canonical Base Sepolia upstreams, never arbitrary model-supplied requests. NCLX contract pinned to testnet address.
- `transfer`, `approve`, `personal_sign`, `eth_sendTransaction`, and arbitrary RPC methods not supported by LX AI.
- `same-origin` and `Content-Type` enforced for chat requests; security headers and CSP preserved.
- 5 requests/minute and 30 requests/day per IP **per Worker isolate only**, not a global quota. Configure Cloudflare WAF Rate Limiting and budget safeguards *before* allowing public traffic.
- Read-only chain queries have no authentication; transaction hashes and wallet addresses are public and may be sent to AI when typed into chat.
- Response is rendered via `textContent`, not HTML; model output cannot inject scripts via the chat UI.
- Hardcoded official deployment origin prevents chat requests from preview domains; updating to a new authorized domain requires explicit code review.
- No mainnet writes or token trading. MetaMask malicious-site warning unresolved. Not a security audit.

## v2.2.1 — Turnstile
- Public site key in `lx-ai.js`; private `TURNSTILE_SECRET` held only in Cloudflare.
- Every `/api/lx/chat` POST demands Siteverify `success:true` + hostname `noclipx-project.pages.dev` + action `lx_chat`. Token only usable once and expires in 5 min.
- CSP allows Cloudflare's Turnstile script/iframe and network origin; all other policies unchanged.
- The isolate-local counters are NOT a durable global quota. A stricter cloud-side rate limit and budget controls are necessary to limit resource expenses. 
- No permission to connect wallets or sign transactions.
