velocity 的 escape实现
EscapeHtmlReference的escape方法调用以下方法实现:
StringEscapeUtils.escapeHtml(param); 再调用
org.apache.commons.lang.Entities.HTML40.escape(writer, string);
代码如下:
public void escape(Writer writer, String str) throws IOException {
int len = str.length();
for(int i = 0; i < len; ++i) {
char c = str.charAt(i);
String entityName = this.entityName(c);
if(entityName == null) {
if(c > 127) {
writer.write("&#");
writer.write(Integer.toString(c, 10));
writer.write(59); //就是个分号
} else {
writer.write(c);
}
} else {
writer.write(38);
writer.write(entityName);
writer.write(59);
}
}
}
我们也可以自己调用
StringEscapeUtils.escapeHtml(param);
比如:
String param = request.getParameter("p");
String x = StringEscapeUtils.escapeHtml(param);
System.out.println(x);
输入 <script>alert(/xxx/)</script> 输出 <script>alert(/xxx/)</script>
velocity 也可以自定义 EventHandler 处理xss,配置EscapeHtmlReference 替换成自己的EventHandler
<bean id="velocityConfigurer"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/pages/"/>
<property name="velocityProperties">
<props>
<prop key="input.encoding">utf-8</prop>
<prop key="output.encoding">utf-8</prop>
<prop key="eventhandler.referenceinsertion.class">org.apache.velocity.app.event.implement.EscapeHtmlReference</prop>
<prop key="eventhandler.escape.html.match">/^(?!\$\!?unesc_).*/</prop>
</props>
</property>
</bean>
velocity 的 escape实现的更多相关文章
- maven+springmvc+spring+mybatis+velocity整合
一.ssmm简介 ssmm是当下企业最常用的开发框架架构 maven:管理项目jar包,构建项目 spring:IOC容器,事务管理 springmvc:mvc框架 myBatis:持久层框架 v ...
- HDU 3533 Escape (BFS + 预处理)
Escape Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- 《Velocity java开发指南》中文版(下)转载
文章出自:http://sakyone.iteye.com/blog/524292 8.Application Attributes Application Attributes (应用程序属性)是和 ...
- 《Velocity 模板使用指南》中文版[转]
转自:http://blog.csdn.net/javafound/archive/2007/05/14/1607931.aspx <Velocity 模板使用指南>中文版 源文见 htt ...
- HDU 3533 Escape(bfs)
Escape Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 3533 Escape(大逃亡)
HDU 3533 Escape(大逃亡) /K (Java/Others) Problem Description - 题目描述 The students of the HEU are maneu ...
- 【算法】Escape
The students of the HEU are maneuvering for their military training. The red army and the blue army ...
- Velocity初始化过程解析
velocity就是由template,engine,context组成. 1.首先创建一个template(如果是用在web上就是一个html文件),将需要参数化或实例化的地方用跟context有关 ...
- HDU3533 Escape —— BFS / A*算法 + 预处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others) ...
随机推荐
- oc block 遍历数组及字典
原遍历数组NSArray * lines = ...for (NSString * line in lines) { // ...}for (int i = 0; i < lines.count ...
- docker发布spring cloud应用
原文地址:http://www.cnblogs.com/skyblog/p/5163691.html 本文涉及到的项目: cloud-simple-docker:一个简单的spring boot应用 ...
- 常用sql语句记录
1.表 --建表 if OBJECT_ID('Student') is not null create table Student( ID ,) not null, Name ), Code ), f ...
- 有关IM即时通讯原理
在网上搜索了一些资料,谈谈自己对IM即时通讯的理解 IM全称为Instant Messaging,即时通讯,如qq那种的. 现在有两个用户UserA, UserB, 俩人是一个IM通讯软件的好友,Us ...
- Atitit.手机验证码的破解---伪随机数
Atitit.手机验证码的破解---伪随机数 1. 手机验证码几乎都是伪随机数1 2. 伪随机数1 2.1. 生成方法编辑1 2.2. 随机数的计算方法在不同的计算机中是不同的,即使在相同的计算机中安 ...
- Angularjs学习笔记7_directive1
1.基础知识 directive()接受两个参数 · name:字符串,指令的名字 · factory_function:函数,指令的行为 应用启动时,以name作为该应用的标识注册factory_f ...
- Linux 5 下安装MySQL 5.6(RPM方式)
MySQL在很多领域被广泛使用,尤其是很多互联网企业,诸如腾讯,阿里等等.本文主要介绍在Linux 5下通过rpm方式来安装Mysql,这是比较简单的一种安装方式,具体详见下文. <MySQL权 ...
- 使用NGINX反向代理做小偷站
用Nginx的反向代理可以轻松山寨对方的网站,但是反向代理后的网站还是有对方的绝对链接时,怎么办?所以要用替换链接方法. 1 使用官方的的模块 编译参数–with-http_sub_moduleub_ ...
- centos7+nginx部署asp.net core mvc网站
1. 安装 .net core 可参见官网安装教程. 选择Linux发行版本为Centos/Oracle 添加dotnet的yum仓库配置 $ sudo rpm -Uvh https://packag ...
- MAC与PHY连接的管理接口MDIO
MII Management interface用于MAC层或其他控制芯片(不一定是MAC层芯片,可能是MCU,如高通芯片建构中,1个MAC芯片可以控制2个PHY芯片,然后MCU控制3个网卡(MAC+ ...