- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- Administrator's Guide
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: python-flask/avoid-ssrf
Language: Python
Severity: Error
Category: Security
CWE: 918
This rule helps prevent Server-Side Request Forgery (SSRF) attacks. SSRF attacks manipulate the server to make HTTP requests to an arbitrary domain of the attacker’s choosing. This can lead to unauthorized actions or access to data within the server, potentially exposing sensitive information.
This rule is important to enforce because SSRF attacks can cause significant damage, allowing attackers to bypass firewall protections, perform actions on behalf of the server, or gain unauthorized access to data. The impact of such an attack can be severe, leading to data breaches or server control takeover.
Good coding practices to avoid SSRF attacks include validating and sanitizing user inputs and limiting the server’s ability to initiate outbound requests.
@app.route("/cmd", methods=['POST'])
def cmd():
filename = request.form['filename']
try:
if "http" not in str(urlparse(filename).scheme):
host = request.url[:-4]
filename = host+"/static/" + filename
result = eval(requests.get(filename).text)
return render_template("index.html", result=result)
else:
result = eval(requests.get(filename).text)
return render_template("index.html", result=result)
except Exception:
return render_template("index.html", result="Unexpected error during the execution of the predefined command.")
import requests
from flask import request, render_template
from urllib.parse import urlparse
@app.route("/cmd", methods=['POST'])
def cmd():
filename = request.form.get('filename')
try:
if not filename or len(filename) > 255:
raise ValueError("Invalid filename")
if any(c in filename for c in [';', '&', '|', '$', '<', '>', '`']):
raise ValueError("Invalid filename")
parsed_url = urlparse(filename)
if parsed_url.scheme not in ["http", "https"]:
host = request.url_root.rstrip('/')
filename = f"{host}/static/{filename}"
response = requests.get(filename)
response.raise_for_status()
result = response.text
return render_template("index.html", result=result)
except Exception as e:
return render_template("index.html", result="Unexpected error during the execution of the predefined command.")