Pie Logo
Quiz: Authentication
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
Storage
Authentication Approaches
Exercise: Cookies and Storage
Github Authentication
Google Authentication
Exercise: Social Logins
Quiz: Authentication
Assignment 2.3: Blog - Backend
APIs
CI/CD and DevOps
Testing React
Advanced Topics
    Pie Logo
    Quiz: Authentication
    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
    Storage
    Authentication Approaches
    Exercise: Cookies and Storage
    Github Authentication
    Google Authentication
    Exercise: Social Logins
    Quiz: Authentication
    Assignment 2.3: Blog - Backend
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics

    New Quiz
    by Tomas Trescak· Authentication Approaches

    QUESTION 1

    Alice logs into the Blogs app using cookie-based authentication. The server generates a session ID (sess_12345) and sends it to her browser in a cookie. Later, a hacker intercepts this cookie because the Blogs app isn’t using HTTPS. What could the hacker do with it?


    QUESTION 2

    In the Blogs app, the login API route checks Alice’s credentials and sets a cookie like this: session=sess_12345; Secure; HttpOnly; SameSite=Strict. Which of these security measures prevents a malicious script on a fake Blogs page from stealing the cookie?


    QUESTION 3

    Alice uses token-based authentication with JWT in the Blogs app. Her session token expires in 15 minutes, and she sends a refresh token (rf_abc123xyz) to /api/refresh. The server checks the refresh token against its database. What happens if the refresh token was stolen and already used by a hacker?


    QUESTION 4

    Here’s a snippet from the Blogs app’s Next.js API route for login:

    import { setCookie } from 'cookies-next';
    export default async function handler(req, res) {
      const { email, password } = req.body;
      const user = await verifyUser(email, password); // Hashed check
      if (user) {
        const sessionId = generateSessionId();
        await storeSession(sessionId, user.id);
        setCookie('session', sessionId, { req, res, secure: true, httpOnly: true });
        return res.status(200).json({ message: 'Logged in' });
      }
      return res.status(401).json({ error: 'Invalid credentials' });
    }
    

    What does the httpOnly: true option in setCookie protect against?


    QUESTION 5

    Alice logs into Blogs via OAuth with her Google account. The Blogs server receives an access token and verifies it with Google. What could go wrong if Google’s authentication servers are down?


    QUESTION 6

    In the Blogs app, a company uses SAML for SSO. Alice logs into her company’s IdP (Okta), and Blogs receives this SAML assertion:

    <saml:Assertion>
      <saml:Attribute Name="email" Value="alice@company.com"/>
      <saml:Attribute Name="role" Value="admin"/>
    </saml:Assertion>
    

    What can Blogs do with this information?


    QUESTION 7

    The Blogs app uses JWT with a refresh token workflow. Alice’s session token expires, and her browser sends this request:

    POST /api/refresh
    Cookie: refresh_token=rf_abc123xyz
    

    The server checks its database and finds rf_abc123xyz tied to userId: 1. What should the server do next?


    QUESTION 8

    Imagine a hacker tricks Alice into clicking a link that sends a request to Blogs with her cookie (session=sess_12345). The cookie has SameSite=Lax. What happens?


    QUESTION 9

    Comparing security for Blogs: A developer forgets to hash passwords in the database and stores them as plain text (e.g., supersecret). What’s the biggest risk?


    QUESTION 10

    Alice uses Blogs on her phone with JWT. Her session token is stored in localStorage, and a malicious app steals it via XSS. What could Blogs have done to prevent this?

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

    New Quiz
    by Tomas Trescak· Authentication Approaches

    QUESTION 1

    Alice logs into the Blogs app using cookie-based authentication. The server generates a session ID (sess_12345) and sends it to her browser in a cookie. Later, a hacker intercepts this cookie because the Blogs app isn’t using HTTPS. What could the hacker do with it?


    QUESTION 2

    In the Blogs app, the login API route checks Alice’s credentials and sets a cookie like this: session=sess_12345; Secure; HttpOnly; SameSite=Strict. Which of these security measures prevents a malicious script on a fake Blogs page from stealing the cookie?


    QUESTION 3

    Alice uses token-based authentication with JWT in the Blogs app. Her session token expires in 15 minutes, and she sends a refresh token (rf_abc123xyz) to /api/refresh. The server checks the refresh token against its database. What happens if the refresh token was stolen and already used by a hacker?


    QUESTION 4

    Here’s a snippet from the Blogs app’s Next.js API route for login:

    import { setCookie } from 'cookies-next';
    export default async function handler(req, res) {
      const { email, password } = req.body;
      const user = await verifyUser(email, password); // Hashed check
      if (user) {
        const sessionId = generateSessionId();
        await storeSession(sessionId, user.id);
        setCookie('session', sessionId, { req, res, secure: true, httpOnly: true });
        return res.status(200).json({ message: 'Logged in' });
      }
      return res.status(401).json({ error: 'Invalid credentials' });
    }
    

    What does the httpOnly: true option in setCookie protect against?


    QUESTION 5

    Alice logs into Blogs via OAuth with her Google account. The Blogs server receives an access token and verifies it with Google. What could go wrong if Google’s authentication servers are down?


    QUESTION 6

    In the Blogs app, a company uses SAML for SSO. Alice logs into her company’s IdP (Okta), and Blogs receives this SAML assertion:

    <saml:Assertion>
      <saml:Attribute Name="email" Value="alice@company.com"/>
      <saml:Attribute Name="role" Value="admin"/>
    </saml:Assertion>
    

    What can Blogs do with this information?


    QUESTION 7

    The Blogs app uses JWT with a refresh token workflow. Alice’s session token expires, and her browser sends this request:

    POST /api/refresh
    Cookie: refresh_token=rf_abc123xyz
    

    The server checks its database and finds rf_abc123xyz tied to userId: 1. What should the server do next?


    QUESTION 8

    Imagine a hacker tricks Alice into clicking a link that sends a request to Blogs with her cookie (session=sess_12345). The cookie has SameSite=Lax. What happens?


    QUESTION 9

    Comparing security for Blogs: A developer forgets to hash passwords in the database and stores them as plain text (e.g., supersecret). What’s the biggest risk?


    QUESTION 10

    Alice uses Blogs on her phone with JWT. Her session token is stored in localStorage, and a malicious app steals it via XSS. What could Blogs have done to prevent this?

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

    Pie Logo
    Quiz: Authentication
    by Tomas Trescak
    Pie Logo
    Quiz: Authentication
    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
    Storage
    Authentication Approaches
    Exercise: Cookies and Storage
    Github Authentication
    Google Authentication
    Exercise: Social Logins
    Quiz: Authentication
    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
    Storage
    Authentication Approaches
    Exercise: Cookies and Storage
    Github Authentication
    Google Authentication
    Exercise: Social Logins
    Quiz: Authentication
    Assignment 2.3: Blog - Backend
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics