1
wysnylc OP 谷歌都收录了但是没人回我呀宝宝好可怜
|
2
wysnylc OP 我已经实现好了,你要么
|
3
shiwuxiwen 2017-06-21 15:50:50 +08:00
需要,这么发我的
|
4
shiwuxiwen 2017-06-21 15:53:17 +08:00
我 qq 767395949
|
5
shiwuxiwen 2017-06-21 15:53:26 +08:00
多谢,多谢。
|
6
shiwuxiwen 2017-06-22 10:23:51 +08:00
@wysnylc 有在不?
|
7
wysnylc OP @shiwuxiwen 两天没上,不要急
package com.meadin.funding.service.support; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.util.MultiValueMap; import org.springframework.web.servlet.handler.AbstractHandlerMapping; import org.springframework.web.util.HtmlUtils; import org.springframework.web.util.UrlPathHelper; import com.meadin.funding.util.CollectionUtils; /** * 解决 @PathVariable 注解造成的 xss 攻击问题,注意:此类必需由 WebApplicationContext 初始化 * * @author zhou * */ public class XssHandlerMappingPostProcessor implements BeanPostProcessor{ @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException{ return bean; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException{ if(bean instanceof AbstractHandlerMapping){ AbstractHandlerMapping ahm = (AbstractHandlerMapping) bean; ahm.setUrlPathHelper(new XssUrlPathHelper()); } return bean; } static class XssUrlPathHelper extends UrlPathHelper{ @Override public Map<String, String> decodePathVariables(HttpServletRequest request, Map<String, String> vars){ Map<String, String> result = super.decodePathVariables(request, vars); if(!CollectionUtils.isEmpty(result)){ for(String key : result.keySet()){ result.put(key, cleanXSS(result.get(key))); } } return result; } @Override public MultiValueMap<String, String> decodeMatrixVariables(HttpServletRequest request, MultiValueMap<String, String> vars){ MultiValueMap<String, String> mvm = super.decodeMatrixVariables(request, vars); if(!CollectionUtils.isEmpty(mvm)){ for(String key : mvm.keySet()){ List<String> value = mvm.get(key); for(int i = 0; i < value.size(); i++){ value.set(i, cleanXSS(value.get(i))); } } } return mvm; } private String cleanXSS(String value){ return HtmlUtils.htmlEscape(value); } } } 代码就是这样,应该没错 |
8
18732907626 2019-03-01 09:57:09 +08:00
@wysnylc 老哥在吗,需要你的帮助,我后台也是用的 @RequestBody User user 来接收前台传的值,现在要过滤 XSS,需要你的指点,方便的话可以加我 QQ334911558 感谢
|
9
wysnylc OP |
10
18732907626 2019-03-01 14:08:39 +08:00
@wysnylc 还是不行,配置上了,没反应。什么情况
|