Courseiva
Question 969 of 724
SecuritymediumMultiple ChoiceObjective-mapped

DVA-C02 Security Practice Question

A company hosts a web application on EC2 instances behind an ALB. The application uses cookies to track user sessions. The security team is concerned about session hijacking. Which action should be taken to protect the cookies?

⚠ Common exam trap

A common mix-up: candidates confuse encryption of the connection (Option A) with securing the cookie itself, or they assume moving session state server-side (Option B) eliminates the need for cookie security flags, when in fact the session identifier cookie still requires Secure and HttpOnly protection.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Set the Secure and HttpOnly flags on the session cookie.

Setting the Secure and HttpOnly flags on the session cookie is the correct action because the Secure flag ensures the cookie is only sent over HTTPS, preventing interception via man-in-the-middle attacks, while the HttpOnly flag prevents client-side scripts (e.g., JavaScript) from accessing the cookie, mitigating cross-site scripting (XSS)-based session hijacking. This directly addresses the security team's concern by hardening the cookie against common attack vectors without requiring architectural changes.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Enable encryption on the ALB using a custom SSL certificate.

    Why it's wrong here

    Enabling encryption on the ALB using an SSL certificate establishes a secure HTTPS connection between the client and the load balancer, encrypting all data in transit. This prevents eavesdropping on the network communication. However, it does not directly influence or enforce the `Secure` or `HttpOnly` attributes of a session cookie, which are directives set by the application server for the browser's behavior, not transport layer encryption.

  • Store session data in ElastiCache instead of cookies.

    Why it's wrong here

    Storing session data in ElastiCache offloads the actual session payload from the cookie, leaving only a session identifier in the browser's cookie. This reduces the risk of sensitive data exposure if the cookie is intercepted and can improve performance by reducing request header size. Nevertheless, if the session ID itself is stolen through means like XSS, an attacker can still use it to impersonate the user, as ElastiCache only stores the data associated with that ID, not protecting the ID's integrity or confidentiality during transit or storage in the browser.

  • Set the Secure and HttpOnly flags on the session cookie.

    Why this is correct

    Setting the `Secure` flag ensures that the browser will only send the session cookie over encrypted HTTPS connections, preventing its transmission over insecure HTTP and protecting against passive network eavesdropping. The `HttpOnly` flag prevents client-side scripts, such as JavaScript, from accessing the cookie's value. This is a critical defense against Cross-Site Scripting (XSS) attacks, where an attacker might otherwise inject malicious scripts to steal session cookies and hijack user sessions.

  • Use AWS WAF to block requests without a valid session cookie.

    Why it's wrong here

    AWS WAF operates at the application layer and can inspect incoming HTTP requests, including headers and cookie values, to block malicious traffic based on predefined rules. While WAF can detect the presence or specific content of a cookie, it cannot directly enforce or modify the `Secure` or `HttpOnly` attributes of a session cookie. These attributes are directives set by the web application server for the client browser, not something WAF can manage or inject into the browser's cookie handling.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 24, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.