How to Check a URL for Server-Side Request Forgery (SSRF) Threats using Python

Cloudmersive
2 min readJul 20, 2022

Many forms of cyber attacks can leave you and/or your business helpless as an unknown malicious actor gains access to your database. Server-side Request Forgery (SSRF) attacks are a common method used by hackers to achieve that end goal, and they can frequently be successful without adequate protection for your network. Thankfully, our SSRF Detection API can put your fears to rest by identifying whether or not a given URL is clean (true) or not (false), and by providing a statement on the degree to which that URL was a threat. The below JSON represents a sample API response model for your reference:

{
"CleanURL": true,
"ThreatLevel": "string"
}

Below, we’ll demonstrate how to use this API for free with a free-tier Cloudmersive API key (you can get one by registering a free account on our website). We’ll quickly walk through how to structure an API call with ready-to-run code provided in Python.

To start off, let’s run the following command to install the Python SDK:

pip install cloudmersive-security-api-client

Now let’s begin structuring our call by adding the imports & API key authorization snippet:

from __future__ import print_function
import time
import cloudmersive_security_api_client
from cloudmersive_security_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_security_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

And let’s wrap it up by including the remaining block:

# create an instance of the API class
api_instance = cloudmersive_security_api_client.NetworkThreatDetectionApi(cloudmersive_security_api_client.ApiClient(configuration))
request = cloudmersive_security_api_client.UrlSsrfThreatDetectionRequestFull() # UrlSsrfThreatDetectionRequestFull | Input URL request
try:
# Check a URL for Server-side Request Forgery (SSRF) threats
api_response = api_instance.network_threat_detection_detect_ssrf_url(request)
pprint(api_response)
except ApiException as e:
print("Exception when calling NetworkThreatDetectionApi->network_threat_detection_detect_ssrf_url: %s\n" % e)

All done — no more coding required.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.