Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



This PR sandbox calls to requests.get to be more resistant to Server-Side Request Forgery (SSRF) attacks.
Most of the time, when you make a GET request to a URL, you intend to reference an HTTP endpoint, like an internal microservice. However, URLs can point to local file system files, a Gopher stream in your local network, a JAR file on a remote Internet site, and all kinds of other unexpected and undesirable outcomes. When the URL values are influenced by attackers, they can trick your application into fetching internal resources, running malicious code, or otherwise harming the system.
In this case, an attacker could supply a value like "http://169.254.169.254/user-data/" and attempt to access user information.
The changes introduce sandboxing around URL creation that forces developers to specify some boundaries on the types of URLs they expect to create:
from flask import Flask, request
from security import safe_requests
app = Flask(name)
@app.route("/request-url")
def request_url():
url = request.args["loc"]
...
This change reduces attack surface significantly because of the default behavior of safe_requests.get raises a SecurityException if a user attempts to access a known infrastructure location, unless specifically disabled.
Dependency Updates
This PR relies on an external dependency. We have automatically added this dependency to your project's requirements.txt file.
This library holds security tools for protecting Python API calls.