Allowing an agent to write userscripts is equivalent to letting it run JavaScript on any site you visit. The design therefore assumes the agent is useful but not fully trusted, and that other local software and web pages are hostile.
| Threat | Mitigation |
|---|---|
A web page links to mcp_connect.html?port=…&token=… pointing at an attacker's server, to make the extension talk to it |
The extension never connects automatically. It shows an authorization page with the host and port, and requires a user click. Only loopback hosts are allowed by default. |
| A web page connects to the local server from JavaScript | The server checks the Origin header on the WebSocket upgrade and only accepts browser extension schemes. A valid token is also required. |
| Another local process connects | It needs the token, which is random (256 bits), delivered only to the agent via vm_status/stderr, and never sent over the WebSocket: the client proves knowledge of it with an HMAC over fresh nonces, checked in constant time. |
| Another local process binds the port first (before the server starts, or after it crashes while the extension is reconnecting) and impersonates the server | The server must prove it knows the token or pairing key (HMAC over both nonces, with a direction label) before the client sends anything else. Without that proof the client closes with 4006 and stops, without sending a proof or key and without registering tools, so the impostor cannot call scripts_write or replay anything. Proofs carry a server/client label so one side's proof cannot be reflected as the other's. An impostor can still make the client stop (denial of service). |
A weak user-chosen --token is guessed offline from one observed HMAC proof |
Only the first pair uses the token. Later reconnects use the pairing key K, which is always 256 random bits generated by the extension, so remembering a server never relies on the token's strength. A random token is still the default. |
| The pairing file is read by another user | --pair-file is opt-in, has no default path, and is written atomically with mode 0600. It holds K (as JSON: { "version": 1, "key": "<K>" }), which lets its reader act as the extension towards this server; protect it like an SSH key. |
| A Violentmonkey version without protocol 2 connects | The server still accepts protocol 1 for now, which sends the token in hello and does not authenticate the server. Such extensions get no protection against port squatting until they update; protocol 1 will be removed in a later release. |
| An unauthenticated peer uses the version-mismatch report to inject text into the agent's context | lastError is composed by the server; the peer contributes only its integer protocol number. |
| A local process relays a live handshake between the extension and the real server | Not prevented: a relay needs the real server to be reachable at the same time on another address, and plain loopback WebSocket has no channel binding. Keep the default 127.0.0.1 bind. |
| DNS rebinding against the HTTP endpoints | The server validates the Host header (127.0.0.1, localhost, [::1], or the configured --host) and rejects others. |
| Token leakage in logs | The token never travels over the WebSocket in protocol 2, and is in the hello frame (not the URL) in protocol 1. The connect URL (which includes the token) is only printed to stderr and returned by vm_status. |
| Extension injecting prompt-injection payloads as tool descriptions | Tools and descriptions are defined by the server package. |
| Script content returned to the agent contains prompt injection | Cannot be fully prevented. Tool results are plain data; agents should treat them as untrusted. |
| Agent overwrites or deletes scripts unexpectedly | Destructive tools carry MCP annotations so clients can prompt. The extension should offer a read-only mode and optional confirmation for writes (error 403 when denied). |
| The agent reads pages the user did not intend to expose | Tab tools work only on tabs the user granted explicitly. Grants live in extension memory and are revoked when the tab closes, so a recycled tab id cannot inherit one. Log capture is limited to GM_log, so ambient console output and page content are never forwarded. |
| Remote access via the HTTP transport | /mcp requires Authorization: Bearer <token>. Default bind is loopback. Binding to non-loopback hosts prints a warning; TLS must be provided by the user (e.g. a reverse proxy). |
- Bind address:
127.0.0.1. - Token: random per start, unless
--token/VM_MCP_TOKENis set. - Pairing key: generated by the extension when it pairs and kept in server memory, so a restarted server needs a new approval. With
--pair-file <path>it is stored in that file (mode 0600); the server writes nowhere else. - HTTP transport: off.
- Read-only mode (
--readonly): off. When on, write tools are not exposed to the agent, and the server refuses to accept them from the extension. - Tab grants: none. The agent cannot see or act on any tab until the user grants one.
- Single extension connection; a new connection must authenticate with the token or the current pairing key to replace the existing one. A new pair replaces the stored pairing key.
- Display the server address and the list of requested tools on the authorization page.
- Never persist the connect token. After pairing, store
{ port, pairingKey }across browser restarts when the server reportedpersistent: trueinchallenge, and keep it in memory only otherwise. Keep one pairing per port. - When the connect URL has
persistent=1, say on the approval page that the connection will be remembered until revoked. The parameter is only a display hint: anyone can write a URL, so base behavior onchallenge.persistent. - List remembered servers and let the user revoke each one (drop the pairing key and close with
4002). Deleting the server's pair file also revokes it: the next resume fails with4005. - On
4005(pairing invalid) while resuming, drop the stored pairing key and ask the user to approve again. On4006(server not authenticated), stop but keep the key, so an impostor on the port cannot unpair the extension. Never fall back to sending the token automatically. - Provide a visible "connected" indicator and a one-click disconnect (close code
4002). - Offer its own read-only setting that rejects
scripts_write,scripts_set_enabledandscripts_deletewith403, in addition to the server's--readonlyflag. - Hold tab grants in memory only, revoke them when the tab closes, and show which tabs are granted while connected.
- Capture nothing but
GM_log. Do not forward console output, page content or network activity to the server.