net.mingsoft.basic.util.JsoupUtil Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 2012-present 铭软科技(mingsoft.net)
* 本软件及相关文档文件(以下简称“软件”)的版权归 铭软科技 所有
* 遵循 铭软科技《服务协议》中的《保密条款》
*/
package net.mingsoft.basic.util;
import cn.hutool.core.net.URLDecoder;
import cn.hutool.core.util.StrUtil;
import net.mingsoft.base.util.SqlInjectionUtil;
import net.mingsoft.base.exception.BusinessException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Whitelist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;
/**
* Xss过滤工具
*/
public class JsoupUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(JsoupUtil.class);
/**
* html白名单
*/
private static final Whitelist WHITE_LIST = Whitelist.relaxed().preserveRelativeLinks(true);
/**
* 配置过滤化参数,不对代码进行格式化
*/
private static final Document.OutputSettings OUTPUT_SETTINGS = new Document.OutputSettings().prettyPrint(false);
/**
* 配置Unicode过滤参数
*/
private static final String[] UNICODE_STR = {"+/v8","+/v9","+/v+","+/v/"};
/**
* xss脚本正则
*/
private final static Pattern[] scriptPatterns = {
// TODO: 2023/1/4 增加xss验证规则
Pattern.compile("", Pattern.CASE_INSENSITIVE),
Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
Pattern.compile("", Pattern.CASE_INSENSITIVE),
Pattern.compile("