限制从 URL 栏访问 DWR(Easy Ajax for Java)
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 声明中。将参数值设置为 false,http://localhost:8080/myProjectName/dwr/ 将 return 404(未找到页面)。
即使您禁用调试模式,仍然可以 运行 您的函数。这就是为什么您可以限制哪些 类 以及这些 类 的哪些功能可以从您的 drw.xml
中的网络获得。有关 dwr.xml
的详细信息,请查看 DWR documentation
请记住,每个公开可用的功能都应检查是否允许用户 运行 它。我通常创建这样的函数:
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 发布的每个函数中,首先确保允许用户 运行 它,然后检查用户可能传递的任何参数是否有效。
更新:也可以使用 filters.
限制对函数的访问
我正在使用 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 声明中。将参数值设置为 false,http://localhost:8080/myProjectName/dwr/ 将 return 404(未找到页面)。
即使您禁用调试模式,仍然可以 运行 您的函数。这就是为什么您可以限制哪些 类 以及这些 类 的哪些功能可以从您的
drw.xml
中的网络获得。有关dwr.xml
的详细信息,请查看 DWR documentation请记住,每个公开可用的功能都应检查是否允许用户 运行 它。我通常创建这样的函数:
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 发布的每个函数中,首先确保允许用户 运行 它,然后检查用户可能传递的任何参数是否有效。
更新:也可以使用 filters.
限制对函数的访问