Skip to content

Lesson 05 — Cookies

Imagine you log in to your online banking application.

After entering your username and password, you navigate between:

  • Dashboard
  • Account Summary
  • Transactions
  • Bill Payments
  • Profile Settings

Notice that you don’t need to log in again every time you open a new page.

How does the website remember who you are?

The answer is Cookies.

Cookies allow web applications to remember information between HTTP requests.

They are used for:

  • User Authentication
  • Session Management
  • Shopping Carts
  • User Preferences
  • Language Selection
  • Analytics
  • Personalization

Understanding cookies is essential for every cybersecurity professional because many web attacks target insecure cookie implementations.


After completing this lesson, you will be able to:

  • Understand HTTP Cookies.
  • Learn how cookies work.
  • Explore cookie types.
  • Understand cookie attributes.
  • Learn authentication cookies.
  • Explore cookie security.
  • Understand enterprise implementations.
  • Apply cookie security best practices.

A Cookie is a small piece of data stored by a web browser on behalf of a website.

The browser automatically sends the cookie back to the server with future requests.

Cookies help websites remember users and maintain state across multiple HTTP requests.


Organizations use cookies to:

  • Keep users logged in.
  • Store shopping carts.
  • Remember language preferences.
  • Save website settings.
  • Personalize content.
  • Improve user experience.

Without cookies, users would need to authenticate on every page request.


HTTP is a stateless protocol.

This means each request is independent.

Cookies help web applications maintain user state.

Login
Cookie Created
Browser Stores Cookie
Future Requests Include Cookie
User Remains Logged In

A typical workflow:

User Login
Server Validates Credentials
Server Sends Cookie
Browser Stores Cookie
Browser Sends Cookie
Server Identifies User

The cookie allows the server to recognize the user across multiple requests.


Example response header:

Set-Cookie: SessionID=ABCD12345

Future requests automatically include:

Cookie: SessionID=ABCD12345

The server uses this value to identify the user’s session.


A cookie typically contains:

  • Name
  • Value
  • Expiration Time
  • Domain
  • Path
  • Secure Flag
  • HttpOnly Flag
  • SameSite Attribute

These attributes determine how and when the cookie is used.


Common cookie types include:

  • Session Cookies
  • Persistent Cookies
  • Secure Cookies
  • HttpOnly Cookies
  • SameSite Cookies
  • Third-Party Cookies

Each type serves a different purpose.


Session cookies exist only while the browser is open.

Characteristics:

  • Temporary
  • Deleted after browser closes
  • Commonly used for login sessions

These are widely used for authentication.


Persistent cookies remain stored after the browser closes.

Examples:

  • Remember Me
  • Language Preferences
  • Theme Settings
  • User Preferences

They expire after a configured period.


Secure cookies are transmitted only over HTTPS.

HTTPS
Secure Cookie Sent
HTTP
Cookie Not Sent

This helps protect cookies from interception.


The HttpOnly attribute prevents JavaScript from accessing the cookie.

Benefits:

  • Reduces XSS risk
  • Protects session cookies
  • Prevents client-side access

Authentication cookies should typically use HttpOnly.


The SameSite attribute controls when browsers send cookies during cross-site requests.

Values include:

  • Strict
  • Lax
  • None

SameSite helps reduce the risk of Cross-Site Request Forgery (CSRF) attacks.


First-Party Third-Party
Created by visited website Created by another domain
Used for authentication Often used for advertising
Generally more trusted More restricted by modern browsers

Many browsers now limit third-party cookie usage to improve privacy.


Most login systems use cookies.

User Login
Authentication Successful
Session Cookie Issued
Browser Stores Cookie
Authenticated Requests

The cookie acts as proof that the user has already authenticated.


Cloud applications use cookies for:

  • AWS Console Authentication
  • Management Console Sessions
  • Azure Portal Authentication
  • Microsoft Entra Sessions
  • Google Cloud Console
  • Workspace Authentication

Cookies enable secure authenticated sessions across cloud management interfaces.


Applications commonly use cookies for:

  • User Login
  • Shopping Cart
  • Theme Preferences
  • Language Selection
  • User Personalization
  • MFA Sessions

Cookies improve usability while maintaining session state.


Poorly configured cookies may lead to:

  • Session Hijacking
  • Cookie Theft
  • Cross-Site Scripting (XSS)
  • Cross-Site Request Forgery (CSRF)
  • Session Fixation

Protecting authentication cookies is critical.


Authentication cookies should generally include:

  • Secure
  • HttpOnly
  • SameSite
  • Appropriate Expiration Time

These settings reduce common attack risks.


Organizations use cookies for:

  • Enterprise Portals
  • Banking Applications
  • E-commerce Websites
  • Healthcare Systems
  • SaaS Applications
  • Cloud Consoles
  • Learning Platforms

Nearly every authenticated web application relies on cookies.


Avoid:

  • Sending cookies over HTTP.
  • Omitting the Secure flag.
  • Forgetting the HttpOnly attribute.
  • Using overly long expiration periods.
  • Storing sensitive information inside cookies.
  • Ignoring SameSite protections.

Improper cookie handling can expose users to session-based attacks.


Professional organizations:

  • Always use HTTPS.
  • Mark authentication cookies as Secure.
  • Use HttpOnly for session cookies.
  • Configure SameSite appropriately.
  • Rotate session identifiers after login.
  • Expire inactive sessions.
  • Encrypt sensitive application data.
  • Monitor suspicious session activity.

These practices significantly improve session security.


CloudNova Technologies provides an employee portal.

Employee Login
Authentication Successful
Session Cookie Issued
Browser Stores Cookie
Employee Navigates Portal
Cookie Sent Automatically
Application Recognizes User

The employee can securely browse multiple pages without repeatedly entering credentials.


After completing this lesson, you should understand:

  • HTTP Cookies
  • Session Cookies
  • Persistent Cookies
  • Secure Cookies
  • HttpOnly
  • SameSite
  • Authentication Cookies
  • Cookie Security
  • Cookie Attributes
  • Enterprise Cookie Best Practices

Cookies are a fundamental component of modern web applications.

They allow websites to maintain user sessions, remember preferences, and deliver personalized experiences. Because cookies often contain authentication information, they must be protected using HTTPS, Secure, HttpOnly, and SameSite attributes to reduce the risk of session hijacking and other web attacks.

Understanding cookies is an essential skill for Cloud Security Engineers, Security Architects, DevSecOps Engineers, Penetration Testers, SOC Analysts, and cybersecurity professionals responsible for securing modern web applications.


➡️ Lesson 06 — Sessions

In the next lesson, you’ll learn how Sessions enable web applications to maintain authenticated user state on the server. You’ll explore session identifiers, session lifecycle, session management, session storage, common attacks, and enterprise best practices for secure session management.