org.kaizen4j.common.util.XSSUtils Maven / Gradle / Ivy
package org.kaizen4j.common.util;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import java.util.regex.Pattern;
import static org.kaizen4j.common.base.Symbols.EMPTY;
public final class XSSUtils {
private static final Pattern[] patterns = new Pattern[] {
// Script fragments
Pattern.compile("", Pattern.CASE_INSENSITIVE),
// src='...'
Pattern.compile("src[\r\n]*=[\r\n]*(.*?)",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
Pattern.compile("src[\r\n]*=[\r\n]*\\\"(.*?)\\\"",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL),
// lonely script tags
Pattern.compile("", Pattern.CASE_INSENSITIVE),
Pattern.compile("