Attack lab: this page is a hostile site
The AI router lets any site use your model account without ever seeing your API key. The tricky bit is that the host site sits right in the middle the whole time: it embeds the router's iframe and opens the router's popup window. So what can a hostile site actually try from that position?
This page plays the attacker. It embeds the real router and tries to break it. Every attack below runs live in your browser when you press its button, with the exact attack code shown right beside it. Everything this page manages to intercept is logged at the bottom so you can inspect the raw messages yourself.
Before you start
- Add an account at the router first. A dummy key like
sk-made-up-0000works fine — keys are only checked when a prompt reaches a provider, and most of these attacks don't send one. - Several attacks will open the router popup. Pick an account and click Allow just as you would for a site you trust, with a limit of 5 requests.
- This page hooked message listeners before the router's script even loaded. It records every message sent to its window, every
MessagePortit touches, and every message crossing those ports.
You're safe to try this with a real key — proving that is the whole point of the page — though since it's an experiment, use a key you don't mind rotating.
The attacks
A green tick means the router held and the attack failed. A red cross means the attacker got something it shouldn't have. Run them in any order.
1. Reach into the iframe
The router's iframe lives inside this page, and the encrypted key sits in its storage. Try to read its DOM, hook its listeners, or tamper with its state.
2. Relay between the window and the iframe
The popup window and the iframe have to talk, and this page sits between them. Hand each one a port we created, forward their messages across, and read everything that passes through.
3. Plant decoy iframes
The popup finds the router iframe by looping over every frame in this page. Inject our own decoy iframes ahead of the real one and try to catch the key channel.
4. Spoof the router window
Send the router window's protocol messages straight to the iframe with a forged grant we wrote: any model, 100,000 requests, valid for a year.
5. Reach into the popup window
Because this page called
window.open(), it holds a handle to the popup. Try reading your accounts out of it, and tell it this page is your bank.6. Bypass the request limit
There's no server tracking usage — the request counter lives in your browser. Try clearing storage, spinning up a second router iframe, and firing parallel requests through both at once.
7. Borrow a trusted origin's reputation
Embed a site you trust inside an iframe on this page, and trigger the router from inside it so you approve the grant under the trusted site's name.
8. Open a look-alike popup
Skip attacking the browser's security model altogether. Open a popup styled to look just like the router window and ask you to paste your API key.
Everything this page intercepted
This is every message this page has received since loading — on its window, on ports it created, and on any port handed to it. Whenever new traffic arrives, the log is scanned for anything exchanged between the router window and iframe, or anything shaped like an API key.
Nothing collected yet.
Nothing yet.
Prompts and answers do show up here, because this page sent those prompts itself. What you won't find is your API key, the encrypted key blob, or a single message from the handshake between the router window and iframe.
Why the attacks fail
- The browser blocks cross-origin reads. A page can't inspect an iframe or popup from another origin — the browser throws a
SecurityErrorimmediately. targetOriginscopes where messages go. The router window posts the key port targeting only the router's origin. Decoy iframes on any other origin never receive the message.event.originis stamped by the browser. This page can post forged router messages at the iframe, but they arrive stamped with this page's origin, so the iframe ignores them.- A
MessagePortcan't be copied. The window creates the channel, keeps one end, and transfers the other directly into the router iframe. This page never holds either end. - The counter lives in partitioned router storage. It's stored in the router iframe's storage bucket for this site, so clearing this page's storage doesn't touch it.
The one attack that works is the look-alike popup. No browser API stops a hostile site from opening a popup styled to look like the router. Only the address bar tells you which origin you're actually on, which is why the real router popup never asks for an API key.
For the full threat model, read Security: assuming the host page is hostile. These same attacks run automatically in test/hostile.mjs, and this page is tested end-to-end in test/attacks.mjs.