Video summary
pwn.college - Talking Web - State
Main summary
Key takeaways
Main ideas / concepts
-
Web applications are remote programs
- Modern web apps aren’t just static files (e.g., images). They’re typically programs running on remote servers.
- The browser communicates with the remote server over HTTP.
-
Programs can be “stateful”
- “State” is what changes over time for an interactive program.
- Examples: logging in, account details, online banking—where the server needs to remember who you are and what actions happened.
-
HTTP is stateless (protocol-level statelessness)
- Even if the web application is stateful, HTTP itself is stateless.
- The server cannot automatically know which client made a previous request because HTTP does not inherently bind requests together.
-
Why normal “remembering” doesn’t work in HTTP
- If you POST login credentials, the server can respond, but future requests won’t automatically be associated with that prior login.
- The protocol provides no built-in “this is the same client as before” mechanism.
Instructional / mechanism: how to maintain state with cookies
- Use HTTP cookies to carry state between requests
- Server → Client: respond with a
Set-Cookieheader. - Client → Server (future requests): include the cookie using the
Cookieheader. - Because the client keeps sending the cookie back, the server can use it to recover the prior state.
- Server → Client: respond with a
Example: login state via cookie value
-
Login request
- POST to a login resource like
account.example.com/login(described asaccount.agample.comin the subtitles). - Send form data (URL-encoded) including:
username=Connorpassword=password(hypothetical correct credentials)
- POST to a login resource like
-
Server response behavior
- The server sets a cookie in the response header:
Set-Cookie: off=Connor
- It also returns a redirect status:
- 302 “Moved Temporarily”
- The client is expected to make another request to the root resource (e.g.,
/) and include the cookie.
- The server sets a cookie in the response header:
-
Subsequent request
- The browser sends future requests including:
Cookie: off=Connor
- The server reads the cookie and responds with stateful behavior, e.g.:
- “Hello Connor…”
- The browser sends future requests including:
-
Demonstrating persistence across users
- Another user (e.g.,
CANAC/ “Kanek” in the subtitles) logs in:- Server sets:
Set-Cookie: off=CANAC
- Server sets:
- When that user requests
/again withCookie: off=CANAC, the server responds:- “Hello CANAC…”
- Key point: state is maintained because each client includes its own cookie value.
- Another user (e.g.,
Security concern: raw state in cookies can be forged
-
Problem
- Since HTTP requests are just messages, an attacker can craft their own requests.
- The server may trust cookie contents too much.
- Example scenario:
- If the server treats
offas “the username” directly, - an attacker could send
Cookie: off=adminwithout ever performing the login, - and the server might respond “Hello admin…”
- If the server treats
-
Why this happens
- HTTP doesn’t enforce that the login previously occurred.
- The server is basically acting on whatever state the cookie claims.
- This is framed as a likely source of security issues that will be explored later.
-
Important takeaway
- Web applications must assume clients can generate arbitrary HTTP requests.
- You should not assume users will only send cookies that the server “told them to send.”
Better approach mentioned: session IDs instead of raw identity
-
Recommended mitigation
- When logging in, don’t store raw “who the user is” (e.g.,
off=Connor) as directly trusted identity. - Instead, store an unguessable session ID in the cookie.
- When logging in, don’t store raw “who the user is” (e.g.,
-
How session-based state works
- On login:
- Server creates a server-side record in a database:
- session ID → which user it represents (e.g., Connor)
- Client receives:
Set-Cookie: session=<difficult-to-guess-id>
- Server creates a server-side record in a database:
- On future requests:
- Client includes:
Cookie: session=<id>
- Server looks up that session ID in its database and authorizes accordingly.
- Client includes:
- On login:
-
Same underlying idea, safer use
- Both methods use cookies to maintain state, but:
- Raw identity in cookies can be forged if trusted directly.
- Session IDs are harder to guess and validated server-side.
- Both methods use cookies to maintain state, but:
When raw cookie state may be acceptable
- The lecture notes there can be cases where storing non-sensitive preferences directly in cookies is fine, such as:
- Theme selection (e.g.,
theme=darkvstheme=light) - If a forged theme value only changes presentation (not privileges), it may not create a security risk.
- Theme selection (e.g.,
Overall lesson
- Understanding HTTP’s stateless nature is critical because:
- The standard format and behavior of HTTP enables cookie-based state transfer,
- which can lead to common security problems if the server trusts client-provided values incorrectly.
- As a developer, you must design state and authentication/authorization logic with the assumption that clients can construct arbitrary HTTP requests.
Speakers / sources featured
- Speaker: The course lecturer (unnamed in subtitles) presenting pwn.college lecture content.
- Source referenced: RFC 1945 (cited as the reference indicating HTTP is stateless).