Use of unsanitized data to make API calls 이 페이지는 아직 한국어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우
언제든지 연락주시기 바랍니다.
이 규칙을 사용해 보세요 ID: python-flask/ssrf-requests
Language: Python
Severity: Error
Category: Security
CWE : 918
Description Use of unsanitized data from incoming request for handling SQL request may lead to SQL injection. Incoming request data must always be sanitized before used.
Learn More Non-Compliant Code Examples import flask
import requests
app = flask . Flask ( __name__ )
@app.route ( "/route/to/resource/<resource_id>" )
def resource ( resource_id ):
foo = requests . get ( f "https://api.service.ext/get/by/id/ { resource_id } " )
return None
@app.route ( "/route/to/resource/<resource_id>" )
def resource2 ( resource_id ):
bar = requests . get ( "https://api.service.ext/get/by/id/" + resource_id })
return None
@app.route ( "/route/to/resource/<resource_id>" )
def resource3 ( resource_id ):
baz = requests . get ( "https://api.service.ext/get/by/id/ {0} " . format ( resource_id }))
return None
@app.get ( "/route/to/another/resource/<resource_id>" )
def resource4 ( resource_id ):
foo = requests . get ( f "https://api.service.ext/get/by/id/ { resource_id } " )
return None
@app.get ( "/route/to/another/resource/<resource_id>" )
def resource5 ( resource_id ):
bar = requests . get ( "https://api.service.ext/get/by/id/" + resource_id })
return None
@app.get ( "/route/to/another/resource/<resource_id>" )
def resource6 ( resource_id ):
baz = requests . get ( "https://api.service.ext/get/by/id/ {0} " . format ( resource_id }))
return None
@app.route ( "/route/to/resource/the/return/<resource_id>" , methods = [ "GET" ])
def get_param ():
rid = flask . request . args . get ( "resource_id" )
# unsanitized data
requests . post ( f "https://api.service.ext/get/by/id/ { rid } " , timeout = 10 )
requests . patch ( rid , timeout = 10 )
requests . get ( "https://api.service.ext/get/by/id/ {0} " . format ( rid ))
requests . get ( "https://api.service.ext/get/by/id/" + rid )
requests . patch ( rid , timeout = 10 )
return None
@app.route ( "/this/is/fine/<sure>" )
def fine ( sure ):
print ( "foobar" )
return requests . get ( "https://api.service.ext/nothing" )
Compliant Code Examples import flask
import requests
app = flask . Flask ( __name__ )
@app.route ( "/route/to/resource/<resource_id>" )
def resource ( resource_id ):
sanitized_resource_id = sanitize ( resource_id )
foo = requests . get ( f "https://api.service.ext/get/by/id/ { sanitized_resource_id } " )
return foo
원활한 통합. Datadog Code Security를 경험해 보세요