fix(web): validate kind on service-worker postMessage#431
Merged
Conversation
`navigator.serviceWorker.onmessage` previously accepted any payload
and stashed it on `window.__willowLastPush` — readable by any script
on the page and triggered the in-app Notifier without a kind check.
New `service_worker_bridge` module gates payloads on
`kind in {willow-push, willow-notification-click}` (constants shared
with the reader) and stores the result in a thread-local
`RefCell<Option<PushPayload>>` instead of a window property. The
global `__willowLastPush` write is removed entirely; web is a
single-page app with no other reader to keep compatible.
Closes #244
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.
Why
navigator.serviceWorker.onmessageaccepted whateverev.datait got. payload landed onwindow.__willowLastPush— readable by any script in the page. nokindcheck before dispatching the in-app Notifier. defense-in-depth gap (SEC-W-06).Fix
new
service_worker_bridgemodule owns the SW boundary:kind in {willow-push, willow-notification-click}— anything else dropped silently. constants shared between writer (install) + reader (app.rs) so both ends agree in one place.thread_local! RefCell<Option<PushPayload>>(CLAUDE.md WASM single-thread rule), not onwindow.__willowLastPushwrite removed entirely — web is single-page, no second reader to keep alive.validate_payload+store_and_dispatchsplit out so browser tests can drive the post-validation path without faking aServiceWorker(unavailable under wasm-pack).Verify
cargo fmt --checkcargo clippy --workspace --all-targets -- -D warningscargo check -p willow-web --target wasm32-unknown-unknowncargo test -p willow-web --libwillow-pushevent + drains slotCloses #244
Generated by Claude Code