Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中使用ESAPI编码器_Java_Rest_Xss_Esapi - Fatal编程技术网

在Java中使用ESAPI编码器

在Java中使用ESAPI编码器,java,rest,xss,esapi,Java,Rest,Xss,Esapi,以下代码显示了fortify中的跨站点脚本问题。我如何使用esapi防止同样的情况 @POST @PATH public EmployeeResponse getFilteredEmployees(EmployeeRequest req, @HeaderParam("user") String user) { if(user == null) user = req.getEmpId(); EmployeeResponse resp = new EmployeeResponse(); r

以下代码显示了fortify中的跨站点脚本问题。我如何使用esapi防止同样的情况

@POST
@PATH
public EmployeeResponse getFilteredEmployees(EmployeeRequest req, @HeaderParam("user") String user) {
if(user == null) 
   user = req.getEmpId();

EmployeeResponse resp = new EmployeeResponse();
resp.setEmpName(req.getEmpName);
//Do something with the resp

return resp;
}
因此,这被标记的原因首先是,您没有对接收到的变量进行任何输入验证。这是合法的用户ID吗<代码>)>8*2]U5d)s^deUB|SNJRpT7u=:*8SN:$/wapC“C&dW9 R@*aeZFtPUYqfEk

因为正如所写的那样,
alert(1);
是跨站点脚本编写的教科书案例,而
'或1=1'
可能会导致SQL注入,除非有几个其他警告

防御1:这是不完整的,但对于XSS缓解是必要的

防御2:正确上下文的输出编码

在用于输出的任何JSP上,使用ESAPI标记库,并对


链接的备忘单将帮助您开始。至于代码示例,一些web框架附带了输入验证API,这些可能就足够了,但是如果使用ESAPI,您将在
validation.properties
中添加一个正则表达式,然后使用
ESAPI.validator().getValidInput(args…)调用该验证规则;
call.

另外,您正在请求头中传递用户名。您如何防止用户将应用程序的用户更改为“admin”?
@POST
@PATH
public EmployeeResponse getFilteredEmployees(EmployeeRequest req, @HeaderParam("user") String user) {
if(user == null) 
   user = req.getEmpId();

EmployeeResponse resp = new EmployeeResponse();
resp.setEmpName(req.getEmpName);
//Do something with the resp

return resp;
}