<?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>Forem: Tấn Trương</title>
    <description>The latest articles on Forem by Tấn Trương (@tanx-1811).</description>
    <link>https://forem.com/tanx-1811</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3893313%2F53ff2739-e446-45c2-ba89-7e488b320354.jpg</url>
      <title>Forem: Tấn Trương</title>
      <link>https://forem.com/tanx-1811</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tanx-1811"/>
    <language>en</language>
    <item>
      <title>When OTP Becomes a Spam Goldmine — And How to Stop It with One Shift</title>
      <dc:creator>Tấn Trương</dc:creator>
      <pubDate>Fri, 24 Apr 2026 01:27:51 +0000</pubDate>
      <link>https://forem.com/tanx-1811/when-otp-becomes-a-spam-goldmine-and-how-to-stop-it-with-one-shift-1eb4</link>
      <guid>https://forem.com/tanx-1811/when-otp-becomes-a-spam-goldmine-and-how-to-stop-it-with-one-shift-1eb4</guid>
      <description>&lt;h1&gt;
  
  
  When OTP Becomes a Spam Goldmine — And How to Stop It with One Shift
&lt;/h1&gt;

&lt;p&gt;There’s a paradox in modern authentication that anyone who has worked with OTP systems long enough will eventually notice:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The very mechanism designed to secure users can also be weaponized at scale.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 1 — The Zalo Story
&lt;/h2&gt;

&lt;p&gt;Take a platform like Zalo.&lt;/p&gt;

&lt;p&gt;They fully understand how OTP can be abused — because they’ve lived through it. There was a time when users were heavily spammed with OTP messages. Not because the system was weak, but because &lt;strong&gt;the mechanism itself was exploitable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you expose an endpoint that sends OTP → it &lt;em&gt;will&lt;/em&gt; be abused.&lt;/p&gt;

&lt;p&gt;No matter how many rate limits or CAPTCHA layers you add, attackers adapt:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rotate IPs&lt;/li&gt;
&lt;li&gt;Simulate devices&lt;/li&gt;
&lt;li&gt;Distribute requests across sessions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Eventually, the cost of defense becomes higher than the cost of attack.&lt;/p&gt;

&lt;p&gt;So what did they do?&lt;/p&gt;

&lt;p&gt;They shifted the model.&lt;/p&gt;

&lt;p&gt;Instead of sending OTP outward (SMS), they introduced &lt;strong&gt;user-initiated flows&lt;/strong&gt; like inbound voice OTP. No outbound API → no spam vector.&lt;/p&gt;

&lt;p&gt;But here’s the irony.&lt;/p&gt;

&lt;p&gt;As a platform, they reduce OTP abuse.&lt;br&gt;
As a service provider, they still offer ZNS OTP — now costing ~440 VND per message.&lt;/p&gt;

&lt;p&gt;Which reveals an uncomfortable truth:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Outbound OTP is both a security feature and a monetizable surface — even though it’s also the root of the spam problem.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Part 2 — The Real Threat: Cross-App Abuse
&lt;/h2&gt;

&lt;p&gt;Modern OTP spam isn’t sophisticated.&lt;/p&gt;

&lt;p&gt;It’s &lt;em&gt;industrialized&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;There are public tools, tutorials, even ready-to-run scripts. Anyone can do it.&lt;/p&gt;

&lt;p&gt;And the most dangerous part?&lt;/p&gt;

&lt;p&gt;Attackers don’t target just one system.&lt;/p&gt;

&lt;p&gt;They exploit the same OTP logic across hundreds of apps.&lt;/p&gt;

&lt;p&gt;Even if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;App A limits 1 OTP per phone number&lt;/li&gt;
&lt;li&gt;App B does the same&lt;/li&gt;
&lt;li&gt;App C does the same&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An attacker can still trigger:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;100 OTP messages → to the same victim → from 100 different apps&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each request:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Comes from a different IP&lt;/li&gt;
&lt;li&gt;Uses a different device fingerprint&lt;/li&gt;
&lt;li&gt;Runs in a separate session&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From the perspective of each system, everything looks legitimate.&lt;/p&gt;

&lt;p&gt;So traditional defenses fail — not because they’re bad, but because:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;You’re trying to solve an ecosystem-level problem at a system level.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Part 3 — The Global Product Reality
&lt;/h2&gt;

&lt;p&gt;If you’re building for international users, SMS OTP becomes even worse.&lt;/p&gt;

&lt;p&gt;You quickly realize this isn’t just a technical problem — it’s a regulatory maze:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some countries require sender registration&lt;/li&gt;
&lt;li&gt;Some filter or rewrite content&lt;/li&gt;
&lt;li&gt;Some delay messages unpredictably&lt;/li&gt;
&lt;li&gt;Some block entire routes without notice&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At scale, OTP delivery turns into a &lt;strong&gt;compliance + telecom negotiation problem&lt;/strong&gt;, not engineering.&lt;/p&gt;




&lt;h2&gt;
  
  
  Part 4 — The One Shift That Changes Everything
&lt;/h2&gt;

&lt;p&gt;Here’s the core insight:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Stop sending OTP. Start making users request it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This sounds trivial, but it changes the entire threat model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Old model (vulnerable)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Server sends OTP → user receives&lt;/li&gt;
&lt;li&gt;Attack surface = public API&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  New model (resilient)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;User initiates authentication&lt;/li&gt;
&lt;li&gt;Server responds only to verified intent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inbound call OTP&lt;/li&gt;
&lt;li&gt;App-based approval (push)&lt;/li&gt;
&lt;li&gt;TOTP (Google Authenticator-style)&lt;/li&gt;
&lt;li&gt;Deep link / magic link&lt;/li&gt;
&lt;li&gt;Device binding&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the attacker has a harder problem:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They must control the user interaction channel&lt;/li&gt;
&lt;li&gt;Not just spam an API&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s a completely different game.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;OTP spam is not a bug.&lt;/p&gt;

&lt;p&gt;It’s a &lt;strong&gt;business + architecture side-effect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As long as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sending OTP is easy&lt;/li&gt;
&lt;li&gt;And costs are externalized&lt;/li&gt;
&lt;li&gt;And APIs remain public&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It will continue to be abused.&lt;/p&gt;

&lt;p&gt;You can keep adding layers (rate limit, CAPTCHA, fingerprinting)...&lt;br&gt;
Or you can change the model entirely.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sometimes the most effective fix isn’t optimization — it’s elimination.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;If you're building auth for a real-time product or scaling globally, this is not an edge case.&lt;/p&gt;

&lt;p&gt;It's inevitable.&lt;/p&gt;

&lt;p&gt;The only question is:&lt;br&gt;
&lt;strong&gt;Do you design for it early — or react when it becomes a problem?&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Authentication Mechanisms: JWT, OAuth, and Single Sign-On (SSO)</title>
      <dc:creator>Tấn Trương</dc:creator>
      <pubDate>Thu, 23 Apr 2026 02:35:34 +0000</pubDate>
      <link>https://forem.com/tanx-1811/authentication-mechanisms-jwt-oauth-and-single-sign-on-sso-1eo3</link>
      <guid>https://forem.com/tanx-1811/authentication-mechanisms-jwt-oauth-and-single-sign-on-sso-1eo3</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In modern application development, securing user authentication is a foundational requirement. As systems scale and threats become more sophisticated, choosing the right authentication and authorization strategy becomes critical.&lt;/p&gt;

&lt;p&gt;Three widely adopted approaches are &lt;strong&gt;JWT (JSON Web Token)&lt;/strong&gt;, &lt;strong&gt;OAuth 2.0&lt;/strong&gt;, and &lt;strong&gt;Single Sign-On (SSO)&lt;/strong&gt;. While often mentioned together, they solve different problems and are frequently used in combination.&lt;/p&gt;

&lt;p&gt;This article provides a clear, practical comparison along with system flows and best practices.&lt;/p&gt;




&lt;h2&gt;
  
  
  Authentication vs Authorization
&lt;/h2&gt;

&lt;p&gt;Before diving deeper:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt;: Who are you?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authorization&lt;/strong&gt;: What are you allowed to do?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A secure system must enforce both.&lt;/p&gt;




&lt;h2&gt;
  
  
  JWT (JSON Web Token)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is JWT?
&lt;/h3&gt;

&lt;p&gt;JWT is a compact, URL-safe token used to transmit claims between client and server. It is commonly used for stateless authentication.&lt;/p&gt;

&lt;h3&gt;
  
  
  Structure
&lt;/h3&gt;

&lt;p&gt;A JWT consists of three parts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Header.Payload.Signature
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Header&lt;/strong&gt;: Algorithm (HS256, RS256)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payload&lt;/strong&gt;: Claims (user_id, role, exp)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Signature&lt;/strong&gt;: Integrity verification&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Flow
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User → Login → Server
Server → Generate JWT → Client
Client → Attach JWT → API
API → Verify JWT → Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Stateless (no session storage)&lt;/li&gt;
&lt;li&gt;Scales well in microservices&lt;/li&gt;
&lt;li&gt;Fast verification&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Hard to revoke&lt;/li&gt;
&lt;li&gt;Token leakage risk&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Best Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Short-lived access tokens&lt;/li&gt;
&lt;li&gt;Use HTTP-only cookies&lt;/li&gt;
&lt;li&gt;Avoid sensitive payload data&lt;/li&gt;
&lt;li&gt;Implement refresh token strategy&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  OAuth 2.0
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is OAuth?
&lt;/h3&gt;

&lt;p&gt;OAuth 2.0 is a protocol for delegated authorization. It allows applications to access user data without exposing credentials.&lt;/p&gt;

&lt;h3&gt;
  
  
  Roles
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Resource Owner (User)&lt;/li&gt;
&lt;li&gt;Client (App)&lt;/li&gt;
&lt;li&gt;Authorization Server&lt;/li&gt;
&lt;li&gt;Resource Server&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Flow
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User → Login + Consent → Authorization Server
Authorization Server → Access Token → Client
Client → API Request → Resource Server
Resource Server → Validate Token → Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Grant Types
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Authorization Code (recommended)&lt;/li&gt;
&lt;li&gt;Client Credentials&lt;/li&gt;
&lt;li&gt;Implicit (deprecated)&lt;/li&gt;
&lt;li&gt;Password (legacy)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Best Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use Authorization Code + PKCE&lt;/li&gt;
&lt;li&gt;Never expose client secret&lt;/li&gt;
&lt;li&gt;Validate redirect URIs&lt;/li&gt;
&lt;li&gt;Use refresh tokens&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Single Sign-On (SSO)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is SSO?
&lt;/h3&gt;

&lt;p&gt;SSO allows users to log in once and access multiple applications without re-authentication.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flow
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        [ SSO Provider ]
               │
     ┌─────────┼─────────┐
     ▼         ▼         ▼
  App A     App B     App C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Technologies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;SAML (enterprise)&lt;/li&gt;
&lt;li&gt;OpenID Connect (modern, built on OAuth)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Pros
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Better user experience&lt;/li&gt;
&lt;li&gt;Centralized access control&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Single point of failure&lt;/li&gt;
&lt;li&gt;Higher complexity&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Best Practices
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Enforce MFA&lt;/li&gt;
&lt;li&gt;Implement RBAC&lt;/li&gt;
&lt;li&gt;Monitor and audit logs&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Comparison Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Criteria&lt;/th&gt;
&lt;th&gt;JWT&lt;/th&gt;
&lt;th&gt;OAuth 2.0&lt;/th&gt;
&lt;th&gt;SSO&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Purpose&lt;/td&gt;
&lt;td&gt;Authentication&lt;/td&gt;
&lt;td&gt;Authorization&lt;/td&gt;
&lt;td&gt;Central Authentication&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;State&lt;/td&gt;
&lt;td&gt;Stateless&lt;/td&gt;
&lt;td&gt;Token-based&lt;/td&gt;
&lt;td&gt;Session-based&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Use Case&lt;/td&gt;
&lt;td&gt;APIs, microservices&lt;/td&gt;
&lt;td&gt;Third-party access&lt;/td&gt;
&lt;td&gt;Multi-app systems&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Complexity&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scalability&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Revocation&lt;/td&gt;
&lt;td&gt;Difficult&lt;/td&gt;
&lt;td&gt;Managed by auth server&lt;/td&gt;
&lt;td&gt;Centralized&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Real-World Architecture (Recommended)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client
  │
  ├── Access Token (JWT - short-lived)
  ├── Refresh Token (stored in DB)
  │
Backend
  ├── Verify JWT
  ├── Manage session / revoke
  ├── Integrate OAuth providers
  │
SSO Provider (optional)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key Ideas
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use JWT for performance&lt;/li&gt;
&lt;li&gt;Store refresh tokens in database (revocable)&lt;/li&gt;
&lt;li&gt;Route all API calls through backend&lt;/li&gt;
&lt;li&gt;Track device/session for security&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There is no one-size-fits-all solution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;JWT&lt;/strong&gt; for stateless APIs&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;OAuth 2.0&lt;/strong&gt; for third-party integrations&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;SSO&lt;/strong&gt; for unified login across systems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In practice, modern systems combine all three to achieve both security and scalability.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>security</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
