Security: Do it the WordPress Way

Pretty regularly, people complain that I’m being pedantic and stubborn about security. They argue that their home-grown filters and regular expression checks are more than sufficient for sanitizing and validating data. Invariably I tell them “WordPress has a function for that. Please use it. Don’t create your own.”

Most of the time, this gets a grumbling acquiescence. On the rare occasions it doesn’t I get a pretentious email telling me the developer has been working in tech and computers for 10 to 14 years (10 is most common) and they’ve released code before and they know what they’re talking about.

You know what? You do. Most of the time the code you people come up with looks fine. But after 14 years working for a bank and around 7 of doing WordPress plugin reviews and nearly 5 of working for a web host, I’ve got a different point of view than you do. I have a mountain of experience that is hard to match. This doesn’t mean I’m the smartest person down the pike, don’t get me wrong. But I’ve seen a lot. I’m like that Farmer’s guy.

We know a lot because we’ve seen a lot

With all the things I’ve seen, I’ve developed a very different set of criteria for security beyond just “Is it secure?”

I know the following:

  • Someone is always going to be smarter than I am.
  • Hackers are incredibly dedicated to being shits.
  • Users are incredibly inventive with usage.
  • People don’t look before they click.

I ask the following:

  • Is this the fastest (most efficient) way to sanity check the data?
  • Is it being validated to prevent PEBUaK errors?
  • How easy will this be to fix when I find a problem?
  • How much damage will this cause if it breaks?

To WordPress or Not to WordPress

When I have a choice of reinventing the wheel or using what WordPress already sanitizes for me, I will always pick WordPress. Every. Single. Time. This is for a very practical reason.

  • People don’t upgrade plugins.
  • People do upgrade WordPress security releases.

By default everyone using WordPress gets security releases and they get them within 12 hours (more or less). Yes, people can and do disable that, but they’re the minority. When you talk about securing 26% of the Internet, the ability to patch people quickly is paramount. WordPress knows this.

If I’m using the sanitize_name() function from WordPress and not a hand-hewn regular expression, then if there’s a flaw in that function I know it will be patched and the patch pushed and my users made safe. If I make it myself, I have to pray everyone upgrades.

Excellence Uses The Right Tools

Think of it this way. If your plugin becomes a popular plugin and 2% of WordPress users use it, then that’s .5% of all sites on the Internet using your plugin. Which is better for them? Which is safer? Do you rely on the tried and true, tested sanitization via WordPress which will emergency self-update or your own code?

Once you think of it not as “How can I make my code succeed?” but “How can I build trust for 27% of the internet?” it’s clearer.

Rely on WordPress and not your own code whenever possible. It’s smarter. It’s safer. It has the long-term view to take you from a newbie to a well-known tool. If there’s a security hole in WordPress, everyone will work to fix it, and it will get out to more people than just your users.





One response to “Security: Do it the WordPress Way”

  1. Ryan Hellyer Avatar

    And if someone thinks their sanitisation system is better than one in core, they should be committing that code to core, not to their plugin.

%d bloggers like this: