Skip to main content

Web Security: XSS, CSRF, CSP and Safe Coding

Learn Web Security: XSS, CSRF, CSP and Safe Coding (Phase 13 · Security and Testing (Essential for production), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Cross-site scripting (XSS) • XSS happens when untrusted text is inserted into the page as HTML or script . The attacker's script then runs with the user's privileges (reads storage, calls APIs, steals sessions). • Types: stored (saved in the database and shown to others), reflected (echoed from the URL), DOM-based (client-side code writes input into the DOM). • Defence: output-encode by default. Use textContent instead of innerHTML ; frameworks like React escape automatically.

More lessons in Phase 13 · Security and Testing (Essential for production)