본문 바로가기
Secure Coding

서버측 요청 위조 공격

by Penetration Tester 2021. 9. 17.
728x90
반응형

서버측 요청 위조 공격

Noncompliant Code Example

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  URL url = new URL(req.getParameter("url"));
  HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // Noncompliant
}

 

Compliant Solution

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
  String urlWhiteListed = "https://example.com/";
  String str = req.getParameter("url");
  if (!str.startsWith(urlWhiteListed))
    throw new IOException();

  URL url2 = new URL(str);
  HttpURLConnection conn2 = (HttpURLConnection) url2.openConnection(); // compliant
}

728x90
반응형

'Secure Coding' 카테고리의 다른 글

서블릿 메소드 예외 처리 취약점  (0) 2021.09.17
로깅 인젝션 공격  (0) 2021.09.17
HTTP 응답 헤더 인젝션  (0) 2021.09.17
OS 명령 삽입 공격  (0) 2021.09.17
XPath 인젝션 공격  (0) 2021.09.17

댓글