WebInject: Prompt Injection Attack to Web Agents

Xilong Wang, John Bloch, Zedian Shao, Yuepeng Hu, Shuyan Zhou, Neil Zhenqiang Gong

TL;DR

This paper introduces WebInject, a novel prompt injection attack that manipulates web agents by subtly altering webpage pixel values. By optimizing these pixel perturbations, WebInject effectively tricks web agents into performing attacker-specified actions, achieving significantly higher success rates than existing methods while remaining imperceptible to users.

What Problem Does This Paper Address?

Modern web agents, powered by Large Language Models (LLMs), interact with webpages by interpreting screenshots and generating actions. While powerful, these agents are vulnerable to prompt injection attacks, where an adversary tricks the agent into performing unintended actions. Existing attacks fall into two categories: webpage-based (modifying HTML, often heuristic and detectable) and screenshot-based (adding visual noise, impractical as attackers lack direct screenshot access). A key challenge for webpage-based attacks is the non-differentiable nature of the webpage-to-screenshot mapping, making it difficult to optimize perturbations that are effective across different user monitors and stealthy. This paper addresses the need for a practical, effective, and stealthy prompt injection attack that overcomes these limitations.

Methods

The core of WebInject is an optimization-based approach to find pixel perturbations that mislead web agents. The authors formulate this as an optimization problem aiming to maximize the probability of the agent performing a target action (effectiveness) while keeping the perturbation imperceptible (stealthiness).

Key methodological innovations include:

  • Webpage-to-Screenshot Mapping Approximation: To handle the non-differentiable webpage-to-screenshot mapping, they train a neural network (U-Net architecture) to approximate this process for each target monitor.
  • Differentiable Resizing: They replace the non-differentiable resizing operation used by LLMs with a differentiable alternative, allowing gradients to flow during optimization.
  • Projected Gradient Descent (PGD): With the above modifications, they use PGD to solve the reformulated optimization problem and find the optimal perturbation.
  • Universal Perturbation: The perturbation is constrained to lie within the overlapping region of various target monitors, ensuring it's visible and effective across a range of display configurations.
  • Implementation via Source Code Modification: The optimized perturbation is then implemented by injecting code into the webpage's source, which directly modifies the raw pixel values before they are rendered as a screenshot. This makes the attack practical and stealthy.

Datasets

The authors created datasets for training and evaluation:

  • Webpage Datasets: They collected real webpages across five categories (blog, commerce, education, healthcare, portfolio) using the SingleFile extension. They also generated synthetic webpages for each category using GPT-4-Turbo. This resulted in ten datasets in total.
  • Target Prompts: For each webpage, they generated 10 target prompts using GPT-4-Turbo, designed to elicit specific actions from the web agent.
  • Shadow and User Histories: They used shadow histories for optimization and user histories for evaluation, both consisting of randomly sampled action sequences.

Key Insights and Ideas

  • The Webpage-to-Screenshot Mapping is Crucial: The paper highlights that ignoring this mapping is a significant flaw in prior webpage-based attacks, leading to suboptimal effectiveness. WebInject's success hinges on accurately modeling and approximating this process.
  • Optimization is Key to Effectiveness and Stealth: Unlike heuristic-based attacks, WebInject's optimization-driven approach directly maximizes the likelihood of the target action while simultaneously enforcing stealth constraints, leading to superior performance.
  • Universal Perturbations are Practical: Crafting a single perturbation that works across multiple monitor types is a significant advantage, making the attack more broadly applicable and easier to deploy.
  • Subtle Pixel Changes are Powerful: The attack demonstrates that even minor, imperceptible pixel alterations can profoundly influence the behavior of sophisticated LLM-based web agents.

Key Results

WebInject significantly outperforms existing attacks across various LLMs and datasets.

  • High Success Rates: For the Gemma-3 agent, WebInject achieved an Attack Success Rate (ASR) of 0.972, compared to 0.062 for the best webpage-based baseline and 0.000 for screenshot-based attacks. Similar high ASRs (around 0.95-0.99) were observed across other LLMs and datasets.
  • Robustness to Monitor Variations: The ASR slightly decreases as the number of target monitors increases, but remains very high, demonstrating robustness.
  • Stealthiness Achieved: The attack remains stealthy, with the perturbation bound $\epsilon$ set to values generally considered imperceptible. As $\epsilon$ increases, ASR rises, indicating a trade-off that can be managed to maintain stealth.
  • Effectiveness with Semantically Equivalent Prompts: WebInject maintains comparable ASR even when user prompts are semantically similar but not identical to the target prompts used for optimization.

Limitations and Future Work

  • Attacker Capability Assumption: The attack assumes the attacker can modify the source code of target webpages, which might not be feasible for highly trustworthy sites.
  • Closed-Source LLMs: Transferability to closed-source LLMs was not evaluated due to computational constraints.
  • Potential Defenses: The authors suggest defenses like analyzing webpage source code for injected snippets, detecting screenshot perturbations, and fine-tuning LLMs with adversarial training. They note that existing prompt-injection detection methods that rely on explicit textual prompts are not applicable to WebInject.
  • Future Work: Exploring transferability to closed-source LLMs and developing robust defenses are suggested future research directions.

Summary updated

BibTeX
@inproceedings{wang2025webinject,
  author = {Xilong Wang and John Bloch and Zedian Shao and Yuepeng Hu and Shuyan Zhou and Neil Zhenqiang Gong},
  title = {{WebInject: Prompt Injection Attack to Web Agents}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure