DEV Community

Discussion on: In Defense of Defensive Programming

Collapse
 
huncyrus profile image
huncyrus

Two story for defensive programming.

1.) Personal story
12 years ago, I wrote a check and validation heavy small framework w/ PHP 5, what never trusted anything, paired and hashed everything and checked everything always. The service still running with it, and I did not touched the code in the previous 5 years at all. So there are a bunch of things what is deprecated because of PHPv7. The service got approx 8-10 million of bot inquiry (ddos, checks, typical injections and generic attacks) per year, and because of the heavy security solutions, the service still up and running, had zero downtime nor breach (what I am proud of).

  1. company story Many years ago, when I started to work at the company where I still workin', I was the only one who designed, planned, built everything as defensive, as possible under c++/js/php. My colleagues does not like it, so they started to remove most of my modules and applications/services. After a few years, GDPR and security breach hitted the company, because of the weakened security. A few quote:
    • "You have to trust the input what other internal service give you, because we did it!"
    • "You only need SSL/HTTPS for web security!"
    • "You don't need ACL in the portal!"
    • "You can not breach a HTTPS connection"
    • "The perfect load for the server is around 90% always!"
    • "We do not need scalability, we just click on the cloud dashboard for more cpu and memory!"
    • "You do not have to double sanitize logined user input, we trust our partners after they login!"

So now everything on fire, and the company will hire a devop/sysop and security expert company for huge amount of money to review everything and point out how to fix the infrastructure and codes.
Except my parts. What they did not touched, they are still safe, not compromised and has been updated by going through OWASP and other security lists (since there are a few other also).

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

Awesome stories! And this hits upon a point that I didn't really address in my article. Mainly, that when you do those "acid tests" on inputs, it doesn't just make your code sturdier in the short term. That bulletproof code tends to stay bulletproof for a very long time.

I've seen some very old, very stable mainframe code - the kinda code that was written decades ago and is still running. And that code tends to use a lot of these voracious ("defensive") techniques.