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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

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

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      How Red Hat just quietly, radically transformed enterprise server Linux

      June 2, 2025

      OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

      June 2, 2025

      The best Linux VPNs of 2025: Expert tested and reviewed

      June 2, 2025

      One of my favorite gaming PCs is 60% off right now

      June 2, 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

      `document.currentScript` is more useful than I thought.

      June 2, 2025
      Recent

      `document.currentScript` is more useful than I thought.

      June 2, 2025

      Adobe Sensei and GenAI in Practice for Enterprise CMS

      June 2, 2025

      Over The Air Updates for React Native Apps

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

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025
      Recent

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025

      Microsoft says Copilot can use location to change Outlook’s UI on Android

      June 2, 2025

      TempoMail — Command Line Temporary Email in Linux

      June 2, 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

    How Red Hat just quietly, radically transformed enterprise server Linux

    June 2, 2025
    News & Updates

    OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-48070 – Plane UserSerializer Account Takeover Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    yachalk – terminal string styling done right

    Development

    NodeSource Adopts gRPC: A Step Toward Greater Resilience, Scalability, and Open Standards

    Development

    The best Galaxy Z Flip 6 cases of 2024

    Development

    Highlights

    Development

    Researches Discovers New Android Banking Trojan ‘Brokewell’ Disguised as Chrome Update

    April 28, 2024

    CRIL Researchers observed a new android banking trojan ‘Brokewell,’ being distributed through a phishing site…

    Best Figma Mockups Collection: Devices, Print, Products & More

    June 18, 2024

    The AI Fix #37: DeepSeek is a security dumpster fire, and quicksand for AI

    February 25, 2025

    Microsoft April 2025 Patch Tuesday: Fixes for 134 security vulnerabilities, one exploited Zero-Day

    April 9, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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