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

      CodeSOD: An Echo In Here in here

      September 19, 2025

      How To Minimize The Environmental Impact Of Your Website

      September 19, 2025

      Progress adds AI coding assistance to Telerik and Kendo UI libraries

      September 19, 2025

      Wasm 3.0 standard is now officially complete

      September 19, 2025

      Development Release: Ubuntu 25.10 Beta

      September 18, 2025

      Development Release: Linux Mint 7 Beta “LMDE”

      September 18, 2025

      Distribution Release: Tails 7.0

      September 18, 2025

      Distribution Release: Security Onion 2.4.180

      September 18, 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

      GenStudio for Performance Marketing: What’s New and What We’ve Learned

      September 19, 2025
      Recent

      GenStudio for Performance Marketing: What’s New and What We’ve Learned

      September 19, 2025

      Agentic and Generative Commerce Can Elevate CX in B2B

      September 19, 2025

      AI Momentum and Perficient’s Inclusion in Analyst Reports – Highlights From 2025 So Far

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

      Denmark’s Strategic Leap Replacing Microsoft Office 365 with LibreOffice for Digital Independence

      September 19, 2025
      Recent

      Denmark’s Strategic Leap Replacing Microsoft Office 365 with LibreOffice for Digital Independence

      September 19, 2025

      Development Release: Ubuntu 25.10 Beta

      September 18, 2025

      Development Release: Linux Mint 7 Beta “LMDE”

      September 18, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Concatenated Validation

    CodeSOD: Concatenated Validation

    August 4, 2025

    User inputs are frequently incorrect, which is why we validate them. So, for example, if the user is allowed to enter an “asset ID” to perform some operation on it, we should verify that the asset ID exists before actually doing the operation.

    Someone working with Capybara James almost got there. Almost.

    <span class="hljs-keyword">private</span> <span class="hljs-type">boolean</span> <span class="hljs-title function_">isAssetIdMatching</span><span class="hljs-params">(String requestedAssetId, String databaseAssetId)</span> {
        <span class="hljs-keyword">return</span> (requestedAssetId + <span class="hljs-string">""</span>).equals(databaseAssetId + <span class="hljs-string">""</span>);
    }
    

    This Java code checks if the requestedAssetId, provided by the user, matches a databaseAssetId, fetched from the database. I don’t fully understand how we get to this particular function. How is the databaseAssetId fetched? If the fetch were successful, how could it not match? I fear they may do this in a loop across all of the asset IDs in the database until they find a match, but I don’t know that for sure, but the naming conventions hint at a WTF.

    The weird thing here, though, is the choice to concatenate an empty string to every value. There’s no logical reason to do this. It certainly won’t change the equality check. I strongly suspect that the goal here was to protect against null values, but it doesn’t work that way in Java. If the string variables are null, this will just throw an exception when you try and concatenate.

    I strongly suspect the developer was more confident in JavaScript, where this pattern “works”.

    I don’t understand why or how this function got here. I’m not the only one. James writes:

    No clue what the original developers were intending with this. It sure was a shocker when we inherited a ton of code like this.

    [Advertisement]
    ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleUnplugging these 7 common household devices helped reduce my electricity bills
    Next Article Tamari – fully-featured recipe manager

    Related Posts

    News & Updates

    Development Release: Ubuntu 25.10 Beta

    September 18, 2025
    News & Updates

    Development Release: Linux Mint 7 Beta “LMDE”

    September 18, 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

    Cyber Brief 25-05 – April 2025

    Security

    Welcome to Manga Office

    Artificial Intelligence

    CVE-2025-47601 – MaxiBlocks Missing Authorization Privilege Escalation

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-47871 – Mattermost Information Disclosure Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Here’s how you can try Audible for $1 per month

    April 23, 2025

    Amazon is offering Audible for $1 per month for three months during their Amazon Book…

    Skywings Marketing – Best SEO Company in Ghaziabad for Proven Digital Growth

    April 17, 2025

    This Lenovo gaming laptop made me ditch my ThinkPad for work – and it’s on sale

    July 7, 2025

    This AMD desktop processor is a beast, and it’s almost 60% off at Amazon

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

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