whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/filter/XssHttpServletRequestWrapper.java
@@ -70,7 +70,7 @@
    /**Json请求体参数处理*/
    @Override
    public ServletInputStream getInputStream() throws IOException {
        final ByteArrayInputStream bais = new ByteArrayInputStream(inputHandlers(super.getInputStream ()).getBytes ());
        final ByteArrayInputStream bais = new ByteArrayInputStream(inputHandlers(super.getInputStream()).getBytes(StandardCharsets.UTF_8));
        return new ServletInputStream() {
@@ -132,11 +132,14 @@
    }
    private String cleanXSS(String value) {
        if (value != null) {
            // 推荐使用ESAPI库来避免脚本攻击
            // 推荐使用ESAPI库来避免脚本攻击,同时对所有的url编码数据进行了完全解码操作
            value = ESAPI.encoder().canonicalize(value);
            // 避免空字符串
            value = value.replaceAll(" ", "");
            //value = value.replaceAll(" ", "");
            // 删除 '
            value = value.replaceAll("'","");
            // 避免script 标签
            Pattern scriptPattern = compile("<script>(.*?)</script>", CASE_INSENSITIVE);
@@ -177,8 +180,8 @@
            value = scriptPattern.matcher(value).replaceAll("");
            // 避免 onXX= 表达式
            scriptPattern = compile("on.*(.*?)=", CASE_INSENSITIVE | MULTILINE | DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");
            /*scriptPattern = compile("on.*(.*?)=", CASE_INSENSITIVE | MULTILINE | DOTALL);
            value = scriptPattern.matcher(value).replaceAll("");*/
        }
        return value;