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_log_artifact_azure_with_headers(
    databricks_artifact_repo, test_file, artifact_path, expected_location
):
    mock_azure_headers = {
        "x-ms-encryption-scope": "test-scope",
        "x-ms-tags": "some-tags",
        "x-ms-blob-type": "some-type",
    }
    filtered_azure_headers = {
        "x-ms-encryption-scope": "test-scope",
        "x-ms-tags": "some-tags",
    }
    mock_response = Response()
    mock_response.status_code = 200
    mock_response.close = lambda: None
    mock_credential_info = ArtifactCredentialInfo(
        signed_uri=MOCK_AZURE_SIGNED_URI,
        type=ArtifactCredentialType.AZURE_SAS_URI,
        headers=[
            ArtifactCredentialInfo.HttpHeader(name=header_name, value=header_value)
            for header_name, header_value in mock_azure_headers.items()
        ],
    )
    with mock.patch(
        f"{DATABRICKS_ARTIFACT_REPOSITORY}._get_credential_infos",
        return_value=[mock_credential_info],
    ) as get_credential_infos_mock, mock.patch(
        "requests.Session.request", return_value=mock_response
    ) as request_mock:
        databricks_artifact_repo.log_artifact(test_file, artifact_path)
        get_credential_infos_mock.assert_called_with(
            GetCredentialsForWrite, MOCK_RUN_ID, [expected_location]
        )
        request_mock.assert_called_with(
            "put",
            f"{MOCK_AZURE_SIGNED_URI}?comp=blocklist",
            allow_redirects=True,
            data=ANY,
            headers=filtered_azure_headers,
            timeout=None,
        )