---
title: "Treat messages from web pages and content · Agent Wranglers"
url: https://agentwranglers.se/playbook/desktop-apps/browser-extensions/untrusted-extension-messages
id: DSK-16
level: Recommended
updated: 2026-10-22
tokens: 777
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Treat messages from web pages and content scripts as untrusted

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Browser extensions](https://agentwranglers.se/playbook/desktop-apps/browser-extensions.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

- ID: DSK-16
- Level: Recommended
- Chapter: [Browser extensions](https://agentwranglers.se/playbook/desktop-apps/browser-extensions.md)
- Rule: Validate every message the background script receives, and check its sender before acting. Let web pages message the extension only from hosts listed under `externally_connectable`.
- Check: A test sends each message type with an unknown action, a wrong field type and a sender from an unlisted host. The background script refuses all three and changes nothing. `externally_connectable.matches` lists exact hosts with no `*://*/*`.
- How: Content scripts run inside web pages, and Chrome warns that a hostile page may compromise the process they run in. Treat a message from a content script as a request from a stranger. Check `sender.id`, `sender.origin` and the action against a fixed list. Never pass a received string to `scripting.executeScript`, `innerHTML` or `tabs.update` with a URL you did not check. Assume anything you send to a content script can leak to the page. This is the same idea as [check the sender and content of every message to the main process](https://agentwranglers.se/playbook/desktop-apps/web-code-inside-desktop-apps/validate-ipc.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JSON example

```json
{
  "externally_connectable": {
    "matches": ["https://app.example.com/*"]
  }
}
```

## Sources

- [Chrome, Message passing security considerations](https://developer.chrome.com/docs/extensions/develop/concepts/messaging)

## Related rules

- DSK-11 [Check the sender and content of every message to the main process](https://agentwranglers.se/playbook/desktop-apps/web-code-inside-desktop-apps/validate-ipc.md) in Desktop apps, extensions and CLIs

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/desktop-apps/browser-extensions/untrusted-extension-messages">Agent Wranglers desktop apps, extensions and CLIs playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Ship every line of code inside the package](https://agentwranglers.se/playbook/desktop-apps/browser-extensions/no-remote-code.md)
- Next: [Keep extension state in storage instead of the background worker](https://agentwranglers.se/playbook/desktop-apps/browser-extensions/worker-state-in-storage.md)
- [Browser extensions](https://agentwranglers.se/playbook/desktop-apps/browser-extensions.md)
