code stringlengths 14 2.05k | label int64 0 1 | programming_language stringclasses 7
values | cwe_id stringlengths 6 14 | cwe_name stringlengths 5 98 ⌀ | description stringlengths 36 379 ⌀ | url stringlengths 36 48 ⌀ | label_name stringclasses 2
values |
|---|---|---|---|---|---|---|---|
def test_can_parse_json_string():
request = mock.MagicMock()
request.method = "POST"
request.content_type = "application/json"
request.get_json = mock.MagicMock()
request.get_json.return_value = '{"name": "hello2"}'
msg = _get_request_message(CreateExperiment(), flask_request=request)
assert... | 1 | Python | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
def test_can_block_post_request_with_missing_content_type():
request = mock.MagicMock()
request.method = "POST"
request.content_type = None
request.get_json = mock.MagicMock()
request.get_json.return_value = {"name": "hello"}
with pytest.raises(MlflowException, match=r"Bad Request. Content-Type"... | 1 | Python | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
def test_can_parse_json():
request = mock.MagicMock()
request.method = "POST"
request.content_type = "application/json"
request.get_json = mock.MagicMock()
request.get_json.return_value = {"name": "hello"}
msg = _get_request_message(CreateExperiment(), flask_request=request)
assert msg.name ... | 1 | Python | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
def test_can_parse_post_json_with_content_type_params():
request = mock.MagicMock()
request.method = "POST"
request.content_type = "application/json; charset=utf-8"
request.get_json = mock.MagicMock()
request.get_json.return_value = {"name": "hello"}
msg = _get_request_message(CreateExperiment()... | 1 | Python | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
def to_html(self) -> str:
"""
Returns a rendered HTML representing the content of the tab.
:return: a HTML string
"""
from jinja2 import BaseLoader
from jinja2.sandbox import SandboxedEnvironment
j2_env = SandboxedEnvironment(loader=BaseLoader()).from_string... | 1 | Python | CWE-1336 | Improper Neutralization of Special Elements Used in a Template Engine | The product uses a template engine to insert or process externally-influenced input, but it does not neutralize or incorrectly neutralizes special elements or syntax that can be interpreted as template expressions or other code directives when processed by the engine. | https://cwe.mitre.org/data/definitions/1336.html | safe |
def is_local_uri(uri, is_tracking_or_registry_uri=True):
"""
Returns true if the specified URI is a local file path (/foo or file:/foo).
:param uri: The URI.
:param is_tracking_uri: Whether or not the specified URI is an MLflow Tracking or MLflow
Model Registry URI. Examples... | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_is_local_uri():
assert is_local_uri("mlruns")
assert is_local_uri("./mlruns")
assert is_local_uri("file:///foo/mlruns")
assert is_local_uri("file:foo/mlruns")
assert is_local_uri("file://./mlruns")
assert is_local_uri("file://localhost/mlruns")
assert is_local_uri("file://localhost:... | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def validate_path_is_safe(path):
"""
Validates that the specified path is safe to join with a trusted prefix. This is a security
measure to prevent path traversal attacks.
A valid path should:
not contain separators other than '/'
not contain .. to navigate to parent dir in path
... | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def validate_path_is_safe(path):
"""
Validates that the specified path is safe to join with a trusted prefix. This is a security
measure to prevent path traversal attacks.
A valid path should:
not contain separators other than '/'
not contain .. to navigate to parent dir in path
... | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_delete_artifact_mlflow_artifacts_throws_for_malicious_path(enable_serve_artifacts, path):
response = _delete_artifact_mlflow_artifacts(path)
assert response.status_code == 400
json_response = json.loads(response.get_data())
assert json_response["error_code"] == ErrorCode.Name(INVALID_PARAMETER_... | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def test_delete_artifact_mlflow_artifacts_throws_for_malicious_path(enable_serve_artifacts, path):
response = _delete_artifact_mlflow_artifacts(path)
assert response.status_code == 400
json_response = json.loads(response.get_data())
assert json_response["error_code"] == ErrorCode.Name(INVALID_PARAMETER_... | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def enable_serve_artifacts(monkeypatch):
monkeypatch.setenv(SERVE_ARTIFACTS_ENV_VAR, "true") | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def enable_serve_artifacts(monkeypatch):
monkeypatch.setenv(SERVE_ARTIFACTS_ENV_VAR, "true") | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_list_artifacts_malicious_path(http_artifact_repo, path):
with mock.patch(
"mlflow.store.artifact.http_artifact_repo.http_request",
return_value=MockResponse(
{
"files": [
{"path": path, "is_dir": False, "file_size": 1},
]
... | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def test_list_artifacts_malicious_path(http_artifact_repo, path):
with mock.patch(
"mlflow.store.artifact.http_artifact_repo.http_request",
return_value=MockResponse(
{
"files": [
{"path": path, "is_dir": False, "file_size": 1},
]
... | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_path_validation(mlflow_client):
experiment_id = mlflow_client.create_experiment("tags validation")
created_run = mlflow_client.create_run(experiment_id)
run_id = created_run.info.run_id
invalid_path = "../path"
def assert_response(resp):
assert resp.status_code == 400
asser... | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def test_path_validation(mlflow_client):
experiment_id = mlflow_client.create_experiment("tags validation")
created_run = mlflow_client.create_run(experiment_id)
run_id = created_run.info.run_id
invalid_path = "../path"
def assert_response(resp):
assert resp.status_code == 400
asser... | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def assert_response(resp):
assert resp.status_code == 400
assert response.json() == {
"error_code": "INVALID_PARAMETER_VALUE",
"message": "Invalid path",
} | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def assert_response(resp):
assert resp.status_code == 400
assert response.json() == {
"error_code": "INVALID_PARAMETER_VALUE",
"message": "Invalid path",
} | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_validate_path_is_safe_windows_good(path):
validate_path_is_safe(path) | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def test_validate_path_is_safe_windows_good(path):
validate_path_is_safe(path) | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_validate_path_is_safe_good(path):
validate_path_is_safe(path) | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def test_validate_path_is_safe_good(path):
validate_path_is_safe(path) | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_validate_path_is_safe_bad(path):
with pytest.raises(MlflowException, match="Invalid path"):
validate_path_is_safe(path) | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def test_validate_path_is_safe_bad(path):
with pytest.raises(MlflowException, match="Invalid path"):
validate_path_is_safe(path) | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_validate_path_is_safe_windows_bad(path):
with pytest.raises(MlflowException, match="Invalid path"):
validate_path_is_safe(path) | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def test_validate_path_is_safe_windows_bad(path):
with pytest.raises(MlflowException, match="Invalid path"):
validate_path_is_safe(path) | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def load(self, dst_path=None) -> str:
"""
Downloads the dataset source to the local filesystem.
:param dst_path: Path of the local filesystem destination directory to which to download the
dataset source. If the directory does not exist, it is created. If
... | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def _extract_filename(self, response) -> str:
"""
Extracts a filename from the Content-Disposition header or the URL's path.
"""
if content_disposition := response.headers.get("Content-Disposition"):
for match in re.finditer(r"filename=(.+)", content_disposition):
... | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def download_with_mock_content_disposition_headers(*args, **kwargs):
response = cloud_storage_http_request(*args, **kwargs)
response.headers = {"Content-Disposition": f"attachment; filename={filename}"}
return response | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def test_source_load_with_content_disposition_header_invalid_filename_windows(filename):
def download_with_mock_content_disposition_headers(*args, **kwargs):
response = cloud_storage_http_request(*args, **kwargs)
response.headers = {"Content-Disposition": f"attachment; filename={filename}"}
... | 1 | Python | CWE-22 | Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') | The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the... | https://cwe.mitre.org/data/definitions/22.html | safe |
def list_artifacts(self, path=None):
with self.get_ftp_client() as ftp:
artifact_dir = self.path
list_dir = posixpath.join(artifact_dir, path) if path else artifact_dir
if not self._is_dir(ftp, list_dir):
return []
artifact_files = ftp.nlst(lis... | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def test_list_artifacts_malicious_path(ftp_mock):
artifact_root_path = "/experiment_id/run_id/"
repo = FTPArtifactRepository("ftp://test_ftp" + artifact_root_path)
repo.get_ftp_client = MagicMock()
call_mock = MagicMock(return_value=ftp_mock)
repo.get_ftp_client.return_value = MagicMock(__enter__=ca... | 1 | Python | CWE-29 | Path Traversal: '\..\filename' | The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize '\..\filename' (leading backslash dot dot) sequences that can resolve to a location that is outside of that directory. | https://cwe.mitre.org/data/definitions/29.html | safe |
def _create_multipart_upload_artifact(artifact_path):
"""
A request handler for `POST /mlflow-artifacts/mpu/create` to create a multipart upload
to `artifact_path` (a relative path from the root artifact directory).
"""
artifact_path = validate_path_is_safe(artifact_path)
request_message = _get... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def get_artifact_handler():
from querystring_parser import parser
query_string = request.query_string.decode("utf-8")
request_dict = parser.parse(query_string, normalized=True)
run_id = request_dict.get("run_id") or request_dict.get("run_uuid")
path = request_dict["path"]
path = validate_path_i... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def _delete_artifact_mlflow_artifacts(artifact_path):
"""
A request handler for `DELETE /mlflow-artifacts/artifacts?path=<value>` to delete artifacts in
`path` (a relative path from the root artifact directory).
"""
artifact_path = validate_path_is_safe(artifact_path)
_get_request_message(Delete... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def _list_artifacts():
request_message = _get_request_message(
ListArtifacts(),
schema={
"run_id": [_assert_string, _assert_required],
"path": [_assert_string],
"page_token": [_assert_string],
},
)
response_message = ListArtifacts.Response()
if... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def _abort_multipart_upload_artifact(artifact_path):
"""
A request handler for `POST /mlflow-artifacts/mpu/abort` to abort a multipart upload
to `artifact_path` (a relative path from the root artifact directory).
"""
artifact_path = validate_path_is_safe(artifact_path)
request_message = _get_re... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def get_model_version_artifact_handler():
from querystring_parser import parser
query_string = request.query_string.decode("utf-8")
request_dict = parser.parse(query_string, normalized=True)
name = request_dict.get("name")
version = request_dict.get("version")
path = request_dict["path"]
pa... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def _download_artifact(artifact_path):
"""
A request handler for `GET /mlflow-artifacts/artifacts/<artifact_path>` to download an artifact
from `artifact_path` (a relative path from the root artifact directory).
"""
artifact_path = validate_path_is_safe(artifact_path)
tmp_dir = tempfile.Temporar... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def _complete_multipart_upload_artifact(artifact_path):
"""
A request handler for `POST /mlflow-artifacts/mpu/complete` to complete a multipart upload
to `artifact_path` (a relative path from the root artifact directory).
"""
artifact_path = validate_path_is_safe(artifact_path)
request_message ... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def _list_artifacts_mlflow_artifacts():
"""
A request handler for `GET /mlflow-artifacts/artifacts?path=<value>` to list artifacts in `path`
(a relative path from the root artifact directory).
"""
request_message = _get_request_message(ListArtifactsMlflowArtifacts())
path = validate_path_is_safe... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def _upload_artifact(artifact_path):
"""
A request handler for `PUT /mlflow-artifacts/artifacts/<artifact_path>` to upload an artifact
to `artifact_path` (a relative path from the root artifact directory).
"""
artifact_path = validate_path_is_safe(artifact_path)
head, tail = posixpath.split(arti... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def list_artifacts(self, path=None):
endpoint = "/mlflow-artifacts/artifacts"
url, tail = self.artifact_uri.split(endpoint, maxsplit=1)
root = tail.lstrip("/")
params = {"path": posixpath.join(root, path) if path else root}
host_creds = _get_default_host_creds(url)
re... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def validate_path_is_safe(path):
"""
Validates that the specified path is safe to join with a trusted prefix. This is a security
measure to prevent path traversal attacks.
A valid path should:
not contain separators other than '/'
not contain .. to navigate to parent dir in path
... | 1 | Python | CWE-434 | Unrestricted Upload of File with Dangerous Type | The product allows the attacker to upload or transfer files of dangerous types that can be automatically processed within the product's environment. | https://cwe.mitre.org/data/definitions/434.html | safe |
def _get_http_response_with_retries(
method,
url,
max_retries,
backoff_factor,
backoff_jitter,
retry_codes,
raise_on_status=True,
allow_redirects=None,
**kwargs,
):
"""
Performs an HTTP request using Python's `requests` module with an automatic retry policy.
:param metho... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_databricks_http_request_integration(get_config, request):
"""Confirms that the databricks http request params can in fact be used as an HTTP request"""
def confirm_request_params(*args, **kwargs):
headers = DefaultRequestHeaderProvider().request_headers()
headers["Authorization"] = "Ba... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def confirm_request_params(*args, **kwargs):
headers = DefaultRequestHeaderProvider().request_headers()
headers["Authorization"] = "Basic dXNlcjpwYXNz"
assert args == ("PUT", "host/clusters/list")
assert kwargs == {
"allow_redirects": True,
"headers": headers,... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_log_artifact_gcp_with_headers(
databricks_artifact_repo, test_file, artifact_path, expected_location
):
expected_headers = {header.name: header.value for header in MOCK_HEADERS}
mock_response = Response()
mock_response.status_code = 200
mock_response.close = lambda: None
mock_credential... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
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-enc... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_log_artifact_aws(databricks_artifact_repo, test_file, artifact_path, expected_location):
mock_response = Response()
mock_response.status_code = 200
mock_response.close = lambda: None
mock_credential_info = ArtifactCredentialInfo(
signed_uri=MOCK_AWS_SIGNED_URI, type=ArtifactCredentialTy... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_log_artifact_adls_gen2_flush_error(databricks_artifact_repo, test_file):
mock_successful_response = Response()
mock_successful_response.status_code = 200
mock_successful_response.close = lambda: None
mock_error_response = MlflowException("MOCK ERROR")
mock_credential_info = ArtifactCredenti... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_log_artifact_gcp(databricks_artifact_repo, test_file, artifact_path, expected_location):
mock_response = Response()
mock_response.status_code = 200
mock_response.close = lambda: None
mock_credential_info = ArtifactCredentialInfo(
signed_uri=MOCK_GCP_SIGNED_URL, type=ArtifactCredentialTy... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_log_artifact_aws_with_headers(
databricks_artifact_repo, test_file, artifact_path, expected_location
):
expected_headers = {header.name: header.value for header in MOCK_HEADERS}
mock_response = Response()
mock_response.status_code = 200
mock_response.close = lambda: None
mock_credential... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_successful_http_request(request):
def mock_request(*args, **kwargs):
# Filter out None arguments
assert args == ("POST", "https://hello/api/2.0/mlflow/experiments/search")
kwargs = {k: v for k, v in kwargs.items() if v is not None}
assert kwargs == {
"allow_redir... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def mock_request(*args, **kwargs):
# Filter out None arguments
assert args == ("POST", "https://hello/api/2.0/mlflow/experiments/search")
kwargs = {k: v for k, v in kwargs.items() if v is not None}
assert kwargs == {
"allow_redirects": True,
"json": {"view_typ... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_redirects_disabled_if_env_var_set(monkeypatch, env_value):
monkeypatch.setenv("MLFLOW_ALLOW_HTTP_REDIRECTS", env_value)
with mock.patch("requests.Session.request") as mock_request:
mock_request.return_value.status_code = 302
mock_request.return_value.text = "mock response"
res... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_redirects_enabled_by_default():
with mock.patch("requests.Session.request") as mock_request:
mock_request.return_value.status_code = 302
mock_request.return_value.text = "mock response"
response = request_utils.cloud_storage_http_request(
"GET",
"http://loca... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_redirects_enabled_if_env_var_set(monkeypatch, env_value):
monkeypatch.setenv("MLFLOW_ALLOW_HTTP_REDIRECTS", env_value)
with mock.patch("requests.Session.request") as mock_request:
mock_request.return_value.status_code = 302
mock_request.return_value.text = "mock response"
resp... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_redirect_kwarg_overrides_env_value_true(monkeypatch, env_value):
monkeypatch.setenv("MLFLOW_ALLOW_HTTP_REDIRECTS", env_value)
with mock.patch("requests.Session.request") as mock_request:
mock_request.return_value.status_code = 302
mock_request.return_value.text = "mock response"
... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_redirect_kwarg_overrides_env_value_false(monkeypatch, env_value):
monkeypatch.setenv("MLFLOW_ALLOW_HTTP_REDIRECTS", env_value)
with mock.patch("requests.Session.request") as mock_request:
mock_request.return_value.status_code = 302
mock_request.return_value.text = "mock response"
... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_with_token(request):
host_only = MlflowHostCreds("http://my-host", token="my-token")
response = mock.MagicMock()
response.status_code = 200
request.return_value = response
http_request(host_only, "/my/endpoint", "GET")
headers = DefaultRequestHeaderProvider().request_header... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_with_content_type_header(request):
host_only = MlflowHostCreds("http://my-host", token="my-token")
response = mock.MagicMock()
response.status_code = 200
request.return_value = response
extra_headers = {"Content-Type": "text/plain"}
http_request(host_only, "/my/endpoint", "... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
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... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_client_cert_path(request):
host_only = MlflowHostCreds("http://my-host", client_cert_path="/some/path")
response = mock.MagicMock()
response.status_code = 200
request.return_value = response
http_request(host_only, "/my/endpoint", "GET")
request.assert_called_with(
... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_server_cert_path(request):
host_only = MlflowHostCreds("http://my-host", server_cert_path="/some/path")
response = mock.MagicMock()
response.status_code = 200
request.return_value = response
http_request(host_only, "/my/endpoint", "GET")
request.assert_called_with(
... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_request_headers(request):
"""This test requires the package in tests/resources/mlflow-test-plugin to be installed"""
from mlflow_test_plugin.request_header_provider import PluginRequestHeaderProvider
# The test plugin's request header provider always returns False from in_context to ... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_hostonly(request):
host_only = MlflowHostCreds("http://my-host")
response = mock.MagicMock()
response.status_code = 200
request.return_value = response
http_request(host_only, "/my/endpoint", "GET")
request.assert_called_with(
"GET",
"http://my-host/my/endpo... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_request_headers_user_agent_and_extra_header(request):
"""This test requires the package in tests/resources/mlflow-test-plugin to be installed"""
from mlflow_test_plugin.request_header_provider import PluginRequestHeaderProvider
# The test plugin's request header provider always retur... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_provide_redirect_kwarg():
with mock.patch("requests.Session.request") as mock_request:
mock_request.return_value.status_code = 302
mock_request.return_value.text = "mock response"
response = http_request(
MlflowHostCreds("http://my-host"),
"/my/endpoint",
... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_with_basic_auth(request):
host_only = MlflowHostCreds("http://my-host", username="user", password="pass")
response = mock.MagicMock()
response.status_code = 200
request.return_value = response
http_request(host_only, "/my/endpoint", "GET")
headers = DefaultRequestHeaderProv... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_with_insecure(request):
host_only = MlflowHostCreds("http://my-host", ignore_tls_verification=True)
response = mock.MagicMock()
response.status_code = 200
request.return_value = response
http_request(host_only, "/my/endpoint", "GET")
request.assert_called_with(
"GET... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_request_headers_user_agent(request):
"""This test requires the package in tests/resources/mlflow-test-plugin to be installed"""
from mlflow_test_plugin.request_header_provider import PluginRequestHeaderProvider
# The test plugin's request header provider always returns False from in_... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_with_auth(fetch_auth, request):
mock_fetch_auth = {"test_name": "test_auth_value"}
fetch_auth.return_value = mock_fetch_auth
auth = "test_auth_name"
host_only = MlflowHostCreds("http://my-host", auth=auth)
response = mock.MagicMock()
response.status_code = 200
request.r... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_wrapper(request):
host_only = MlflowHostCreds("http://my-host", ignore_tls_verification=True)
response = mock.MagicMock()
response.status_code = 200
response.text = "{}"
request.return_value = response
http_request_safe(host_only, "/my/endpoint", "GET")
request.assert_c... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def test_http_request_cleans_hostname(request):
# Add a trailing slash, should be removed.
host_only = MlflowHostCreds("http://my-host/")
response = mock.MagicMock()
response.status_code = 200
request.return_value = response
http_request(host_only, "/my/endpoint", "GET")
request.assert_calle... | 1 | Python | CWE-918 | 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. | https://cwe.mitre.org/data/definitions/918.html | safe |
def open_url(self, url):
"""Open the given URL in a new browser window.
Display an error dialog if everything fails.
"""
(r, w) = os.pipe()
if os.fork() > 0:
os.close(w)
status = os.wait()[1]
if status:
title = _("Unable to... | 1 | Python | CWE-269 | Improper Privilege Management | The product does not properly assign, modify, track, or check privileges for an actor, creating an unintended sphere of control for that actor. | https://cwe.mitre.org/data/definitions/269.html | safe |
def run_as_real_user(
args: list[str], *, get_user_env: bool = False, **kwargs
) -> None:
"""Call subprocess.run as real user if called via sudo/pkexec.
If we are called through pkexec/sudo, determine the real user ID and
run the command with it to get the user's web browser settings.
If get_user_e... | 1 | Python | CWE-269 | Improper Privilege Management | The product does not properly assign, modify, track, or check privileges for an actor, creating an unintended sphere of control for that actor. | https://cwe.mitre.org/data/definitions/269.html | safe |
def test_run_as_real_user_no_gvfsd(
self, getpwuid_mock: unittest.mock.MagicMock
) -> None:
"""Test run_as_real_user() without no gvfsd process."""
getpwuid_mock.return_value = pwd.struct_passwd(
(
"testuser",
"x",
1337,
... | 1 | Python | CWE-269 | Improper Privilege Management | The product does not properly assign, modify, track, or check privileges for an actor, creating an unintended sphere of control for that actor. | https://cwe.mitre.org/data/definitions/269.html | safe |
def test_run_as_real_user(self) -> None:
"""Test run_as_real_user() with SUDO_UID set."""
pwuid = pwd.getpwuid(int(os.environ["SUDO_UID"]))
with tempfile.TemporaryDirectory() as tmpdir:
# rename test program to fake gvfsd
gvfsd_mock = os.path.join(tmpdir, "gvfsd")
... | 1 | Python | CWE-269 | Improper Privilege Management | The product does not properly assign, modify, track, or check privileges for an actor, creating an unintended sphere of control for that actor. | https://cwe.mitre.org/data/definitions/269.html | safe |
def redact_sensitive_keys(metadata, redact_value=REDACT_SENSITIVE_VALUE):
"""Redact any sensitive keys from to provided metadata dictionary.
Replace any keys values listed in 'sensitive_keys' with redact_value.
"""
# While 'sensitive_keys' should already sanitized to only include what
# is in metad... | 1 | Python | CWE-532 | Insertion of Sensitive Information into Log File | Information written to log files can be of a sensitive nature and give valuable guidance to an attacker or expose sensitive user information. | https://cwe.mitre.org/data/definitions/532.html | safe |
def process_instance_metadata(metadata, key_path="", sensitive_keys=()):
"""Process all instance metadata cleaning it up for persisting as json.
Strip ci-b64 prefix and catalog any 'base64_encoded_keys' as a list
@return Dict copy of processed metadata.
"""
md_copy = copy.deepcopy(metadata)
ba... | 1 | Python | CWE-532 | Insertion of Sensitive Information into Log File | Information written to log files can be of a sensitive nature and give valuable guidance to an attacker or expose sensitive user information. | https://cwe.mitre.org/data/definitions/532.html | safe |
def _initialize_filesystem(self):
util.ensure_dirs(self._initial_subdirs())
log_file = util.get_cfg_option_str(self.cfg, "def_log_file")
if log_file:
# At this point the log file should have already been created
# in the setupLogging function of log.py
uti... | 1 | Python | CWE-532 | Insertion of Sensitive Information into Log File | Information written to log files can be of a sensitive nature and give valuable guidance to an attacker or expose sensitive user information. | https://cwe.mitre.org/data/definitions/532.html | safe |
def test_existing_file_permissions(self, init, tmpdir):
"""Test file permissions are set as expected.
CIS Hardening requires 640 permissions. These permissions are
currently hardcoded on every boot, but if there's ever a reason
to change this, we need to then ensure that they
... | 1 | Python | CWE-532 | Insertion of Sensitive Information into Log File | Information written to log files can be of a sensitive nature and give valuable guidance to an attacker or expose sensitive user information. | https://cwe.mitre.org/data/definitions/532.html | safe |
def test_regular_user_cant_add_users(self):
response = self.client.get("/admin/auth/user/add/")
self.assertEqual(HTTPStatus.FORBIDDEN, response.status_code)
response = self.client.post(
"/admin/auth/user/add/",
{
"username": "added-by-regular-user",
... | 1 | Python | CWE-521 | Weak Password Requirements | The product does not require that users should have strong passwords, which makes it easier for attackers to compromise user accounts. | https://cwe.mitre.org/data/definitions/521.html | safe |
def test_moderator_can_add_users(self):
user_should_have_perm(self.moderator, "auth.add_user")
user_should_have_perm(self.moderator, "auth.change_user")
# test for https://github.com/kiwitcms/Kiwi/issues/642
self.client.login( # nosec:B106:hardcoded_password_funcarg
use... | 1 | Python | CWE-521 | Weak Password Requirements | The product does not require that users should have strong passwords, which makes it easier for attackers to compromise user accounts. | https://cwe.mitre.org/data/definitions/521.html | safe |
def test_superuser_can_add_users(self):
# test for https://github.com/kiwitcms/Kiwi/issues/642
self.client.login( # nosec:B106:hardcoded_password_funcarg
username=self.admin.username, password="admin-password"
)
response = self.client.get("/admin/auth/user/add/")
... | 1 | Python | CWE-521 | Weak Password Requirements | The product does not require that users should have strong passwords, which makes it easier for attackers to compromise user accounts. | https://cwe.mitre.org/data/definitions/521.html | safe |
def setUp(self):
self.data = {
"username": "test_user",
"password1": __FOR_TESTING__,
"password2": __FOR_TESTING__,
"email": "new-tester@example.com",
} | 1 | Python | CWE-521 | Weak Password Requirements | The product does not require that users should have strong passwords, which makes it easier for attackers to compromise user accounts. | https://cwe.mitre.org/data/definitions/521.html | safe |
def test_invalid_form(self):
response = self.client.post(
self.register_url,
{
"username": "kiwi-tester",
"password1": __FOR_TESTING__,
"password2": f"000-{__FOR_TESTING__}",
"email": "new-tester@example.com",
... | 1 | Python | CWE-521 | Weak Password Requirements | The product does not require that users should have strong passwords, which makes it easier for attackers to compromise user accounts. | https://cwe.mitre.org/data/definitions/521.html | safe |
def assert_user_registration(self, username, follow=False):
with patch("tcms.kiwi_auth.models.secrets") as _secrets:
_secrets.token_hex.return_value = self.fake_activate_key
try:
# https://github.com/mbi/django-simple-captcha/issues/84
# pylint: disab... | 1 | Python | CWE-521 | Weak Password Requirements | The product does not require that users should have strong passwords, which makes it easier for attackers to compromise user accounts. | https://cwe.mitre.org/data/definitions/521.html | safe |
def test_register_user_already_registered(self):
User.objects.create_user("kiwi-tester", "new-tester@example.com", "password")
response = self.client.post(
self.register_url,
{
"username": "test_user",
"password1": __FOR_TESTING__,
... | 1 | Python | CWE-521 | Weak Password Requirements | The product does not require that users should have strong passwords, which makes it easier for attackers to compromise user accounts. | https://cwe.mitre.org/data/definitions/521.html | safe |
def test_send_mail_for_password_reset(self, mail_sent):
user = User.objects.create_user("kiwi-tester", "tester@example.com", "password")
user.is_active = True
user.save()
try:
# https://github.com/mbi/django-simple-captcha/issues/84
# pylint: disable=import-o... | 1 | Python | CWE-770 | Allocation of Resources Without Limits or Throttling | The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor. | https://cwe.mitre.org/data/definitions/770.html | safe |
def process_response(self, request, response):
if settings.DEBUG:
response.headers["X-Frame-Options"] = "DENY"
response.headers["X-Content-Type-Options"] = "nosniff"
response.headers[
"Content-Security-Policy"
] = "script-src 'self' cdn.crowdin... | 1 | Python | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
def test_uploading_svg_with_forbidden_attributes_should_fail(self, file_name):
with open(f"tests/ui/data/{file_name}", "rb") as svg_file:
b64 = base64.b64encode(svg_file.read()).decode()
message = str(_("File contains forbidden attribute:"))
with self.assertRaisesRegex(F... | 1 | Python | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
def deny_uploads_containing_script_tag(uploaded_file):
for chunk in uploaded_file.chunks(2048):
if chunk.lower().find(b"<script") > -1:
raise ValidationError(_("File contains forbidden <script> tag"))
if chunk.lower().find(b"onload=") > -1:
raise ValidationError(_("File cont... | 1 | Python | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
async def save_server(self, request):
await self.elg(request)
guild = self.bot.get_guild(int(request.match_info.get('server', '0')))
if guild is None:
self.notfound()
if not guild.get_member(
int(self.getsesh(request)['client']['id'])
).guild_permissio... | 1 | Python | CWE-20 | Improper Input Validation | The product receives input or data, but it does
not validate or incorrectly validates that the input has the
properties that are required to process the data safely and
correctly. | https://cwe.mitre.org/data/definitions/20.html | safe |
def render_GET(self, request):
template = unsafe_env.get_template('generate_new.html')
sites_len = len(get_all_canary_sites())
now = datetime.datetime.now()
return template.render(settings=settings, sites_len=sites_len, now=now).encode('utf8') | 1 | Python | CWE-79 | Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') | The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. | https://cwe.mitre.org/data/definitions/79.html | safe |
def get_signed_upload_url(path: str) -> str:
client = boto3.client(
"s3",
aws_access_key_id=settings.S3_KEY,
aws_secret_access_key=settings.S3_SECRET_KEY,
region_name=settings.S3_REGION,
endpoint_url=settings.S3_ENDPOINT_URL,
)
return client.generate_presigned_url(
... | 1 | Python | CWE-436 | Interpretation Conflict | Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state. | https://cwe.mitre.org/data/definitions/436.html | safe |
def check_xsend_links(
name: str,
name_str_for_test: str,
content_disposition: str = "",
download: bool = False,
) -> None:
self.login("hamlet")
fp = StringIO("zulip!")
fp.name = name
result = self.client_pos... | 1 | Python | CWE-436 | Interpretation Conflict | Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state. | https://cwe.mitre.org/data/definitions/436.html | safe |
def test_avatar_url_local(self) -> None:
self.login("hamlet")
with get_test_image_file("img.png") as image_file:
result = self.client_post("/json/users/me/avatar", {"file": image_file})
response_dict = self.assert_json_success(result)
self.assertIn("avatar_url", response... | 1 | Python | CWE-436 | Interpretation Conflict | Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state. | https://cwe.mitre.org/data/definitions/436.html | safe |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.