36

I see systems that use database prefixes. Some call it a security feature. Some call it a way to have multiple installations in one database.

The main pro is that it's harder to guess the whole table name. On the other hand, if you have some kind of access to the database I would say you could figure out the scheme/table list.

Is it a viable security feature?

janw
  • 463
  • 4
  • 5
  • 55
    Security by obscurity is never real security. – BadSkillz Apr 05 '16 at 08:56
  • 3
    Only more secure if your only attack vector on the database is your child's name... – Michael Apr 05 '16 at 16:09
  • 5
    I'm just guessing but I think convention of database prefix started because of shared hosting. Many web host offer only 1 DB on cheaper plans. Having multiple site use same DB by prefixing table is the only way to get across this limitation. –  Apr 05 '16 at 17:35

4 Answers4

69

This is security through obscurity. While it might not hurt you in all cases, on it's own it does not provide viable security. Do not rely on this as your protection.

A short parable

Let's say you keep your money in a jar labeled MONEY in your house. Since you know you sometimes forget to lock the door when you leave the house, you relabel the jar COOKIESto prevent a thief from finding it. Would you feel more secure now? Sure, a very lazy, dumb thief might miss it, but you would not have to be a master thief to steal your money. Wouldn't it be better to just remember to lock the door instead?

Back to the computer world

Let's say you have an old phpBB installation with an SQL injection vulnerability. By default the tables are prefixed by phpbb_. You change this to obscure_. Will this help you?

A naive scan might fail to find hard coded table names (like phpbb_users with all the passwords), and therefore fail. But even a script kiddie could run a script that runs a SHOW TABLES and finds your obscure_users. In fact, there are tools that will automatically dump the contents of all your tables through a SQL injection vulnerability.

Conclusion

So what is the lesson here? While changing table prefixes (relabeling the jar) might perhaps protect you from the most basic dumb automated attack (the stupid, lazy thief), you would still be vulnerable to simple attacks performed by script kiddies (a thief searching through your jars). When you have a real vulnerability like SQL injection, the solution is to fix that vulnerability (lock the door), and not to add a thin veil of obscurity.

That said, a simple precaution that might slow down some attacks might still be worthwhile as "defence in depth" if it has no harmful side effects. Just don't feel safe just because you implement it.

(As an addendum, I should say that running multiple installations in the same database might come with security implications on it's own, depending on the situation.)

Anders
  • 65,582
  • 24
  • 185
  • 221
  • Good balance in your answer! The bottom line is building in resistance to low skill attackers (the dumb thief) is defense in depth, and if it's a simple process with no other side effects then it is hard to argue it's not worthwhile. – Jeff Meden Apr 05 '16 at 13:06
  • 10
    "While it might not hurt you in all cases" ... Why would this hurt you in any case? I see no reason why making a malicious user's work more difficult (no matter by how little) is a negative. I agree this is not security by the way, but it's wrong to discourage it. – James Apr 05 '16 at 13:33
  • 3
    @b3njamin I am talking about security through obscurity in general. It is not always harmful, but it can be sometimes. – Anders Apr 05 '16 at 13:37
  • 14
    @b3njamin Because it makes you feel safe while you are not. "Oh ship! It's so late! Where's my keys? Left pocket? Nope. Right one? Nope! Bed? Nope. Oh fudge it, nobody's gonna look into the cookie jar anyway". – Margaret Bloom Apr 05 '16 at 13:48
  • 4
    @b3njamin the only cases I can think it would hurt you are because of existing bad code. For example, I've seen people write wordpress plugins which make direct queries on wp_* tables without going through the framework's abstractions. You can say that's not the fault of the person obscuring the table prefixes, but it's a potential real-world problem. – moopet Apr 05 '16 at 15:59
  • @MargaretBloom Agreed, if this practice makes people 100% safe to the point they set their admin password to 'abc123' then it is harmful, but it's unlikely most of those who take advantage of it do not fall into that category. – James Apr 05 '16 at 16:24
  • I'm more likely to steal your cookies than your money. – Joshua Apr 05 '16 at 23:03
  • 1
    @b3njamin One reason the OP cites is that it enables having multiple instances of the same application in the database. In this case, you would need multiple database user accounts and extremely strict (and cumbersome) access permissions to keep them isolated. For an example, say you fix a SQL injection attack, but because you have a lot of clients, it takes time to upgrade all of the instances. What happens if one of them gets breached in the mean time? In an environment where some developers claim this is a security feature, I'm not inclined to trust that they set up all those users. ;) – jpmc26 Apr 06 '16 at 03:12
  • 1
    @moopet I've seen this. And to me it's an instant delete. It says enough about the plugins quality. I don't want that. – janw Apr 06 '16 at 07:44
  • 4
    ...if it has no harmful side effects... For table prefixes, I would consider the very slight decrease in readability enough to make it not worth it. You're buying pennies worth of security for dollars of clarity. – MGOwen Apr 06 '16 at 23:50
  • @James "making a malicious user's work more difficult (no matter by how little) is a negative" 1) It can have a non trivial implementation cost. The gain can be so minuscule, and will not even be measurable for a targeted attack by a competent attacker. 2) Anything that involves changing software can introduce bugs, and anything that change security relevant code like a server could introduce security vulnerabilities. The risk may be very small for every conceptually simple code change, but changing a lot of lines of code multiplies the risk. – curiousguy Jun 22 '18 at 02:16
  • Making the malicious user's work more difficult sometimes correlates with making the honest user's work more difficult (with poor security measures, the difficulty might be increased by an equal amount). The code might be slightly less readable. The attention might be moved away from the logic of the program to annoying stuff that looks like noise in the code. The people doing code review might lose focus and skip something important.
  • – curiousguy Jun 22 '18 at 02:20