JavaScript theorytheory 0/50 · 0%
Security · hard

45. Security in the browser

XSS, dependencies and secrets.

Anything in a front-end bundle is public: there are no client-side secrets. Untrusted HTML injected into the page can steal sessions and swap wallet addresses, and a compromised npm dependency can do the same.

el.textContent = userInput; // safe
el.innerHTML = userInput;   // XSS

Pin dependencies, review lockfile changes, use a content security policy, and always display the exact address and amount the user is about to sign.

Check your understanding

  1. 1. Can a front-end keep an API secret?

  2. 2. What is the danger of innerHTML with user data?

  3. 3. What limits supply-chain risk?