Server-side request forgery (ARCH2104)
Esta página aún no está disponible en tu idioma.
Key python.security.ssrf · Severity warning · Category security · CWE CWE-918
Making an outbound request to a user-controlled URL without validation lets an attacker force the server to hit internal services or cloud metadata endpoints.
Incorrect
Section titled “Incorrect”import requestsfrom flask import request
def fetch(): url = request.args["url"] return requests.get(url).textCorrect
Section titled “Correct”import requestsfrom urllib.parse import urlparsefrom flask import request
ALLOWED = {"api.example.com"}
def fetch(): url = request.args["url"] if urlparse(url).hostname not in ALLOWED: raise ValueError("host not allowed") return requests.get(url).textValidate outbound URLs against an allowlist; block private IP ranges and metadata endpoints.