Server Behavior and Cookie Scenarios

This document explains the behavior of each server in the Cookie Playground infrastructure, including when and how cookies are handled.

Infrastructure Overview

The Cookie Playground consists of multiple servers, each serving different purposes:

Server Architecture

Each server (except guide and redirect) follows the same pattern:

HTML Handler Lambda Function

Purpose: Serves HTML pages to browsers

Behavior:

Endpoints:

Example Response:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: no-cache, no-store, must-revalidate

<!DOCTYPE html>
<html>
  <!-- HTML content with domain placeholders replaced -->
</html>

Pixel Handler Lambda Function

Purpose: Serves 1x1 transparent GIF pixels for tracking/testing

Behavior:

Endpoints:

Example Response:

HTTP/1.1 200 OK
Content-Type: image/gif
Cache-Control: no-cache, no-store, must-revalidate
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, OPTIONS

[1x1 transparent GIF binary data]

Logging: The pixel handler logs the following information to CloudWatch:

Redirect Handler Lambda Function

Purpose: Performs HTTP 301 redirects to test cookie behavior during redirects

Behavior:

Endpoints:

Example Response:

HTTP/1.1 301 Moved Permanently
Location: https://site-a.cookie-playground.pun7o.click/path?query=value
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

{"message": "Permanent redirect", "redirectTo": "https://..."}

Important: Servers Do NOT Automatically Set Cookies

Key Point: None of the server-side Lambda functions set cookies via Set-Cookie headers. This is intentional to allow users to experiment with cookie behavior using JavaScript.

Cookies are set using JavaScript in the HTML pages:

document.cookie = "name=value; Domain=.example.com; Path=/; Secure; SameSite=Lax";

When Cookies Are Set:

  1. User Interaction: When users interact with the cookie playground forms
  2. Page Load: Some pages may set cookies on load (via JavaScript)
  3. Pixel Requests: JavaScript can set cookies before loading pixels

Cookie Attributes Supported:

Server-Specific Behavior

Available Pages:

Domain Replacement:

Cookie Context:

Subdomain A (site-a.cookie-playground.pun7o.click)

Available Pages:

Domain Replacement:

Cookie Context:

Subdomain B (site-b.cookie-playground.pun7o.click)

Available Pages:

Domain Replacement:

Cookie Context:

Redirect Domain (site-c.cookie-playground.pun7o.click)

Behavior:

Cookie Context:

Setup:

  1. Visit https://cookie-playground.pun7o.click
  2. Set cookie: test_cookie=value1; Domain=cookie-playground.pun7o.click; Path=/

Result:

Setup:

  1. Visit https://site-a.cookie-playground.pun7o.click
  2. Set cookie: subdomain_cookie=value2; Domain=site-a.cookie-playground.pun7o.click; Path=/

Result:

Setup:

  1. Visit https://site-a.cookie-playground.pun7o.click
  2. Set cookie: parent_cookie=value3; Domain=cookie-playground.pun7o.click; Path=/

Result:

Scenario 4: Cross-Domain Pixel Request

Setup:

  1. Visit https://site-a.cookie-playground.pun7o.click
  2. Set cookie: tracking_cookie=value4; Domain=cookie-playground.pun7o.click; Path=/
  3. Load pixel: <img src="https://cookie-playground.pun7o.click/pixel?id=123" />

Result:

Scenario 5: Third-Party Pixel Request

Setup:

  1. Visit https://site-a.cookie-playground.pun7o.click
  2. Set cookie: third_party_cookie=value5; Domain=site-b.cookie-playground.pun7o.click; Path=/
  3. Load pixel from subdomain B: <img src="https://site-b.cookie-playground.pun7o.click/pixel?id=123" />

Result:

Scenario 6: Redirect with Cookies

Setup:

  1. Visit https://site-c.cookie-playground.pun7o.click
  2. Set cookie: redirect_cookie=value6; Domain=cookie-playground.pun7o.click; Path=/
  3. Browser follows redirect to site-a.cookie-playground.pun7o.click

Result:

HTML Page Request Flow

sequenceDiagram participant Browser participant API Gateway participant HTML Handler participant Browser Storage Browser->>API Gateway: GET /index.html API Gateway->>HTML Handler: Invoke Lambda HTML Handler->>HTML Handler: Read HTML file HTML Handler->>HTML Handler: Replace domain placeholders HTML Handler->>API Gateway: Return HTML (no Set-Cookie) API Gateway->>Browser: HTTP 200 OK
Content-Type: text/html Note over Browser: HTML loaded, JavaScript executes Browser->>Browser Storage: document.cookie = name=value#59; Domain=example.com Browser Storage-->>Browser: Cookie stored

Pixel Request Flow

sequenceDiagram participant Browser participant API Gateway participant Pixel Handler participant CloudWatch Browser->>API Gateway: GET /pixel?id=123
Cookie: tracking_cookie=value API Gateway->>Pixel Handler: Invoke Lambda Pixel Handler->>Pixel Handler: Extract request data Pixel Handler->>CloudWatch: Log request (including cookies) Pixel Handler->>API Gateway: Return 1x1 GIF (no Set-Cookie) API Gateway->>Browser: HTTP 200 OK
Content-Type: image/gif

Redirect Flow

sequenceDiagram participant Browser participant API Gateway participant Redirect Handler participant Target Server Browser->>API Gateway: GET /path
Cookie: redirect_cookie=value API Gateway->>Redirect Handler: Invoke Lambda Redirect Handler->>Redirect Handler: Construct redirect URL Redirect Handler->>Redirect Handler: Log redirect details Redirect Handler->>API Gateway: HTTP 301
Location: target domain API Gateway->>Browser: HTTP 301 Moved Permanently Browser->>Target Server: GET /path
Cookie: redirect_cookie=value Target Server->>Browser: HTTP 200 OK

Testing Server Behavior

Inspecting Server Responses

Use browser developer tools to inspect HTTP responses:

  1. Open Developer Tools (F12)
  2. Navigate to Network tab
  3. Load a page (e.g., https://site-a.cookie-playground.pun7o.click)
  4. Inspect Response Headers:
    • Look for Set-Cookie headers (should be none)
    • Verify Content-Type matches expected type
    • Check Cache-Control headers

Inspecting Pixel Requests

  1. Load a page with pixel tags
  2. Open Network tab in developer tools
  3. Filter by "pixel" or "gif"
  4. Inspect Request Headers:
    • Check Cookie header (shows cookies sent)
    • Check Referer header (shows originating page)
  5. Inspect Response Headers:
    • Verify Content-Type: image/gif
    • Verify no Set-Cookie header

Checking CloudWatch Logs

Pixel handlers log all requests to CloudWatch:

  1. Open AWS Console
  2. Navigate to CloudWatch Logs
  3. Find log group: /aws/lambda/cookie-playground-pixel-handler-*
  4. View log entries:
    • Each pixel request logs full request details
    • Includes cookies received in request
    • Includes query parameters and headers

Summary

Key Points

  1. Servers do NOT set cookies automatically - This is intentional for experimentation
  2. Cookies are set via JavaScript - Using document.cookie in HTML pages
  3. Pixel handlers receive cookies - They log cookies but don't set them
  4. Redirect handlers preserve cookies - Cookies are sent with redirect requests
  5. Domain attribute controls scope - Parent domain cookies accessible by subdomains

When Cookies Are Added

Which Cookies Are Set

Next Steps