Skip to main content

DVA-C02 practice question · Security

A web application stores session tokens and needs to prevent them from being read by client-side JavaScript in the…

A web application stores session tokens and needs to prevent them from being read by client-side JavaScript in the browser, to reduce the impact of a cross-site scripting (XSS) vulnerability. What cookie attribute helps with this?

  • AHttpOnly
  • BSameSite=None with no other restriction
  • CA longer expiration time
  • DStoring the token in localStorage instead of a cookie
Show the answer and explanation

Correct answer: A) HttpOnly

Why each option is right or wrong

  • A) Correct. The HttpOnly attribute prevents client-side scripts from accessing the cookie via document.cookie, reducing the risk that an XSS vulnerability could be used to steal the session token.
  • B) Incorrect. SameSite controls whether a cookie is sent on cross-site requests, related to CSRF risk, not whether JavaScript can read the cookie's contents.
  • C) Incorrect. A longer expiration increases exposure time if the token is stolen; it doesn't prevent JavaScript from reading it.
  • D) Incorrect. localStorage is fully accessible to JavaScript, making it more vulnerable to theft via XSS than an HttpOnly cookie, not less.
Exam domain
Security · 26% of DVA-C02
Question type
Multiple choice (one answer)

Practise the full DVA-C02 exam

This question is one of a small free sample from the CertRidge DVA-C02 bank. Full practice exams match the real exam's length, time limit and domain weights, explain every option, and Review Mode re-drills the questions you miss.

Original question written from the official exam guide. Not affiliated with AWS; never copied from the real exam.

Worth reading: DVA-C02 cheat sheet, Lambda, DynamoDB, API Gateway, IAM and Cognito, messaging, CI/CD and X-Ray in tables, plus what DVA-C03 changes.