Commit 5e8fb6e
fix(security): origin check on service-worker message handler (CodeQL js/missing-origin-check) (#208)
The PWA service worker's `message` handler (the `dar:purge`
cache-on-logout hook, #200) processed messages without verifying the
sender origin — CodeQL `js/missing-origin-check` (medium). A
cross-origin frame must never be able to drive the SW cache.
Add `if (event.origin && event.origin !== self.location.origin)
return;` so only same-origin clients (the SPA pages this worker
controls) can trigger a purge. Same-origin internal
`client.postMessage` (empty origin) is still accepted; anything
cross-origin is dropped.
This is the one open CodeQL alert on main (the other 10 are fixed
via #191/#193). Clears it → 0 open. Test asserts the served SW
embeds the origin check.
Co-authored-by: Martin Castro Laminrs <mcastro@laminr.ai>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent e19931f commit 5e8fb6e
2 files changed
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
49 | 58 | | |
50 | 59 | | |
51 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
124 | 127 | | |
125 | 128 | | |
126 | 129 | | |
| |||
0 commit comments