---
title: "Check the sender of every window message · Agent Wranglers"
url: https://agentwranglers.se/playbook/adversarial-testing/requests-and-files/postmessage-origin
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Check the sender of every window message

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

For AI agents: [llms.txt](https://agentwranglers.se/llms.txt) is a short guide that sends you to the rules your problem needs, and [rules.json](https://agentwranglers.se/playbook/adversarial-testing/rules.json) holds every rule of this playbook as JSON.

- Level: Recommended
- Chapter: [Requests and files](https://agentwranglers.se/playbook/adversarial-testing/requests-and-files)
- Rule: When a page listens for messages from other windows or frames, accept only those from a fixed list of origins. Never send private data to the target origin `*`.
- How: Pages use `postMessage` to talk to pop-ups, embedded widgets and login or payment frames. Any site can open your page and post to it, so compare `event.origin` with your list before reading `event.data`. Treat the data as untrusted input, and never put it into `innerHTML` or `eval`. Name the exact receiving origin when you send. Framing of your own pages is covered in [Refuse to be framed](https://agentwranglers.se/playbook/website/security/frame-ancestors).
- Check: The agent loads the page from a test page on another origin. It posts a message holding `<img src=x onerror=alert('PENTEST-7a8b')>` and one holding a fake action. The page ignores both. A search of the code finds no `postMessage` call with `'*'` as its target.

## 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.

### HTML example

```html
<script>
  const TRUSTED_ORIGINS = new Set(['https://pay.example.com']);
  window.addEventListener('message', event => {
    if (!TRUSTED_ORIGINS.has(event.origin)) return;
    showPaymentStatus(String(event.data.status));
  });
  popup.postMessage({ orderId }, 'https://pay.example.com');
</script>
```

## Sources

- [HTML Standard on web messaging security](https://html.spec.whatwg.org/multipage/web-messaging.html#authors)

## Related rules

- [Refuse to be framed](https://agentwranglers.se/playbook/website/security/frame-ancestors) in Website

**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/adversarial-testing/requests-and-files/postmessage-origin">Agent Wranglers security testing playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Keep private pages out of shared caches](https://agentwranglers.se/playbook/adversarial-testing/requests-and-files/private-responses-uncached)
- [Requests and files](https://agentwranglers.se/playbook/adversarial-testing/requests-and-files)
