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)
Related DVA-C02 questions
- A Lambda function's execution role has the AWS managed AmazonS3FullAccess policy attached.Security
- A developer is deploying an application to Amazon EC2 and plans to put an IAM user's access key in the application's…Security
- A developer is comparing AWS managed KMS keys (such as aws/s3) with customer managed KMS keys (symmetric, with key…Security
- An IAM policy needs to restrict access so that a set of API calls can only succeed when made over an encrypted (HTTPS)…Security
All 67 free DVA-C02 questions by domain · 15 sample questions on one page
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.