| | |
| | | /**Json请求体参数处理*/ |
| | | @Override |
| | | public ServletInputStream getInputStream() throws IOException { |
| | | final ByteArrayInputStream bais = new ByteArrayInputStream(inputHandlers(super.getInputStream ()).getBytes ()); |
| | | final ByteArrayInputStream bais = new ByteArrayInputStream(inputHandlers(super.getInputStream()).getBytes(StandardCharsets.UTF_8)); |
| | | |
| | | return new ServletInputStream() { |
| | | |
| | |
| | | } |
| | | private String cleanXSS(String value) { |
| | | if (value != null) { |
| | | // 推荐使用ESAPI库来避免脚本攻击 |
| | | // 推荐使用ESAPI库来避免脚本攻击,同时对所有的url编码数据进行了完全解码操作 |
| | | value = ESAPI.encoder().canonicalize(value); |
| | | |
| | | // 避免空字符串 |
| | | value = value.replaceAll(" ", ""); |
| | | //value = value.replaceAll(" ", ""); |
| | | |
| | | // 删除 ' |
| | | value = value.replaceAll("'",""); |
| | | |
| | | // 避免script 标签 |
| | | Pattern scriptPattern = compile("<script>(.*?)</script>", CASE_INSENSITIVE); |
| | |
| | | value = scriptPattern.matcher(value).replaceAll(""); |
| | | |
| | | // 避免 onXX= 表达式 |
| | | scriptPattern = compile("on.*(.*?)=", CASE_INSENSITIVE | MULTILINE | DOTALL); |
| | | value = scriptPattern.matcher(value).replaceAll(""); |
| | | /*scriptPattern = compile("on.*(.*?)=", CASE_INSENSITIVE | MULTILINE | DOTALL); |
| | | value = scriptPattern.matcher(value).replaceAll("");*/ |
| | | |
| | | } |
| | | return value; |