【问题标题】:Use ESAPI Encoder in Java在 Java 中使用 ESAPI 编码器
【发布时间】:2017-05-31 07:41:29
【问题描述】:

以下代码显示了 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;
}

【问题讨论】:

  • 另外,您在请求标头中传递了用户名。您正在做什么来防止用户将其用户更改为您的应用程序的“管理员”?

标签: java rest xss esapi


【解决方案1】:
@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;
}

所以,这被标记的原因首先是,您没有对收到的变量进行任何输入验证。这是合法的userId吗? )>8*2]U5d)s^deUB|SNJRpT7u=: *8SN:$/wapC"C&dW9 R@*aeZFtPUYqfEk

因为正如所写,它是。 <script>alert(1);</script> 也是跨站点脚本的教科书案例,' OR 1=1' 也可能导致 SQL 注入,除非有其他一些警告。

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

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

在您用于输出的任何 JSP 上,使用 ESAPI 标签库,并为 proper context. 编码

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多