![](/img/trans.png)
[英]How to restrict user from editing the URL data in a java application and access the URL
[英]Restrict Access to DWR(Easy Ajax for Java) from URL bar
我正在使用DWR ,通常称为Easy Ajax for Java 。
但是可以像这样通过URL bar
直接访问它
http://localhost:8080/myProjectName/dwr/
从这里我可以执行每个Ajax Call
,这被认为是对应用程序安全的威胁,
有没有办法限制这一点?
我不确定您要完成什么,但是这里有一些建议:
http:// localhost:8080 / myProjectName / dwr /仅在设置后可用
<init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param>
在web.xml
中的servlet声明中。 将param-value设置为false,并且http:// localhost:8080 / myProjectName / dwr /将返回404(找不到页面)。
即使禁用调试模式,仍然可以运行功能。 这就是为什么您可以在drw.xml
从Web上限制哪些类以及这些类的哪些功能。 有关dwr.xml
详细信息,请参阅DWR文档。
请记住,每个可用的公共功能都应检查是否允许用户运行它。 我通常创建一个这样的函数:
private void getLoggedInUser(){ WebContext ctx = WebContextFactory.get(); HttpSession session=ctx.getSession(); if(session.getAttribute("loggedIn")!=null && (Boolean)session.getAttribute("loggedIn")==true){ if(session.getAttribute("user")!=null){ try{ return (Person)session.getAttribute("user"); }catch (ClassCastException ex){ return null; } }else{ return null; } }else{ return null; } }
然后在通过网络提供的每个功能的开头,我都会做类似的事情
Person user=getLoggedInUser();
if(user)==null return null;
切记,您的网站访问者可以操纵javascript。 如果通过dwr发布函数,请假定任何人都可以调用它。 我对此不太强调:在通过dwr发布的每个函数中,首先要确保允许用户运行它,然后检查用户可能传递的任何参数是否有效。
更新:也可以使用过滤器限制对功能的访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.