Есть ли опасность для создания UUID на стороне клиента JavaScript?

StackOverflow https://stackoverflow.com/questions/1296234

  •  18-09-2019
  •  | 
  •  

Вопрос

Мне нужно генерировать UUID, чтобы в конечном итоге хранить в базе данных. Могу ли я сгенерировать тезисы uuid от javaScript в браузере клиента (Здесь есть несколько примеров)?

Есть ли какой -нибудь риск безопасности сделать это таким образом? Я понимаю, что любой может изменить UUID, прежде чем он будет передан на сервер для хранения. Так что мне нужно проверить, являются ли они уникальными, прежде чем хранить их в базе данных, но кроме этого, есть ли другие вещи, чтобы оформить заказа?

(Извините за мой английский, не стесняйтесь исправлять любые грамматические ошибки)

редактировать: Чтобы ответить на вопросы о том, почему я хотел бы сделать это, это потому, что я могу создать новый объект, и он является идентификатором в JavaScript и добавить его в свое представление, а затем сделать вызов Ajax на сервер, чтобы добавить его в базу данных. Таким образом, мне не нужно загружать его обратно из базы данных, чтобы узнать, что это за основной идентификатор.

Это было полезно?

Решение

Not really. As long as it's a simple identifier and nothing more, and you are indeed checking it for validity and uniqueness, it's no different than user accounts having an id in the url, for example.

Look at your URL bar. I bet 1296234 is the primary key of this question, but I can't really do anything with that information. Same deal with your script.

Другие советы

What benefit do you see in generating these client-side? In all honesty, the best option is to generate it server-side, out of the users reach. It may not give save you from any serious security issues, but it will cut down on redundant validation.

Yes. The risk is not specific to UUID, any client-side generated ID has some risks, depending on what you do with the ID. The problem is that it's very hard to authenticate the Javascript. If you accept ID generated by client, you accept any IDs from the hackers.

The risks may include,

  1. Session stealing. If you use the ID to identify the session, someone may use an existing ID as generated ID and the server may treat it as an existing session if proper care is not taking.

  2. Duplicate keys. True UUID is random but someone can generate duplicate keys which will mess up your database.

You might find ways to defend against each of these attacks but that's passive protection. It might defeat the original purpose of generating IDs on the client, which is simple.

Is there some reason you can't have the database generate (increment) an ID?

If, like you say, you'll have to check the uniqueness of the value before submitting it anyway, why not just have whatever backend language you are using generate it. That would make it much more opaque.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top