Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      From Data To Decisions: UX Strategies For Real-Time Dashboards

      September 13, 2025

      Honeycomb launches AI observability suite for developers

      September 13, 2025

      Low-Code vs No-Code Platforms for Node.js: What CTOs Must Know Before Investing

      September 12, 2025

      ServiceNow unveils Zurich AI platform

      September 12, 2025

      Building personal apps with open source and AI

      September 12, 2025

      What Can We Actually Do With corner-shape?

      September 12, 2025

      Craft, Clarity, and Care: The Story and Work of Mengchu Yao

      September 12, 2025

      Distribution Release: Q4OS 6.1

      September 12, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Learning from PHP Log to File Example

      September 13, 2025
      Recent

      Learning from PHP Log to File Example

      September 13, 2025

      Online EMI Calculator using PHP – Calculate Loan EMI, Interest, and Amortization Schedule

      September 13, 2025

      Package efficiency and dependency hygiene

      September 13, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Dmitry — The Deep Magic

      September 13, 2025
      Recent

      Dmitry — The Deep Magic

      September 13, 2025

      Right way to record and share our Terminal sessions

      September 13, 2025

      Windows 11 Powers Up WSL: How GPU Acceleration & Kernel Upgrades Change the Game

      September 13, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: IsValidToken

    CodeSOD: IsValidToken

    July 29, 2025

    To ensure that several services could only be invoked by trusted parties, someone at Ricardo P‘s employer had the brilliant idea of requiring a token along with each request. Before servicing a request, they added this check:

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-built_in">bool</span> <span class="hljs-title">IsValidToken</span>(<span class="hljs-params"><span class="hljs-built_in">string</span>? token</span>)</span>
    {
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">string</span>.Equals(<span class="hljs-string">"xxxxxxxx-xxxxxx+xxxxxxx+xxxxxx-xxxxxx-xxxxxx+xxxxx"</span>, token)) <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }
    

    The token is anonymized here, but it’s hard-coded into the code, because checking security tokens into source control, and having tokens that never expire has never caused anyone any trouble.

    Which, in the company’s defense, they did want the token to expire. The problem there is that they wanted to be able to roll out the new token to all of their services over time, which meant the system had to be able to support both the old and new token for a period of time. And you know exactly how they handled that.

    <span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-built_in">bool</span> <span class="hljs-title">IsValidToken</span>(<span class="hljs-params"><span class="hljs-built_in">string</span>? token</span>)</span>
    {
        <span class="hljs-keyword">if</span> (<span class="hljs-built_in">string</span>.Equals(<span class="hljs-string">"xxxxxxxx-xxxxxx+xxxxxxx+xxxxxx-xxxxxx-xxxxxx+xxxxx"</span>, token)) <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-built_in">string</span>.Equals(<span class="hljs-string">"yyyyyyy-yyyyyy+yyyyy+yyyyy-yyyyy-yyyyy+yyyy"</span>, token)) <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }
    

    For a change, I’m more mad about this insecurity than the if(cond) return true pattern, but boy, I hate that pattern.

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFirefox Add-Ons Website Revamps Listing Pages
    Next Article XO – configurable ESLint wrapper

    Related Posts

    News & Updates

    Building personal apps with open source and AI

    September 12, 2025
    News & Updates

    What Can We Actually Do With corner-shape?

    September 12, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2025-53610 – Cisco WebEx Meeting Server Unvalidated Redirect

    Common Vulnerabilities and Exposures (CVEs)

    AMD will power every next-gen Xbox as Microsoft moves its console closer to a Windows PC

    Operating Systems

    The Microsoft Store on Windows 11 is actually great now — here’s why you should be using it in 2025

    News & Updates

    CVE-2025-36026 – IBM Datacap Insecure Cookie Handling Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    News & Updates

    Stack years of Microsoft 365 — this deal would have been a bargain in 2013

    July 11, 2025

    Microsoft 365 is down to $64.99 for Personal and $99.99 for Family. You can stack…

    Stop waiting for an emergency to upgrade your home’s tech – there’s a better way

    April 18, 2025

    DOOM: The Dark Ages is already on sale ahead of its release next week — Rip and tear into savings with this deal

    May 6, 2025

    Minecraft’s mob vote loser just made a surprise comeback — and it brought brand new gear to the Bedrock Preview with it

    July 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.