【问题标题】:How to prevent Cross-Frame Scripting (XFS) in request parameter of spring boot controller with request method GET?如何使用请求方法 GET 防止 Spring Boot 控制器的请求参数中的跨帧脚本(XFS)?
【发布时间】:2017-06-25 20:22:34
【问题描述】:

在 GET 请求中,如何扫描请求参数以查找任何安全漏洞。

@RequestMapping(value = "/XX/YYY", method = {RequestMethod.GET, RequestMethod.HEAD})
public String myCustomMethod(Model model, HttpServletRequest request, HttpServletResponse response, 
        @RequestParam(value = "a", required = false) String a,
        @RequestParam(value = "b", required = false) String b)
{

}

在此代码示例中,我想检查参数 a/b 是否感染了类似 //" .

【问题讨论】:

  • 你的输出会被包含在 HTML 中吗?
  • 是的,输出将包含在 HTML 中

标签: spring validation spring-boot xss csrf


【解决方案1】:

我使用的预防措施是在将不受信任的输入添加到输出之前将其编码为suggested by OWASP,即开放式 Web 应用程序安全项目。

我使用他们的 ESAPI 库。在此处找到指向

的链接

包含库后,在configuration/.esapi 目录中找到ESAPI.propertiesvalidation.properties 文件并将它们复制到项目的根目录(如果您使用的是maven,则为src/main/resources)。这些文件指定了验证和编码的策略;我通常很擅长默认设置。

然后您可以像这样使用编码器:

Encoder encoder = ESAPI.encoder();
String aSafe = encoder.encodeForHTML(a); 
String bSafe = encoder.encodeForHTML(b);

【讨论】:

    猜你喜欢
    • 2020-11-09
    • 2021-08-29
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 2018-06-20
    相关资源
    最近更新 更多