>  기사  >  Java  >  Struts1 URL 차단에 대한 자세한 소개

Struts1 URL 차단에 대한 자세한 소개

黄舟
黄舟원래의
2018-05-24 15:19:261667검색

이 글에서는 주로 Power Node Java Academy에서 정리한 Struts1 관련 정보의 URL 차단을 소개합니다. 도움이 필요한 친구는

Struts1의 URL 차단

을 참조하세요. 먼저 ActionServlet에 대한 심층적인 분석을 진행해 보겠습니다. 우리는 기본 소스 코드를 살펴보기 위해 중단점 디버깅을 사용합니다. 이 인스턴스는 포스트 모드로 제출되므로 doPost 메소드에 중단점을 설정하십시오.


실행 중인 프로그램을 디버그하고 doPost에 메소드를 입력합니다.

이 메소드는 매우 중요하며 ActionServlet 실행의 핵심 메소드입니다.

이 메소드를 입력합니다:


그런 다음 계속 입력합니다:



우리는 갑자기 이러한 메소드가 문자열을 가로채는 메소드인 processPath 메소드라는 것을 발견했습니다. 이 메소드의 소스 코드는 다음과 같습니다.

/** 
  * <p>Identify and return the path component(from the request URI) that 
  * we will use to select an <code>ActionMapping</code> with which todispatch. 
  * If no such path can be identified,create an error response and return 
  * <code>null</code>.</p> 
  * 
  * @param request The servlet request weare processing 
  * @param response The servlet response weare creating 
  * 
  * @exception IOException if an input/outputerror occurs 
  */ 
 protectedString processPath(HttpServletRequest request, 
        HttpServletResponse response) 
  throws IOException { 
 
  String path = null; 
 
  // For prefix matching, match on the path info (if any) 
  path = (String) request.getAttribute(INCLUDE_PATH_INFO); 
  if (path == null) { 
   path = request.getPathInfo(); 
  } 
  if ((path != null) && (path.length() > 0)) { 
   return (path); 
  } 
 
  // For extension matching, strip the module prefix and extension 
  path = (String) request.getAttribute(INCLUDE_SERVLET_PATH); 
  if (path == null) { 
   path = request.getServletPath(); 
  } 
  String prefix = moduleConfig.getPrefix(); 
  if (!path.startsWith(prefix)) { 
   String msg =getInternal().getMessage("processPath"); 
    
   log.error(msg + " " + request.getRequestURI()); 
   response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); 
 
   return null; 
  } 
   
  path = path.substring(prefix.length()); 
  int slash = path.lastIndexOf("/"); 
  int period = path.lastIndexOf("."); 
  if ((period >= 0) && (period >slash)) { 
   path = path.substring(0, period); 
  } 
  return (path); 
 
}

이 코드 분석:

path = (String)request.getAttribute(INCLUDE_PATH_INFO); 
  if (path == null) { 
   path = request.getPathInfo(); 
  } 
  if ((path != null) && (path.length() > 0)) { 
   return (path); 
  }

이 코드는 먼저 javax.servlet.include.path_info에 경로 정보가 있는지 확인합니다. 여기서 페이지가 RequestDispatcher에 표시되는지 알아야 합니다. .include 모드. 이 속성 값이 존재합니다. 따라서 여기에 값이 없으면 path=request.getPathInfo() 프로그램에 들어가게 됩니다. 여기에서 getPathInfo를 통해 얻은 값은 서블릿에 대한 상대 경로 정보입니다.

// For extension matching, stripthe module prefix and extension 
  path = (String) request.getAttribute(INCLUDE_SERVLET_PATH); 
  if (path == null) { 
   path = request.getServletPath(); 
  } 
  String prefix = moduleConfig.getPrefix(); 
  if (!path.startsWith(prefix)) { 
   String msg =getInternal().getMessage("processPath"); 
    
   log.error(msg + " " + request.getRequestURI()); 
   response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); 
 
   return null; 
  }

이 코드는 javax.servlet.include.servlet_path에 값이 있는지 확인하는 코드입니다. 이 속성 값은 페이지가 requestDispatcher.include 모드로 표시될 때만 존재하므로 여기에는 값이 없습니다. 그런 다음 path = request.getServletPath()를 입력합니다. 이 메소드는 요청 URI 컨텍스트를 반환한 후 하위 문자열을 가져오는 것이므로 여기서 반환 값은 "/"이고 액세스 페이지 이름과 접미사입니다(이것은 내 mvc 인스턴스에서 가로채는 것과 동일합니다). 원칙). 그런 다음 다음 코드를 입력하세요.

path = path.substring(prefix.length()); 
  intslash = path.lastIndexOf("/"); 
  intperiod = path.lastIndexOf("."); 
  if((period >= 0) && (period > slash)) { 
   path = path.substring(0, period); 
  } 
  return (path);

여기의 방법은 주로 위의 방법과 동일하며, 가장 중요한 것은 접미사를 제거하는 것입니다.

위 내용은 Struts1 URL 차단에 대한 자세한 소개의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.