Coding task · JavaScript and React course · Module 10: React Ecosystem and Future

Practice: Station Security Center

React escapes values inside JSX braces, so the <img onerror=...> tag from a message is displayed as text. It does not protect links, though: an address with the javascript: or data: protocol has to be rejected by you, by checking new URL(address).protocol against a list of allowed protocols. Security tokens (CSRF) come from crypto.getRandomValues(), and rel="noopener noreferrer" cuts the new tab off from window.opener and does not send the page address.

Task

Secure the panel that shows transmissions from unknown ships. React escapes the message text by itself, because it goes into JSX inside braces. ___BLANK1___: isSafeUrl returns true only for the http:, https: and mailto: protocols (false for javascript:, data: and any other). ___BLANK2___: fill the bytes array with random bytes from the cryptographically secure crypto.getRandomValues (never Math.random), so that a 32-character CSRF token is created. ___BLANK3___: a link that opens in a new tab gets rel with the values noopener and noreferrer. In the preview the link from the unknown ship must be blocked and its text shown as plain text.