[Security]: generative widget accepts postMessage updates from any window (HTML injection via forged bitfun-widget:update)
- Dominant language
- Rust
- Stars
- 2.2k
- Forks
- 229
- Avg merge
- 2h 46m
- Merged PRs (30d)
- 577
Description
Summary: The generative widget iframe shell processes `message` events without verifying the sender. Any window that can postMessage into the host page can forge a `bitfun-widget:update` event, causing arbitrary attacker-controlled HTML to be written into the widget document via `setContent`.
Area: Web UI
Reproduction or evidence: `src/web-ui/src/tools/generative-widget/GenerativeWidgetFrame.tsx:862` registers `window.addEventListener('message', ...)` whose handler reads `event.data` and, for `type === 'bitfun-widget:update'`, calls `setContent(String(data.html || ''), Boolean(data.runScripts))` with no `event.source` check — while the reverse (iframe→parent) direction already validates `event.source` against the iframe content window (:921/:922).
Environment: BitFun version/commit 32f2427697ee16f253ee6119860a03255c0b3e47 (origin/main).
Contributor guide
Research direction
Start in src/web-ui/src/tools/generative-widget/GenerativeWidgetFrame.tsx around lines 862 and 921-922. Compare the incoming message handler with the existing iframe-to-parent source validation, then verify that updates from unrelated windows cannot reach setContent while valid widget updates still work. Done means forged bitfun-widget:update messages no longer control the widget HTML.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend, security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100