疯狂的狮子li
2021-08-30 bdfd2f0787b0a39fb65793a7f57c95f5de09edf4
ruoyi-common/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java
@@ -1,9 +1,8 @@
package com.ruoyi.common.filter;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HtmlUtil;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@@ -59,15 +58,15 @@
        // 为空,直接返回
        String json = IoUtil.read(super.getInputStream(), StandardCharsets.UTF_8);
        if (Validator.isEmpty(json))
        if (StringUtils.isEmpty(json))
        {
            return super.getInputStream();
        }
        // xss过滤
        json = HtmlUtil.cleanHtmlTag(json).trim();
        final ByteArrayInputStream bis = IoUtil.toStream(json, StandardCharsets.UTF_8);
        byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);
        final ByteArrayInputStream bis = IoUtil.toStream(jsonBytes);
        return new ServletInputStream()
        {
            @Override
@@ -80,6 +79,12 @@
            public boolean isReady()
            {
                return true;
            }
            @Override
            public int available() throws IOException
            {
                return jsonBytes.length;
            }
            @Override
@@ -103,6 +108,6 @@
    public boolean isJsonRequest()
    {
        String header = super.getHeader(HttpHeaders.CONTENT_TYPE);
        return StrUtil.startWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE);
        return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE);
    }
}
}