package com.lut.teacher.teacherservice.xss;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* HTML filtering utility for protecting against XSS (Cross Site Scripting).
*
* This code is licensed LGPLv3
*
* This code is a Java port of the original work in PHP by Cal Hendersen.
* http://code.iamcal.com/php/lib_filter/
*
* The trickiest part of the translation was handling the differences in regex handling
* between PHP and Java. These resources were helpful in the process:
*
* http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
* http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php
* http://www.regular-expressions.info/modifiers.html
*
* A note on naming conventions: instance variables are prefixed with a "v"; global
* constants are in all caps.
*
* Sample use:
* String input = ...
* String clean = new HTMLFilter().filter( input );
*
* The class is not thread safe. Create a new instance if in doubt.
*
* If you find bugs or have suggestions on improvement (especially regarding
* performance), please contact us. The latest version of this
* source, and our contact details, can be found at http://xss-html-filter.sf.net
*
* @author Joseph O'Connell
* @author Cal Hendersen
* @author Michael Semb Wever
*/
public final class HTMLFilter {
/** regex flag union representing /si modifiers in php **/
private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL;
private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL);
private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI);
private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL);
private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI);
private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI);
private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI);
private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI);
private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI);
private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?");
private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?");
private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?");
private static final Pattern P_VALID_ENTITIES = Pattern.compile("&([^&;]*)(?=(;|&|$))");
private static final Pattern P_VALID_QUOTES = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL);
private static final Pattern P_END_ARROW = Pattern.compile("^>");
private static final Pattern P_BODY_TO_END = Pattern.compile("<([^>]*?)(?=<|$)");
private static final Pattern P_XML_CONTENT = Pattern.compile("(^|>)([^<]*?)(?=>)");
private static final Pattern P_STRAY_LEFT_ARROW = Pattern.compile("<([^>]*?)(?=<|$)");
private static final Pattern P_STRAY_RIGHT_ARROW = Pattern.compile("(^|>)([^<]*?)(?=>)");
private static final Pattern P_AMP = Pattern.compile("&");
private static final Pattern P_QUOTE = Pattern.compile("<");
private static final Pattern P_LEFT_ARROW = Pattern.compile("<");
private static final Pattern P_RIGHT_ARROW = Pattern.compile(">");
private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>");
// @xxx could grow large... maybe use sesat's ReferenceMap
private static final ConcurrentMap<String,Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<String, Pattern>();
private static final ConcurrentMap<String,Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<String, Pattern>();
/** set of allowed html elements, along with allowed attributes for each element **/
private final Map<String, List<String>> vAllowed;
/** counts of open tags for each (allowable) html element **/
private final Map<String, Integer> vTagCounts = new HashMap<String, Integer>();
/** html elements which must always be self-closing (e.g. "<img />") **/
private final String[] vSelfClosingTags;
/** html elements which must always have separate opening and closing tags (e.g. "<b></b>") **/
private final String[] vNeedClosingTags;
/** set of disallowed html elements **/
private final String[] vDisallowed;
/** attributes which should be checked for valid protocols **/
private final String[] vProtocolAtts;
/** allowed protocols **/
private final String[] vAllowedProtocols;
/** tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />") **/
private final String[] vRemoveBlanks;
/** entities allowed within html markup **/
private final String[] vAllowedEntities;
/** flag determining whether comments are allowed in input String. */
private final boolean stripComment;
private final boolean encodeQuotes;
private boolean vDebug = false;
/**
* flag determining whether to try to make tags when presented with "unbalanced"
* angle brackets (e.g. "<b text </b>" becomes "<b> text </b>"). If set to false,
* unbalanced angle brackets will be html escaped.
*/
private final boolean alwaysMakeTags;
/** Default constructor.
*
*/
public HTMLFilter() {
vAllowed = new HashMap<>();
final ArrayList<String> a_atts = new ArrayList<String>();
a_atts.add("href");
a_atts.add("target");
vAllowed.put("a", a_atts);
final ArrayList<String> img_atts = new ArrayList<String>();
img_atts.add("src");
img_atts.add("width");
img_atts.add("height");
img_atts.add("alt");
vAllowed.put("img", img_atts);
final ArrayList<String> no_atts = new ArrayList<String>();
vAllowed.put("b", no_atts);
vAllowed.put("strong", no_atts);
vAllowed.put("i", no_atts);
vAllowed.put("em", no_atts);
vSelfClosingTags = new String[]{"img"};
vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"};
vDisallowed = new String[]{};
vAllowedProtocols = new String[]{"http", "mailto", "https"}; // no ftp.
vProtocolAtts = new String[]{"src", "href"};
vRemoveBlanks = new String[]{"a", "b", "strong", "i", "em"};
vAllowedEntities = new String[]{"amp", "gt", "lt", "quot"};
stripComment = true;
encodeQuotes = true;
alwaysMakeTags = true;
}
/** Set debug flag to true. Otherwise use default settings. See the default constructor.
*
* @param debug turn debug on with a true argument
*/
public HTMLFilter(final boolean debug) {
this();
vDebug = debug;
}
/** Map-parameter configurable constructor.
*
* @param conf map containing configuration. keys match field names.
*/
public HTMLFilter(final Map<String,Object> conf) {
assert conf.containsKey("vAllowed") : "configuration requires vAllowed";
assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags";
assert conf.containsKey("vNeedClosingTags") : "configuration requires vNeedClosingTags";
assert conf.containsKey("vDisallowed") : "configuration requires vDisallowed";
assert conf.containsKey("vAllowedProtocols") : "configuration requires vAllowedProtocols";
assert conf.containsKey("vProtocolAtts") : "configuration requires vProtocolAtts";
assert conf.containsKey("vRemoveBlanks") : "configuration requires vRemoveBlanks";
assert conf.containsKey("vAllowedEntities") : "configuration requires vAllowedEntities";
vAllowed = Collections.unmodifiableMap((HashMap<String, List<String>>) co
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本项目是基于Java的教师业务档案管理系统后端设计源码,包含367个文件,其中223个Java文件。该系统用于存放课设做的教师业务管理系统,提供了丰富的功能和界面,以便于教师和学生进行业务档案的管理和操作。系统采用Java作为主要开发语言,同时融合了JavaScript、Vue、CSS和HTML等技术,构建了一个高效、易用的业务档案管理系统。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java的教师业务档案管理系统后端设计源码 (364个子文件)
mvnw.cmd 6KB
mvnw.cmd 6KB
mvnw.cmd 6KB
screen.css 43KB
print.css 41KB
swagger-ui.css 26KB
style.css 3KB
reset.css 773B
typography.css 0B
throbber.gif 9KB
expand.gif 73B
collapse.gif 69B
.gitignore 333B
.gitignore 333B
.gitignore 333B
.gitignore 291B
.gitignore 278B
index.html 4KB
oauth2-redirect.html 2KB
o2c.html 479B
favicon.ico 5KB
favicon.ico 4KB
teacherbusiness.iml 80B
maven-wrapper.jar 50KB
maven-wrapper.jar 50KB
maven-wrapper.jar 50KB
HTMLFilter.java 20KB
HTMLFilter.java 20KB
HttpClientUtils.java 11KB
HttpUtils.java 10KB
WxApiController.java 6KB
SysUserController.java 5KB
DataSourceProperties.java 5KB
ScheduleUtils.java 5KB
MavenWrapperDownloader.java 5KB
MavenWrapperDownloader.java 5KB
MavenWrapperDownloader.java 5KB
SysUserServiceImpl.java 5KB
TeacherInfoServiceImpl.java 5KB
DateUtils.java 5KB
SysMenuController.java 5KB
XssHttpServletRequestWrapper.java 4KB
ScheduleJobServiceImpl.java 4KB
TeacherPaperServiceImpl.java 4KB
TeacherProjectServiceImpl.java 4KB
SysRoleServiceImpl.java 4KB
SysOssController.java 4KB
OAuth2Filter.java 4KB
CloudStorageConfig.java 3KB
TeacherProjectController.java 3KB
TeacherEductionServiceImpl.java 3KB
TeacherCourseServiceImpl.java 3KB
TeacherTitleController.java 3KB
TeacherTitleServiceImpl.java 3KB
TeacherPaperController.java 3KB
SysRoleController.java 3KB
ScheduleJobController.java 3KB
OssController.java 3KB
SysLoginController.java 3KB
TeacherInfoController.java 3KB
SysMenuServiceImpl.java 3KB
SysConfigServiceImpl.java 3KB
ShiroConfig.java 3KB
RedisUtils.java 3KB
TeacherCourseController.java 3KB
TeacherEductionController.java 3KB
ScheduleJob.java 3KB
SysLogAspect.java 3KB
QcloudCloudStorageService.java 3KB
MemberServiceImpl.java 3KB
OAuth2Realm.java 2KB
ScheduleConfig.java 2KB
PeriodicalLevelController.java 2KB
AuthorizationInterceptor.java 2KB
IndexesController.java 2KB
Query.java 2KB
JwtUtils.java 2KB
DynamicDataSourceFactory.java 2KB
Query.java 2KB
Constant.java 2KB
Constant.java 2KB
QiniuCloudStorageService.java 2KB
DataSourceAspect.java 2KB
DynamicDataSourceConfig.java 2KB
SysConfigController.java 2KB
SysCaptchaServiceImpl.java 2KB
ShiroServiceImpl.java 2KB
RedisConfig.java 2KB
IPUtils.java 2KB
PageUtils.java 2KB
CloudStorageService.java 2KB
PageUtils.java 2KB
SwaggerConfig.java 2KB
SysUserTokenServiceImpl.java 2KB
LoginUserHandlerMethodArgumentResolver.java 2KB
Member.java 2KB
RRExceptionHandler.java 2KB
SysUserEntity.java 2KB
AppLoginController.java 2KB
FilterConfig.java 2KB
共 364 条
- 1
- 2
- 3
- 4
资源评论
沐知全栈开发
- 粉丝: 5697
- 资源: 5224
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- MySQL 规范和使用手册
- redis-5.0.14-1.el7.remi.x86-64.rpm安装包并含有部署手册
- SAP GUI for Windows 8.00 PL 09 Hotfix 1 (note 1489891) – Win64
- nginx-1.18.0-2.el7.ngx.x86-64.rpm安装包并包含部署手册
- Keil 5 报错 μvision is unusable without a valid TOOL.INI file解决方法
- SQL Server多维数据集.pdf
- OpenCV视频防抖源码及编译脚本
- 病理图像识别算法.pdf
- 非常nb的vue插件呜呜呜
- 梦幻壁纸下载DreamScene2下载
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功