Language: Python
Label: safe
CWE: CWE-918 \u2014 Server-Side Request Forgery (SSRF)
The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.

Code:
def test_http_request_with_aws_sigv4(request, monkeypatch):
    """This test requires the "requests_auth_aws_sigv4" package to be installed"""

    from requests_auth_aws_sigv4 import AWSSigV4

    monkeypatch.setenvs(
        {
            "AWS_ACCESS_KEY_ID": "access-key",
            "AWS_SECRET_ACCESS_KEY": "secret-key",
            "AWS_DEFAULT_REGION": "eu-west-1",
        }
    )
    aws_sigv4 = MlflowHostCreds("http://my-host", aws_sigv4=True)
    response = mock.MagicMock()
    response.status_code = 200
    request.return_value = response
    http_request(aws_sigv4, "/my/endpoint", "GET")

    class AuthMatcher:
        def __eq__(self, other):
            return isinstance(other, AWSSigV4)

    request.assert_called_once_with(
        "GET",
        "http://my-host/my/endpoint",
        allow_redirects=True,
        verify=mock.ANY,
        headers=mock.ANY,
        timeout=mock.ANY,
        auth=AuthMatcher(),
    )