설명
서버 버전, 소프트웨어 구성 요소, 디버그 메시지가 응답에 포함되면 애플리케이션의 내부 정보가 사용자에게 노출될 수 있습니다.
잠재적 영향
- 공격 표면 증가: 공격자는 노출된 정보를 바탕으로 시스템의 취약점을 찾고 공격할 수 있습니다.
- 취약점 악용: 서버 소프트웨어의 버전 정보 등을 통해 알려진 취약점을 악용할 수 있습니다.
- 시스템 손상: 민감한 정보가 노출되어 시스템이 손상되거나 데이터가 유출될 수 있습니다.
해결 방법
- 운영 환경에서는 애플리케이션의 디버그 모드를 끄고 오류 응답에 내부 정보가 남는지 확인하세요.
- 웹 서버와 프록시의 응답 헤더도 확인해 불필요한 서버·버전 정보를 제거하세요.
예시
Django
변경 전
python
# Unsafe Django code (DEBUG mode enabled)
from django.http import HttpResponse
def unsafe_view(request):
return HttpResponse("Hello, world!")
# settings.py
DEBUG = True
변경 후
python
# Safe Django code (DEBUG mode disabled)
from django.http import HttpResponse
def safe_view(request):
return HttpResponse("Hello, world!")
# settings.py
DEBUG = False
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_HSTS_SECONDS = 3600
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
Django는 DEBUG=False로 설정합니다. 함께 표시한 HTTPS·HSTS 설정을 적용하려면 HTTPS로 배포하고 SecurityMiddleware를 구성해야 합니다. 세션 쿠키와 CSRF 쿠키에도 HTTPS 전송을 지정합니다.
Flask
변경 전
python
# Unsafe Flask code (DEBUG mode enabled)
from flask import Flask
app = Flask(__name__)
app.config['DEBUG'] = True
@app.route('/')
def unsafe():
return "Hello, world!"
변경 후
python
# Safe Flask code (DEBUG mode disabled)
from flask import Flask
app = Flask(__name__)
app.config['DEBUG'] = False
app.config['SESSION_COOKIE_SECURE'] = True
app.config['REMEMBER_COOKIE_SECURE'] = True
@app.route('/')
def safe():
return "Hello, world!"
Flask는 DEBUG를 끄고 세션 쿠키를 HTTPS로 제한합니다. REMEMBER_COOKIE_SECURE는 Flask-Login의 로그인 유지 쿠키에 적용됩니다.
FastAPI
변경 전
python
# Unsafe FastAPI code (Debug mode enabled)
from fastapi import FastAPI
app = FastAPI(debug=True)
@app.get("/")
async def unsafe():
return {"message": "Hello, world!"}
변경 후
python
# Safe FastAPI code (Debug mode disabled)
from fastapi import FastAPI
app = FastAPI(debug=False)
@app.get("/")
async def safe():
return {"message": "Hello, world!"}
FastAPI에서는 앱을 생성할 때 debug=False를 지정합니다.
참조
- OWASP: Information Exposure
- CWE: CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
- CWE: CWE-209: Generation of Error Message Containing Sensitive Information
- CWE: CWE-497: Exposure of Sensitive System Information to an Unauthorized Control Sphere
- Django 4.0의 제거된 X-XSS-Protection 설정