Skip to content

fix(web-ui): verify message source before applying widget updates (light-tested) - #2612

Open
1688mengdie wants to merge 1 commit into
GCWing:mainfrom
BitFun-SIG:fix/security-widget-postmessage-source
Open

fix(web-ui): verify message source before applying widget updates (light-tested)#2612
1688mengdie wants to merge 1 commit into
GCWing:mainfrom
BitFun-SIG:fix/security-widget-postmessage-source

Conversation

@1688mengdie

Copy link
Copy Markdown

Summary

The generative widget iframe shell listened for message events without
checking where they came from. Any window able to postMessage into the
host page could forge a bitfun-widget:update event and have arbitrary
attacker-controlled HTML applied inside the widget document via
setContent.

This PR rejects every message whose source is not the direct parent
window before any data processing, mirroring the source check already
applied to the iframe-to-parent direction. An anti-injection test
asserts the gate sits ahead of setContent in the widget shell.

Fixes #2603

Type and Areas

Type: security fix

Areas: Web UI

Verification

  • pnpm --dir src/web-ui run type-check — passed (0 errors).
  • pnpm --dir src/web-ui run lint — passed (0 errors).
  • vitest run GenerativeWidgetFrame.test.tsx — 3 passed (including the new anti-injection case; the two pre-existing cases are untouched).

Reviewer Notes

  • The guard is a one-line source check at the top of the message listener, covering the data path and the clear-selection branch alike; behavior for legitimate parent-originated updates is unchanged.
  • No new dependencies and no API changes.
  • Rollback is a revert of the one-line guard plus the appended test case.

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable. (Not applicable: no user-facing change.)

This is an AI-assisted change.

The generative widget iframe shell listened for `message` events without
checking where they came from. Any window able to postMessage into the
host page could forge a `bitfun-widget:update` event and have arbitrary
HTML applied inside the widget via setContent.

Reject every message whose source is not the direct parent window before
any data processing, mirroring the source check already applied to the
iframe-to-parent direction. Cover the guard with an anti-injection test
asserting the gate sits ahead of setContent in the widget shell.

Test: pnpm --dir src/web-ui run type-check; pnpm --dir src/web-ui run lint;
vitest run GenerativeWidgetFrame.test.tsx (3 passed).
AI: AI-assisted, locally tested (type-check + lint + targeted vitest).
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.

[Security]: generative widget accepts postMessage updates from any window (HTML injection via forged bitfun-widget:update)

1 participant