Cookie and Session

Junghoo Cho

cho@cs.ucla.edu

HTTP: Stateless

Cookie: Key Idea

Setting Cookie

Set-Cookie: username=john; expires=Wed, 21 Oct 2031 07:28:00 GMT;

Sending Cookie Back

Cookie: username=john

Same-Origin Policy

Tracking Users Across Domains

Third-Party Cookie


Cookie is Unsafe

Securing Cookies

JSON Web Token (JWT)

JWT Header

Payload

Signature

Final JWT

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9           // header
.eyJrZXkiOiJ2YWwiLCJpYXQiOjE0MjI2MDU0NDV9      // payload
.eUiabuiKv-8PYk2AkGY4Fb5KMZeorYBLw261JPQD5lM   // signature
{
    "alg": "HS256",
    "typ": "JWT"
}.{
    "iss": "http://oak.cs.ucla.edu",
    "jti": "3gxhylhd",
    "exp": 11253352,
    "user": "junghoo"
}.signature

User Authentication

Session

What We Learned

References