Exposing database IDs – security risk?

Exposing database IDs – security risk?

There are risks associated with exposing database identifiers. On the other hand, it would be extremely burdensome to design a web application without exposing them at all. Thus, its important to understand the risks and take care to address them.

The first danger is what OWASP called insecure direct object references. If someone discovers the id of an entity, and your application lacks sufficient authorization controls to prevent it, they can do things that you didnt intend.

Here are some good rules to follow:

  1. Use role-based security to control access to an operation. How this is done depends on the platform and framework youve chosen, but many support a declarative security model that will automatically redirect browsers to an authentication step when an action requires some authority.
  2. Use programmatic security to control access to an object. This is harder to do at a framework level. More often, it is something you have to write into your code and is therefore more error prone. This check goes beyond role-based checking by ensuring not only that the user has authority for the operation, but also has necessary rights on the specific object being modified. In a role-based system, its easy to check that only managers can give raises, but beyond that, you need to make sure that the employee belongs to the particular managers department.

There are schemes to hide the real identifier from an end user (e.g., map between the real identifier and a temporary, user-specific identifier on the server), but I would argue that this is a form of security by obscurity. I want to focus on keeping real cryptographic secrets, not trying to conceal application data. In a web context, it also runs counter to widely used REST design, where identifiers commonly show up in URLs to address a resource, which is subject to access control.

Another challenge is prediction or discovery of the identifiers. The easiest way for an attacker to discover an unauthorized object is to guess it from a numbering sequence. The following guidelines can help mitigate that:

  1. Expose only unpredictable identifiers. For the sake of performance, you might use sequence numbers in foreign key relationships inside the database, but any entity you want to reference from the web application should also have an unpredictable surrogate identifier. This is the only one that should ever be exposed to the client. Using random UUIDs for these is a practical solution for assigning these surrogate keys, even though they arent cryptographically secure.

  2. One place where cryptographically unpredictable identifiers is a necessity, however, is in session IDs or other authentication tokens, where the ID itself authenticates a request. These should be generated by a cryptographic RNG.

While not a data security risk this is absolutely a business intelligence security risk as it exposes both data size and velocity. Ive seen businesses get harmed by this and have written about this anti-pattern in depth. Unless youre just building an experiment and not a business Id highly suggest keeping your private ids out of public eye. https://medium.com/lightrail/prevent-business-intelligence-leaks-by-using-uuids-instead-of-database-ids-on-urls-and-in-apis-17f15669fd2e

Exposing database IDs – security risk?

It depends on what the IDs stand for.

Consider a site that for competitive reason dont want to make public how many members they have but by using sequential IDs reveals it anyway in the URL: http://some.domain.name/user?id=3933

On the other hand, if they used the login name of the user instead: http://some.domain.name/user?id=some they havent disclosed anything the user didnt already know.

Leave a Reply

Your email address will not be published. Required fields are marked *