Skip to content

test(chat-client): add postMessage origin check regression tests#2783

Open
laileni-aws wants to merge 1 commit into
aws:mainfrom
laileni-aws:feat/postmessage-origin-check-tests
Open

test(chat-client): add postMessage origin check regression tests#2783
laileni-aws wants to merge 1 commit into
aws:mainfrom
laileni-aws:feat/postmessage-origin-check-tests

Conversation

@laileni-aws

Copy link
Copy Markdown
Contributor

Summary

Adds comprehensive regression tests for the same-origin guard in handleInboundMessage (P389799154) to prevent the XSS mitigation from silently regressing.

New tests (15 total)

Rejects foreign-origin messages across command types

  • CHAT_REQUEST_METHOD, SEND_TO_PROMPT, ERROR_MESSAGE, GENERIC_COMMAND, CHAT_OPTIONS, OPEN_TAB_REQUEST_METHOD — all verified to only produce rejection telemetry, not command-handler output.

Rejects messages from various untrusted origins

  • https://attacker.example.com, http://evil.localhost, https://phishing.internal.corp

Same-origin messages are processed normally

  • Verifies SEND_TO_PROMPT, CHAT_REQUEST_METHOD, and OPEN_TAB_REQUEST_METHOD still work from same-origin.

Rejection is observable without throwing

  • console.warn fires with the untrusted origin string
  • No exception is thrown (graceful early return)
  • No warning is logged for same-origin traffic

Audit results

Only one window.addEventListener('message', ...) exists in chat-client/src — the one in chat.ts. No unguarded message sinks found.

Testing

228 passing (39s)
1 pending

Add comprehensive regression tests for the same-origin guard in
handleInboundMessage (P389799154). Tests assert:

- Foreign-origin messages are rejected across 6 command types
- Multiple untrusted origins are blocked
- Same-origin messages continue to process normally
- Rejection logs console.warn without throwing

This prevents the XSS mitigation from silently regressing.
@laileni-aws
laileni-aws requested a review from a team as a code owner July 14, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant