1

A colleague once mentioned to me that when developing web applications, explicitly using a sequence/auto-increment integer (typically a primary key) to uniquely identify values within a database is a security risk, and that since such keys are often used as "surrogate keys" (e.g., for internally identifying records and relationships between records) the safest way of identify resources is use to domain primary key.

Take the following example.

create table category
(
    category_key serial not null primary key,
    name character varying(255) not null,
    unique(name)
);

create table product
(
    product_key serial not null primary key,
    product_id character varying(8) not null,
    name character varying(255) not null,
    unique(product_id)
);

To access category, the url is /category/(\d+) using the category_key primary key. How is this less secure than a url /category/([^/]+) using the name unique key?

The only thing I can think of is that a particular category_key is much easier to guess (e.g., add one), and if you haven't coded your access control properly, this could allow someone to arbitarily view any category within the database.

4

1 回答 1

0

我不认为它会毁掉你的应用程序,这完全是关于猜测......当涉及到安全性时。对我来说,它更多的是关于加密和权限检查等等。总之,我认为使用自动增量与安全性之间没有关系。

于 2014-07-12T11:58:06.667 回答