Dev/Server

Apache/Tomcat 400, 404, 500, 503 에러 페이지 처리 및 보안 취약점 권고조치

pu3vig 2022. 11. 22. 12:39
728x90
  • target:  Apache와 Tomcat에서의 400 / 404 / 500 / 503 에러코드별 처리 및 보안 취약점 권고조치

 


  • method: 

1. Error Code

  • 400 Bad Request - 잘못된 요청 구문, 유효하지 않은 요청 메시지 프레이밍 또는 변조된 요청 라우팅 감지
  • 404 Not Found - 요청한 리소스를 찾을 수 없음
  • 500 Internal Server Error - 서버 응답 에러
  • 503 Service Unavailable - 서비 다운 혹은 오버로드

1. Apache

Apache의 httpd.conf에 직접 ErrorDocument를 설정하거나, httpd-vhosts.conf까지 확장하여 사용중인 경우, httpd-vhosts.conf의 VirtualHost 태그 내에서 추가하여 활용

 

1) httpd.conf

### Apache/2.4.38 (Linux) 기준
### httpd.conf만 사용인 경우, ErrorDocument 추가
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html

ErrorDocument 400 /error/error400.html
ErrorDocument 404 /error/error404.html
ErrorDocument 500 /error/error500.html
ErrorDocument 503 /error/error503.html

### httpd.conf에서 httpd-vhosts.conf까지 확장한 경우
### httpd.conf에서 아래 부분이 주석(#)이 해제되어있는지 확인
Include conf/extra/httpd-vhosts.conf

 

2) httpd-vhosts.conf (httpd.conf에서 확장한 경우)

<!-- ErrorDocument 503 추가 -->
<VirtualHost *:80>
    ...
    (중략)
    ...
    
    ErrorDocument 400 /error/error400.html
    ErrorDocument 404 /error/error404.html
    ErrorDocument 500 /error/error500.html
    ErrorDocument 503 /error/error503.html
</VirtualHost>

 


2. Tomcat

Tomcat의 경우, Spring 프레임워크 기준 WEB-INF아래 web.xml파일에서 Error Page에 대한 정보를 추가

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    ...
    (중략)
    ...
    
    <error-page>
    	<error-code>400</error-code>
        <location>/error/400.jsp</location>
    </error-page>
    <error-page>
    	<error-code>404</error-code>
        <location>/error/404.jsp</location>
    </error-page>
    <error-page>
    	<error-code>500</error-code>
        <location>/error/500.jsp</location>
    </error-page>
</web-app>

각 에러에 해당하는 페이지들을 생성하고, Tomcat에서 에러가 발생한 경우, 위 페이지로 redirect하도록 처리

※ Tomcat에서는 503 에러가 없는 이유는, 503 에러 코드 자체의 의미를 확인하면 알 수 있음

 


보안 취약점 권고

서버 에러페이지를 통해서 [정보누출] 관련 항목으로 보안 취약점에 노출될 수 있음

Tomcat에서의 400에러의 경우, 별도 페이지를 설정하지 않을 경우, 서버 정보가 노출됨

이에 Tomcat의 server.xml에 아래 내용을 추가하여 노출방지

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false">
    ...
    (중략)
    ...
        
    <!-- 에러 페이지 내에서 서버정보노출(showServerInfo)를 false로 설정 --> 
    <Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false"/>
</Host>

 


  • desc: 

Apache와 Tomcat 모두 설정할 필요 없고, 에러 코드에 따라 적절히 설정 (Web / WAS 연동을 제대로 한 경우, 응답 에러 페이지 내에서 특정 정보를 포함하지 않아도 될 경우에는 Apache에서만 처리해도 무방

 


 

  • source:

https://developer.mozilla.org/ko/docs/Web/HTTP/Status/503

 

503 Service Unavailable - HTTP | MDN

하이퍼텍스트 전송 프로토콜 (HTTP) 503 Service Unavailable 서버 에러 응답(response) 코드는 서버가 요청(request)을 처리할 준비가 되지 않은 것을 나타낸다.

developer.mozilla.org

 

728x90