我正在开发一个现有的基于 Web 的应用程序。
现在,我需要保护应用程序免受我认为的 url 黑客攻击。例如,如果 customerId 为 1 的客户登录并查看其个人资料,则地址字段中将显示以下 http get 变量:customerId=1。 我需要阻止客户设置 customerId=2 并查看其他客户的个人资料。
问题是,应用程序已经投入生产并且工作状态良好,因此相对于此更改而言,更改应该很小。
如何最好地实现这一目标?
有什么建议/意见吗?
最佳答案
当用户只被允许更改他的个人资料时,为什么要在 URL 中给出 id?我认为没有必要这样做。而是从 SecurityConext 获取当前用户并在不带 ID 的 URL 上显示其个人资料。
根据您在评论中提供的新信息,我提出了建议。像这样:
只需检查 URL 中给定的 orderid 是否属于当前用户。 你说你使用“普通的基于网络的应用程序”,所以我假设基于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*/
关于JavaEE : Prevent application URL hacking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11828987/