Pie Logo
Quiz: Cookies
by Tomas Trescak

QuizTest your understanding of the section content.

ContentDetailed description of the section content.

Full Stack Development
Introduction
Generative AI
🍰 Player
💼 Editor
Setup
React Fundamentals
Next.js
Advanced React
Databases
React Hooks
Authentication and Authorisation
Cookies
Quiz: Cookies
Storage
Authentication Approaches
Assignment 2.3: Blog - Backend
APIs
CI/CD and DevOps
Testing React
Advanced Topics
    Pie Logo
    Quiz: Cookies
    by Tomas Trescak

    QuizTest your understanding of the section content.

    ContentDetailed description of the section content.

    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    Cookies
    Quiz: Cookies
    Storage
    Authentication Approaches
    Assignment 2.3: Blog - Backend
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics
    QUESTION 1

    In the Blog application, a guest visits the site, and the server sets a cookie with visitor_id=guest456 using the code below:

    cookies().set('visitor_id', 'guest456', { path: '/', maxAge: 60 * 60 });
    

    Later, the guest refreshes the page. What happens to the visitor_id cookie?


    QUESTION 2

    An admin logs into the Blog application, and the server sets a cookie:

    cookies().set('session_id', 'abc789xyz', { httpOnly: true, secure: true, sameSite: 'strict' });
    

    A hacker tries to steal this cookie using a malicious script injected into the page (XSS attack). What prevents the hacker from succeeding?


    QUESTION 3

    A user sets a preference cookie client-side in the Blog application:

    documentcookie='prefs=tag:tech; path=/; max-age=86400';
    

    Later, the server needs to check this cookie. Which of these could go wrong?


    QUESTION 4

    Look at this server-side code to verify an admin session:

    const sessionId = cookieStore.get('session_id')?.value;
    if (sessionId === 'abc789xyz') {
      return new Response(JSON.stringify({ message: 'Admin access granted' }));
    }
    

    What’s a potential problem with this approach in a real application?


    QUESTION 5

    In the Blog application, a developer decides to store a user’s email directly in a cookie: user_email=jane@example.com. Why might this be a bad idea? (Select all that apply.)


    QUESTION 6

    A student modifies the guest cookie code:

    cookies().set('visitor_id', 'guest456', { path: '/blog', maxAge: 60 * 60 });
    

    What changes when the user navigates the Blog application?

    This content is only available to registered users.
    Please register at the the home page.

    QUESTION 1

    In the Blog application, a guest visits the site, and the server sets a cookie with visitor_id=guest456 using the code below:

    cookies().set('visitor_id', 'guest456', { path: '/', maxAge: 60 * 60 });
    

    Later, the guest refreshes the page. What happens to the visitor_id cookie?


    QUESTION 2

    An admin logs into the Blog application, and the server sets a cookie:

    cookies().set('session_id', 'abc789xyz', { httpOnly: true, secure: true, sameSite: 'strict' });
    

    A hacker tries to steal this cookie using a malicious script injected into the page (XSS attack). What prevents the hacker from succeeding?


    QUESTION 3

    A user sets a preference cookie client-side in the Blog application:

    documentcookie='prefs=tag:tech; path=/; max-age=86400';
    

    Later, the server needs to check this cookie. Which of these could go wrong?


    QUESTION 4

    Look at this server-side code to verify an admin session:

    const sessionId = cookieStore.get('session_id')?.value;
    if (sessionId === 'abc789xyz') {
      return new Response(JSON.stringify({ message: 'Admin access granted' }));
    }
    

    What’s a potential problem with this approach in a real application?


    QUESTION 5

    In the Blog application, a developer decides to store a user’s email directly in a cookie: user_email=jane@example.com. Why might this be a bad idea? (Select all that apply.)


    QUESTION 6

    A student modifies the guest cookie code:

    cookies().set('visitor_id', 'guest456', { path: '/blog', maxAge: 60 * 60 });
    

    What changes when the user navigates the Blog application?

    This content is only available to registered users.
    Please register at the the home page.

    Pie Logo
    Quiz: Cookies
    by Tomas Trescak
    Pie Logo
    Quiz: Cookies
    by Tomas Trescak
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    Cookies
    Quiz: Cookies
    Storage
    Authentication Approaches
    Assignment 2.3: Blog - Backend
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    Cookies
    Quiz: Cookies
    Storage
    Authentication Approaches
    Assignment 2.3: Blog - Backend
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics