# Prompt injection from web pages: treat fetched text as data

Text an agent fetches from a web page arrives in the same place as its instructions. One practice page fetched as markdown in a dated run, then shown inside a wrapper that marks it as data, and the limits your code should hold.

Canonical: https://spider.cloud/learn/untrusted-page-text/

Prompt injection from a web page happens when an agent fetches a page and treats a sentence on it as an instruction. The page's text and your own instructions reach the model as the same kind of thing, plain text, so the model has no built-in way to tell who wrote which.

The defence is a habit more than a filter. Fetched text is data. Your agent reports it, quotes it and reasons about it, and never takes orders from it.

## Why a page can do this

OWASP, which keeps the best-known list of risks for applications built on language models, puts this one first. Its definition: "Indirect prompt injections occur when an LLM accepts input from external sources, such as websites or files."

Any agent that does [web scraping](/web-scraping/) on its own accepts exactly that input. A person visiting a page sees its layout and knows the site is speaking. A model receives one long string in which your instructions, the user's question and the page all sit together. If the page includes a line addressed to the reader, the model may act on it.

It need not be an attack. OWASP notes that these injections "can be either intentional or unintentional". A page that tells its readers to skip a section because it is out of date is talking to people, and a model can still take that as a direction.

## The run: what a fetched page looks like to a model

[Quotes to Scrape](https://quotes.toscrape.com/) is a practice site, and nothing on it is hostile. It is here to show the shape of what arrives. The request went to the Spider API on 2026-11-23 at 02:02 UTC, and this is the body as sent. `KEY` stands for an API key.

```bash
curl -s https://api.spider.cloud/scrape \
  -H "Authorization: Bearer KEY" -H "Content-Type: application/json" \
  -d '{"url": "https://quotes.toscrape.com/", "request": "http", "return_format": "markdown", "user_agent": "examplebot/1.0 (+https://example.com/bot; bot@example.com)"}'
```

It came back on 2026-11-23 with status 200. These are the status and the first six lines of the markdown. The site sets its quotations in curly quotation marks, shown here as straight ones:

```text
status 200, first six lines of the markdown
Quotes to Scrape
#
[Quotes to Scrape](https://quotes.toscrape.com/)
[Login](https://quotes.toscrape.com/login)
"The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking."
by Albert Einstein
```

Look at the fifth line as a model would. It is a full sentence that makes a claim, and nothing in the text marks it as a quotation from a page. Here it is harmless. The point is that a line on a page reaches the model as fluent prose, with the same weight as a line you wrote.

## Mark the text as data

The first step is to hand the page over inside a wrapper that says what it is and where it came from. This is the same six lines as a careful tool would pass them on:

```text
<fetched_page url="https://quotes.toscrape.com/" fetched="2026-11-23T02:02Z" trust="none">
Quotes to Scrape
#
[Quotes to Scrape](https://quotes.toscrape.com/)
[Login](https://quotes.toscrape.com/login)
"The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking."
by Albert Einstein
</fetched_page>
```

Your own instructions then say, once and outside the wrapper, that anything inside a `fetched_page` block is material to read and report, and that no text inside one changes the task.

The wrapper gives the model a boundary it can refer to, and gives you the address and time for every piece of text, which you need anyway to cite a source. It is not a guarantee. A model can still be talked round, so the wrapper lowers the odds and the limits below do the rest.

## Limits the model cannot change

What protects you is what the agent is able to do, and that lives in your code.

- **Keep secrets out of reach.** An agent that reads the web should not also hold keys, private files or a logged-in session it does not need. Anthropic's documentation for its fetch tool gives the reason: "Enabling the web fetch tool in environments where Claude processes untrusted input alongside sensitive data poses data exfiltration risks."
- **Decide in code which addresses it may fetch.** The model proposes an address, and your code checks it against the hosts the task needs before any request goes out. A page should not be able to send the agent somewhere new.
- **Ask a person before anything that cannot be undone.** Reading is cheap to get wrong. Sending a message, buying something or deleting a file is not.
- **Cap what one page can cost.** Set a page limit, a size limit and a [request rate](/learn/request-rate/) for each host, so a page that sends the agent in circles runs out of budget.

A page built to hold [structured data](/learn/structured-data/) is easier to handle safely, because your code can pull the fields out and pass only those on. Free text is where the risk is.

## The site's side of it

Treating a page as untrusted does not make the site an opponent. Almost every page your agent reads was written for people, by someone who has never thought about models. The site's robots.txt and terms still say what you may fetch, and its text is still the site's own, under copyright, however you wrap it.

If you publish a site, the same idea applies in reverse. Keep text meant for a model in a file made for it, such as [llms.txt](/learn/llms-txt/), and do not hide directions in a page.

## Do this, avoid this

### Do this

- Wrap every fetched page with its address and fetch time, and say in your instructions that wrapped text is data.
- Check each address the model wants against an allowed list in your code.
- Keep keys, sessions and private files away from an agent that reads the open web.
- Have a person approve any action that cannot be undone.

### Avoid this

- Pasting fetched text straight after your own instructions with nothing to mark where it starts.
- Relying on the wrapper alone. It lowers the odds and proves nothing.
- Letting a page choose the next address the agent fetches without a check.
- Giving one agent both open web access and access to private data.

## Test your own agent

Fetch a page you control through your agent and read exactly what the model receives. If you cannot tell at a glance where your instructions end and the page begins, neither can the model.

## Sources

1. [OWASP Gen AI Security Project, LLM01:2025 Prompt Injection](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) Read November 23, 2026
2. [Claude API documentation, Web fetch tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool) Read November 23, 2026
