本文介绍了如何防止用户访问其他用户的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题
- 已通过应用程序验证的用户
- 简单的数据库架构:用户--->文档--->项
- 用于访问文档项目的API
如果登录的用户知道属于其他用户的项目的ID,则他可以访问它.我想防止这种行为.
If the logged user knows the id of items that belong to some other user, he can access to it.I would like to prevent this behavior.
解决方案
我发现的第一个解决方案是在每个表的每个记录中添加一个userid字段,以在每次查询时检查记录是否属于登录用户.
The first solution I found is to add a userid field to every records in every table to check at every query if the record belong to the logged user.
这是一个好的解决方案?您是否知道一些更好的设计模式来防止用户访问其他用户的数据?
This is a good solution? Do you know some better design pattern to prevent the user to access other users' data?
谢谢
推荐答案
- 如果文档属于用户,请调整查询,以便仅检索属于用户文档的项目.无需将用户ID添加到项目本身.
- 如果需要向用户公开ID,请使这些ID成为GUID,而不是连续的数字.虽然这不是一个完美的解决方案,但要猜测其他用户商品的ID变得更加困难,
- 如果您使用的是Oracle,则有VPD,虚拟专用数据库.您可以使用它来限制用户的访问权限.
- If the documents belong to a user, adjust your queries so that only items that belong to the user's documents are retrieved. No need to add userIDs to the items themselves.
- If you need to expose IDs to the users, make those IDs GUIDs, instead of consecutive numbers. While not a perfect solution, it makes it much harder to guess the IDs of other users' items,
- If you're using Oracle, there's VPD, Virtual Private Database. You can use that to restrict access for users.
这篇关于如何防止用户访问其他用户的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!