Prompt Injection in AI Browsers: How It Works

Surface Security Team

Prompt injection in AI browsers turns web content into commands for agents. See how direct and indirect attacks work, where payloads hide, and defenses.

Prompt injection in an AI browser happens when text the agent reads, on a web page, in an email, or in a document, is treated as an instruction instead of as data, so the agent does what the attacker wrote rather than what the user asked. It works because the user's request and the page content land in the same model context, and the model cannot reliably tell which one is in charge.

That makes every page an AI browser opens a possible source of commands. This post explains the two forms of the attack, walks through a real one, catalogs where payloads hide, and covers defenses that do not depend on the model getting it right.

Direct and indirect prompt injection

The OWASP Top 10 for LLM Applications lists prompt injection as LLM01 and splits it in two:

  • Direct prompt injection is when "a user's prompt input directly alters the behavior of the model." The person typing is the attacker, trying to jailbreak the assistant or pull out its system prompt.
  • Indirect prompt injection is when "an LLM accepts input from external sources, such as websites or files." The attacker never talks to the model. They plant instructions where the model will read them.

For AI browsers, indirect injection is the one that matters. The user is the victim, not the attacker, and the payload arrives through content the agent was asked to read. OWASP also notes that injections "can affect the model even if they are imperceptible to humans," which is exactly why the browser is such a good delivery channel.

How an attack unfolds

Brave's research team published a clean example against Perplexity's Comet browser in August 2025:

  1. The attacker posted a Reddit comment with instructions hidden behind a spoiler tag.
  2. A user opened the thread and asked Comet to summarize the current page.
  3. Comet passed the page text, hidden instructions included, to its model along with the user's request.
  4. Following the injected steps, the agent fetched the user's email address from their Perplexity account page, requested a one-time password, opened the user's logged-in Gmail to read the code, and posted both as a reply to the comment.

No malware ran and no exploit fired. The agent used the user's own sessions, exactly as designed, on the attacker's behalf. Brave also reported that Perplexity's first fix was incomplete when they retested it.

Where attackers hide instructions

CSS-hidden text

White text on a white background, tiny fonts, text positioned off-screen, or content collapsed behind a spoiler. The agent reads the DOM or extracted text, so styling that hides content from a person does nothing to hide it from the model.

HTML comments and attributes

Comments and attribute values such as alt text never render as page text, but they can survive whatever extraction feeds the model.

Invisible Unicode

The Unicode Tags block mirrors ASCII but is usually not rendered, so text encoded with it is invisible to people while models still interpret it. Johann Rehberger demonstrated this in January 2024 and recommended that LLM applications filter Tag code points out of prompts and responses. Zero-width characters can be abused in a similar way.

Text in images and screenshots

In October 2025 Brave showed that faint light blue text on a yellow background, easy for a person to miss, was extracted when a Comet user asked the assistant about a screenshot of the page, then passed to the model alongside the user's question.

Plain visible text

Hiding is optional. In the same research, Brave showed that the Fellou browser could be steered by visible instructions on an attacker's page when the user simply asked the assistant to navigate there. If the agent reads it, it can become an instruction.

Why the browser is the right place to catch it

The model vendors are working hard on this, and their own results show why other layers still matter. Anthropic reported that new mitigations for Claude for Chrome cut attack success on a set of browser-specific attacks from 35.7% to 0%, while its broader autonomous-mode rate still sat at 11.2%. OpenAI writes that prompt injection "is unlikely to ever be fully 'solved'."

The browser has three advantages over the network or the model:

  • It sees the page as delivered. Styling, comments, and invisible characters are all still in the DOM before text extraction flattens them.
  • It can act before the model reads. Hidden content can be removed from the page before the agent processes it, instead of turning up in a log afterward.
  • It sees where actions go. Origins, form targets, and outbound requests are visible at the moment the agent uses them, so a hijacked agent can be caught when it tries to send data or a credential somewhere new.

Defenses that work together

No single control stops prompt injection. Layer them:

  • Sanitize hidden content before the agent reads the page.
  • Treat page content as untrusted. Brave and OWASP both recommend keeping the user's instructions clearly separated from external content.
  • Limit what the agent can reach. Least privilege, a separate browser profile, and only the sessions the task needs. OpenAI recommends logged-out mode where the task allows it.
  • Allowlist destinations so exfiltration attempts stand out.
  • Pin credentials to origins so a hijacked agent cannot hand a password to the wrong site. More in Credential and Autofill Guardrails for AI Agents.
  • Require human approval for sending, purchasing, publishing, or deleting.
  • Test adversarially. OWASP recommends regular attack simulations that treat the model as an untrusted user.

For the wider risk picture beyond injection, see Agentic Browser Security: Risks and Controls.

How Surface catches prompt injection

For agents running with Surface on Playwright, Puppeteer, Selenium, Browser Use, Stagehand, or a custom framework, prompt injection is detected and sanitized, including hidden CSS text, Unicode steganography, and HTML comments. Domain allowlists raise exfiltration and domain-violation alerts, credentials are origin-locked by default, and agent traffic carries a watermark header so each event ties back to the agent that triggered it.

The framework setup is covered in Agentic AI Security: Protecting Your AI-Powered Browser Agents, and the product view is on the agentic AI technology page. If people in your company are installing AI browsers on their own, that is a shadow AI problem as well.