Bezpieczeństwo
security/postmessage-origin
postMessage names an exact target origin, and every window message listener checks event.origin against an allowlist.
poważnastatycznefe-security
Dlaczego
With "*", a token or personal data goes to whatever page is in the target window, including one an attacker navigated there. A listener that does not check event.origin accepts commands from any site that can open or frame yours.
Poprawka
Send with the exact origin ('https://widget.example.com'). In every message listener on window, return early unless event.origin is in an allowlist (and event.source is the expected frame), then validate event.data before using it. Never pass message data to an HTML sink or eval.
Przykłady
// bad
frame.contentWindow.postMessage({ token }, '*')
window.addEventListener('message', (e) => apply(e.data))
// good
frame.contentWindow.postMessage({ token }, 'https://widget.example.com')
window.addEventListener('message', (e) => { if (e.origin === 'https://widget.example.com') apply(e.data) })Źródła
Fakty
- Identyfikator
security/postmessage-origin- Waga
- poważna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
htmljsxvuesvelteastro- Uczy jej skill
fe-securityFront-end security- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain security/postmessage-origin