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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      7 MagSafe accessories that I recommend every iPhone user should have

      June 1, 2025

      I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

      June 1, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 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

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

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

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025
      Recent

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 22/2025

      June 1, 2025

      Rilasciata PorteuX 2.1: Novità e Approfondimenti sulla Distribuzione GNU/Linux Portatile Basata su Slackware

      June 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Device Detection

    CodeSOD: Device Detection

    February 4, 2025

    There are a lot of cases where the submission is “this was server side generated JavaScript and they were loading constants”. Which, honestly, is a WTF, but it isn’t interesting code. Things like this:

    if (false === true)
    {
    	// do stuff
    }
    

    That’s absolutely the wrong way to do that, and I hate it, but there’s just so many times you can say, “send server-side values to the client as an object, not inline”.

    But Daniel‘s electrical provider decided to come up with an example of this that really takes it to the next level of grossness.

       var isMobile = "" === "true";
       var isAndroid = "" === "true";
       var isIPad = "" === "true";
       var isIPhone = "" === "true";
    

    For starters, they’re doing device detection on the server side, which isn’t the worst possible idea, but it means they’re relying on header fields or worse: the user agent string. Maybe they’re checking the device resolution. The fact that they’re naming specific devices instead of browser capabilities hints at a terrible hackjob of reactive webdesign- likely someone wrote a bunch of JavaScript that alters the desktop stylesheet to cram the desktop site onto a mobile device. But that’s just background noise.

    Look at that code.

    Hostinger

    First, we’ve got some lovely order-of-operations abuse: === has higher precedence than =, which makes sense but hardly makes this code readable. The first time I saw this, my brain wanted the assignment to happen first.

    But what’s really special to me is the insistence on making this stringly typed. They control both sides of the code, so they could have just done booleans on both sides. And sure, there’s a world where they’re just dumb, or didn’t trust their templating engine to handle that well.

    I’ve seen enough bad code, though, to have a different suspicion. I can’t confirm it, but c’mon, you know in your hearts this is true: the function which is doing device detection returns a string itself, and that string isn’t always a boolean for some reason. So they needed to wrap the output in quotes, because that was the only way to make sure that the JavaScript actually could be executed without a syntax error.

    I can’t be sure that’s true from this little snippet. But look at this code, and tell me that someone didn’t make that mistake.

    [Advertisement]
    Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleArmSoM CM5: Powerful Replacement for Raspberry Pi CM4
    Next Article Power Checklist: New Workstation

    Related Posts

    News & Updates

    7 MagSafe accessories that I recommend every iPhone user should have

    June 1, 2025
    News & Updates

    I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

    June 1, 2025
    Leave A Reply Cancel Reply

    Hostinger

    Continue Reading

    If you’re not working on quantum-safe encryption now, it’s already too late

    News & Updates

    Dissolving the line between design and engineering

    Web Development

    CVE-2025-5080 – Tenda FH451 Stack-Based Buffer Overflow

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-4341 – D-Link DIR-880L Command Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Development

    Role of AI-driven Autonomous Testing in Software QA

    April 28, 2025

    The blog discusses how AI is upscaling quality assurance through autonomous testing, where systems independently create, run, and maintain test cases. This approach reduces manual work, boosts accuracy, and adapts to changes in real-time.
    The post Role of AI-driven Autonomous Testing in Software QA first appeared on TestingXperts.

    CVE-2025-47283 – Gardener gardenlet Administrative Privilege Escalation Vulnerability

    May 19, 2025

    git-chglog – CHANGELOG generator implemented in Go

    July 8, 2024

    CVE-2025-47181 – Microsoft Edge Link Following Privilege Escalation Vulnerability

    May 22, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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