0

我正在开发一个现有的基于 Web 的应用程序。

现在,我需要保护应用程序免受我认为所谓的 url 黑客攻击。例如,如果 customerId 为 1 的客户登录并查看他的个人资料,则地址字段中将显示以下 http get 变量:customerId=1。我需要防止客户能够设置 customerId=2 并查看其他客户的个人资料。

问题是,该应用程序已经投入生产并且处于良好的工作状态,因此相对于这种变化,变化应该是最小的。

如何最好地做到这一点?

有什么建议/意见吗?

4

2 回答 2

3

当只允许用户更改其个人资料时,为什么要在 URL 中提供 id?我认为没有必要这样做。而是从 SecurityConext 获取当前用户并在没有 id 的 URL 上显示其配置文件。

使用您在我建议的评论中提供的新信息。像这样:

只需检查 URL 中给定的 orderid 是否属于当前用户。你是说你使用“普通的基于 web 的应用程序”,所以我假设基于 Servlet/jsp。在您的 servlet 中,您将执行以下操作:

int orderId = Integer.parseInt(request.getParameter("orderId"));
String username = request.getUserPrincipal().getName();
/*now you need to check if username match with the username of the order e.g. by using hibernate to get the order by id and check its user and if not throw PermissionDeniedException or similiar*/
于 2012-08-06T13:14:38.387 回答
0

95% 的人同意上面 Korgen 的回答。5% - 如果您想允许管理员访问使用相同的功能编辑用户配置文件,只需切换到 UUID 以识别已编辑的用户。

于 2012-08-06T13:17:45.153 回答