fix(web-ui): verify message source before applying widget updates (light-tested) - #2612
Open
1688mengdie wants to merge 1 commit into
Open
fix(web-ui): verify message source before applying widget updates (light-tested)#26121688mengdie wants to merge 1 commit into
1688mengdie wants to merge 1 commit into
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The generative widget iframe shell listened for
messageevents withoutchecking where they came from. Any window able to postMessage into the
host page could forge a
bitfun-widget:updateevent and have arbitraryattacker-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
setContentin 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
Checklist
This is an AI-assisted change.