Web security interview questions
Show answer
Cross-site scripting is when attacker-controlled input runs as script in another user's browser. Prevent it by escaping output (frameworks like React do this by default), sanitising any HTML you must render, avoiding
dangerouslySetInnerHTML/innerHTMLwith user data, and adding a Content-Security-Policy as defence in depth.Show answer
Cross-site request forgery tricks a logged-in user's browser into sending a state-changing request to your site. Defences:
SameSitecookies (Lax or Strict), CSRF tokens on forms, checking the Origin header, and never changing state on GET requests.