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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 9, 2025

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

      May 9, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 9, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 9, 2025

      Your password manager is under attack, and this new threat makes it worse: How to defend yourself

      May 9, 2025

      EcoFlow’s new backyard solar energy system starts at $599 – no installation crews or permits needed

      May 9, 2025

      Why Sonos’ cheapest smart speaker is one of my favorites – even a year after its release

      May 9, 2025

      7 productivity gadgets I can’t live without (and why they make such a big difference)

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

      Tap into Your PHP Potential with Free Projects at PHPGurukul

      May 9, 2025
      Recent

      Tap into Your PHP Potential with Free Projects at PHPGurukul

      May 9, 2025

      Preparing for AI? Here’s How PIM Gets Your Data in Shape

      May 9, 2025

      A Closer Look at the AI Assistant of Oracle Analytics

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

      kew v3.2.0 improves internet radio support and more

      May 9, 2025
      Recent

      kew v3.2.0 improves internet radio support and more

      May 9, 2025

      GNOME Replace Totem Video Player with Showtime

      May 9, 2025

      Placemark is a web-based tool for geospatial data

      May 9, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: A Ruby Encrusted Footgun

    CodeSOD: A Ruby Encrusted Footgun

    April 1, 2025

    Many years ago, JP joined a Ruby project. This was in the heyday of Ruby, when every startup on Earth was using it, and if you weren’t building your app on Rails, were you even building an app?

    Now, Ruby offers a lot of flexibility. One might argue that it offers too much flexibility, especially insofar as it permits “monkey patching”: you can always add new methods to an existing class, if you want. Regardless of the technical details, JP and the team saw that massive flexibility and said, “Yes, we should use that. All of it!”

    As these stories usually go, that was fine- for awhile. Then one day, a test started failing because a class name wasn’t defined. That was already odd, but what was even odder is that when they searched through the code, that class name wasn’t actually used anywhere. So yes, there was definitely no class with that name, but also, there was no line of code that was trying to instantiate that class. So where was the problem?

    def controller_class(name)
      "#{settings.app_name.camelize}::Controllers".constantize.const_get("#{name.to_s.camelize}")
    end
    
    def model_class(name)
      "#{settings.app_name.camelize}".constantize.const_get("#{name.to_s.camelize}")
    end
    
    def resource_class(name)
      "#{settings.app_name.camelize}Client".constantize.const_get("#{name.to_s.camelize}")
    end
    

    It happened because they were dynamically constructing the class names from a settings field. And not just in this handful of lines- this pattern occurred all over the codebase. There were other places where it referenced a different settings field, and they just hadn’t encountered the bug yet, but knew that it was only a matter of time before changing a settings file was going to break more functionality in the application.

    They wisely rewrote these sections to not reference the settings, and dubbed the pattern the “Caramelize Pattern”. They added that to their coding standards as a thing to avoid, and learned a valuable lesson about how languages provide footguns.

    Since today’s April Fool’s Day, consider the prank the fact that everyone learned their lesson and corrected their mistakes. I suppose that has to happen at least sometimes.

    [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 ArticleHow to Create Ghibli-Inspired Art Videos Using Snapchat?
    Next Article ArchiveKeep keeps your files archived in multiple places

    Related Posts

    News & Updates

    Your password manager is under attack, and this new threat makes it worse: How to defend yourself

    May 9, 2025
    News & Updates

    EcoFlow’s new backyard solar energy system starts at $599 – no installation crews or permits needed

    May 9, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    DataVisT5: A Powerful Pre-Trained Language Model for Seamless Data Visualization Tasks

    Development

    How to use Visual Intelligence on an iPhone 16 to identify unknown objects

    News & Updates

    Amazon just confirmed its July Prime Day sale will be back, despite looming tariffs

    News & Updates

    Leveraging Tags with Dynamic Test Suite Collection in Katalon Studio

    Development
    Hostinger

    Highlights

    Development

    Google Takes Down Influence Campaigns Tied to China, Indonesia, and Russia

    June 10, 2024

    Google has revealed that it took down 1,320 YouTube channels and 1,177 Blogger blogs as…

    Solving the Top 6 Mobile Automation Challenges Fast (DevAssure Guide)

    March 16, 2025

    CapCut copycats are on the prowl

    April 18, 2025

    ACSC, CISA, FBI and NSA Unite for New Event Logging and Threat Detection Guide

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

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