DEV Community

Cover image for I Know It's You, But I Can't Prove It

I Know It's You, But I Can't Prove It

Elmar Chavez on November 25, 2026

Imagine you have a list of usernames and passwords. Then a user logs in to your web application. You check and verify that they are indeed on the l...
Collapse
 
francistrdev profile image
FrancisTRᴅᴇᴠ •

Great detail article on JWT Elmar!

Collapse
 
codingwithjiro profile image
Elmar Chavez •

Thank you @francistrdev!

Collapse
 
kielltampubolon profile image
Kiell Tampubolon •

The key analogy works well. One thing I'd want in the follow-up next to logout is where the browser keeps that key. In localStorage any script on the page can read it, so a single XSS hands over the key to every door. An httpOnly cookie keeps it out of JavaScript's reach, at the cost of having to think about CSRF. For a Kanban backend it's a small decision now and an annoying migration later.

Collapse
 
codingwithjiro profile image
Elmar Chavez •

Right on. Been reading a lot about XSS and CSRF so everything was kind of new to me. Thanks for explaining this a bit further.

Collapse
 
paullovelace profile image
Paul Lovelace •

Decoded the example token — 'Thor's secret enemy' and 'I love you 3000' sitting in plain base64 is the whole lesson in one string. Anyone can read it; the signature's the only thing stopping them rewriting it. The short-lived + refresh token bit is the part I'd want the follow-up on — do you rotate the refresh token on every use, or is that a whole second post?

Collapse
 
codingwithjiro profile image
Elmar Chavez •

Ohh, thanks for cracking the code. Yep, I was tempted to add the refresh token topic here but I feel like it would be too much for a single post. For the next one? I'm thinking of a completely different topic!

Collapse
 
riskopslab profile image
Tao Zhu •

Clear walkthrough of the encoding vs. signature distinction, which trips up a lot of first-time backend builds. When wiring up jwt.verify() in Node/Express, one subtle edge case worth pinning down is passing an explicit algorithms: ['HS256'] allowlist rather than trusting the token header's alg field, so alg: none or key-confusion payloads get rejected immediately. Storing those short-lived tokens in HttpOnly; SameSite=Lax cookies instead of localStorage also prevents stray client-side scripts from exfiltrating them.

Collapse
 
codingwithjiro profile image
Elmar Chavez •

Yes, I believe I did SameSite=Lax and HttpOnly on my first backend. But explicitly saying I only allow 'HS256' is new to me. It make sense actually, if not the same, the token is rejected ASAP. Thanks for the in-depth explanation!

Collapse
 
gautamtalksdev profile image
Gautam K •

Great framing. Knowing it's the same person and being able to prove it are different problems, and most auth bugs live in the gap between them. Nice walk through it.

Collapse
 
syedfahads profile image
Syed Fahad •

fun next one to write: logout. the token stays valid until exp no matter what the user clicks, and that's usually where people first meet short expiry plus a denylist

Collapse
 
codingwithjiro profile image
Elmar Chavez •

Ohhh, I'll keep this in mind!

Collapse
 
parimalmakes profile image
Parimal Makes •

The noobmaster69 payload in the example token was a fun touch, and keeping the distinction between base64 encoding and actual encryption clear is something a lot of JWT intros skip

Collapse
 
codingwithjiro profile image
Elmar Chavez •

Glad that distinction came out well. Thanks @parimalmakes

Collapse
 
the_daily_flare profile image
The daily flare •

I think the encoding versus encryption distinction was the clearest part for me.

Collapse
 
codingwithjiro profile image
Elmar Chavez •

Thanks! I did quite a lot of thinking of how I could translate it in real world visuals.