CS FundamentalsHardProduct-company placement · Security interview

A forum shows user comments, and an attacker posts a comment containing a script tag that runs in other users' browsers. Which is the primary fix?

  1. A. Mark the session cookie HttpOnly
  2. B. Encode untrusted data for the context where it is output (HTML-escape in page content), optionally backed by a Content-Security-Policy
  3. C. Switch the site from HTTP to HTTPS
  4. D. Use parameterised SQL queries when storing comments

Correct answer: B. Encode untrusted data for the context where it is output (HTML-escape in page content), optionally backed by a Content-Security-Policy

This is stored XSS: the fix is context-aware output encoding so the browser treats the text as data. HttpOnly only stops scripts reading the cookie, HTTPS does not affect injected script, and parameterised queries prevent SQL injection, not XSS.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic