<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Younes Hebaiche</title>
    <description>The latest articles on DEV Community by Younes Hebaiche (@0xyurii).</description>
    <link>https://dev.to/0xyurii</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4071186%2F377c8fcb-6fcf-4c82-a58f-69f51175dfa7.jpg</url>
      <title>DEV Community: Younes Hebaiche</title>
      <link>https://dev.to/0xyurii</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/0xyurii"/>
    <language>en</language>
    <item>
      <title>JWT Pitfalls I Actually Ran Into (Building an API Gateway and a Carpooling App)</title>
      <dc:creator>Younes Hebaiche</dc:creator>
      <pubDate>Mon, 10 Aug 2026 11:33:57 +0000</pubDate>
      <link>https://dev.to/0xyurii/jwt-pitfalls-i-actually-ran-into-building-an-api-gateway-and-a-carpooling-app-230l</link>
      <guid>https://dev.to/0xyurii/jwt-pitfalls-i-actually-ran-into-building-an-api-gateway-and-a-carpooling-app-230l</guid>
      <description>&lt;h1&gt;
  
  
  JWT Pitfalls I Actually Ran Into (Building an API Gateway and a Carpooling App)
&lt;/h1&gt;

&lt;p&gt;JWTs look deceptively simple. Decode a token, check a signature, trust the payload, move on. It's the "move on" part that gets people.&lt;/p&gt;

&lt;p&gt;I've implemented JWT auth twice now — once as middleware in &lt;a href="https://github.com/0xYurii/Aegis" rel="noopener noreferrer"&gt;Aegis&lt;/a&gt;, an API gateway I built with a plugin-based architecture, and once in &lt;a href="https://github.com/0xYurii/Wasselni" rel="noopener noreferrer"&gt;Wasselni&lt;/a&gt;, a carpooling platform. Here are the pitfalls that actually mattered, not the generic "JWT is bad, use sessions" takes you see everywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The algorithm confusion trap
&lt;/h2&gt;

&lt;p&gt;JWTs let the token itself declare which algorithm was used to sign it (the &lt;code&gt;alg&lt;/code&gt; header). If your verification code blindly trusts that header instead of pinning the expected algorithm, you've handed an attacker a way to potentially downgrade your signing scheme — including the infamous &lt;code&gt;alg: none&lt;/code&gt; case, where some libraries will accept a token as "verified" with no signature at all if you don't explicitly guard against it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix:&lt;/strong&gt; always specify the expected algorithm explicitly when verifying, never read it from the token. Most modern JWT libraries support this — you pass the algorithm(s) you accept as a parameter to the verify call instead of letting the library infer it from the token.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Treating the payload as safe to trust blindly
&lt;/h2&gt;

&lt;p&gt;A JWT's payload isn't encrypted — it's base64-encoded and signed. Anyone can decode and read it (try it on jwt.io). The signature guarantees the payload &lt;em&gt;wasn't tampered with&lt;/em&gt;, not that it's &lt;em&gt;secret&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In a gateway context like Aegis, this matters even more — the gateway is the thing forwarding requests to internal services based on what's in that token. If those downstream services also blindly trust decoded claims without re-verifying anything, you've built an implicit trust chain that's only as strong as its weakest link.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix:&lt;/strong&gt; never put sensitive data (passwords, full PII, secrets) in the payload. And if multiple services are involved, be explicit about which layer is responsible for verification — don't assume "the gateway already checked it" is enough context for a service to skip its own validation of &lt;em&gt;what&lt;/em&gt; the token grants access to.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Long-lived tokens with no revocation story
&lt;/h2&gt;

&lt;p&gt;A JWT's whole appeal is that it's stateless — the server doesn't need to look anything up to verify it's valid. That's also the problem: if a token leaks or a user needs to be logged out immediately (password change, account compromise), there's no built-in way to invalidate a JWT before it naturally expires.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix that actually works in practice:&lt;/strong&gt; short-lived access tokens (minutes, not days) paired with a refresh token that &lt;em&gt;is&lt;/em&gt; checked against a store server-side. That gives you statelessness for the common case (verifying access) while still having a kill switch for the rare case (revoking access).&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Not handling clock skew
&lt;/h2&gt;

&lt;p&gt;If your auth server and your resource server aren't perfectly clock-synced (and in a distributed system, they often aren't), a token can appear expired or "not yet valid" a few seconds early or late even though it's actually fine. This is a subtle one because it doesn't show up in dev — it shows up in production, intermittently, and looks like a flaky bug.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix:&lt;/strong&gt; most JWT libraries support a small clock tolerance/leeway setting (a few seconds) specifically for this. Use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Where you store the token client-side
&lt;/h2&gt;

&lt;p&gt;This one's more about the client than the token itself, but it's the pitfall that gets talked about the least in backend-focused JWT content. Storing a JWT in &lt;code&gt;localStorage&lt;/code&gt; makes it readable by any JS running on the page — including injected scripts from an XSS vulnerability elsewhere in your app. &lt;code&gt;httpOnly&lt;/code&gt; cookies aren't readable by JS at all, which closes that specific hole, but open you up to CSRF instead if you're not careful with &lt;code&gt;SameSite&lt;/code&gt; settings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fix:&lt;/strong&gt; there's no universally "correct" answer here — it's a genuine tradeoff, and the right choice depends on your app's specific risk surface. What matters is picking one deliberately instead of defaulting to &lt;code&gt;localStorage&lt;/code&gt; because it's the easiest to reach for.&lt;/p&gt;




&lt;p&gt;None of these are exotic. They're the kind of thing that's easy to know about in the abstract and still get wrong in the specifics — because the specifics depend on your actual architecture (gateway vs. monolith, one service vs. many, how sensitive the data behind the token actually is).&lt;/p&gt;

&lt;p&gt;If you're implementing JWT auth for the first time, I'd rather you spend time thinking through these five than reaching for the first "add JWT auth in 10 lines" tutorial you find.&lt;/p&gt;

</description>
      <category>jsonwebtoken</category>
      <category>node</category>
      <category>security</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
