0
XSS 주입을 위해 들어오는 모든 요청 본문을 피하는 데 도움이되는 스프링 보안에는 어떤 것이 있습니까?스프링 MVC 이스케이프 요청 본문
XSS 주입을 위해 들어오는 모든 요청 본문을 피하는 데 도움이되는 스프링 보안에는 어떤 것이 있습니까?스프링 MVC 이스케이프 요청 본문
OWASP ESAPI 프레임 워크를 사용하면 XSS를 방지 할 수 있습니다. 요청 매개 변수가 & HTML, CSS, 자바 스크립트 등의 데이터를 인코딩하는 방법의 Encoder 인터페이스의 광범위한 배열을 사용하여 인코딩 차단 필터를 구현
String safeString = ESAPI.encoder().encodeForURL(request.getParameter("input"));
당신이 NOT을 선택하면 내가 ESAPI와 함께 이동하는 것이 좋습니다,하지만 것 그것을 사용하면 다음과 같은 방법으로 필터를 구현할 수 있습니다.
private String stripXSS(String value) {
if (value != null) {
// NOTE: It's highly recommended to use the ESAPI library and uncomment the following line to
// avoid encoded attacks.
// value = ESAPI.encoder().canonicalize(value);
// Avoid null characters
value = value.replaceAll("", "");
// Avoid anything between script tags
Pattern scriptPattern = Pattern.compile("<script>(.*?)</script>", Pattern.CASE_INSENSITIVE);
value = scriptPattern.matcher(value).replaceAll("");
// Avoid anything in a src='...' type of expression
scriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\'(.*?)\\\'", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
value = scriptPattern.matcher(value).replaceAll("");
scriptPattern = Pattern.compile("src[\r\n]*=[\r\n]*\\\"(.*?)\\\"", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
value = scriptPattern.matcher(value).replaceAll("");
// Remove any lonesome </script> tag
scriptPattern = Pattern.compile("</script>", Pattern.CASE_INSENSITIVE);
value = scriptPattern.matcher(value).replaceAll("");
// Remove any lonesome <script ...> tag
scriptPattern = Pattern.compile("<script(.*?)>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
value = scriptPattern.matcher(value).replaceAll("");
// Avoid eval(...) expressions
scriptPattern = Pattern.compile("eval\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
value = scriptPattern.matcher(value).replaceAll("");
// Avoid expression(...) expressions
scriptPattern = Pattern.compile("expression\\((.*?)\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
value = scriptPattern.matcher(value).replaceAll("");
// Avoid javascript:... expressions
scriptPattern = Pattern.compile("javascript:", Pattern.CASE_INSENSITIVE);
value = scriptPattern.matcher(value).replaceAll("");
// Avoid vbscript:... expressions
scriptPattern = Pattern.compile("vbscript:", Pattern.CASE_INSENSITIVE);
value = scriptPattern.matcher(value).replaceAll("");
// Avoid onload= expressions
scriptPattern = Pattern.compile("onload(.*?)=", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
value = scriptPattern.matcher(value).replaceAll("");
}
return value;
}
코드 소스 : 내가 알고하지 않는 것이 Anti cross-site scripting (XSS) filter for Java web apps
. 다음 게시물을 보셨습니까? http://stackoverflow.com/questions/5769847/how-to-avoid-apps-from-xss-attacks, http://stackoverflow.com/questions/19824338/avoid-xss-and-allow-some-html- tags-with-javascript/19943011 # 19943011 – tom