-
Notifications
You must be signed in to change notification settings - Fork 1
🛡️ Sentinel: [CRITICAL] Fix Path Traversal via Folder ID #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
becb937
1666172
e731ebe
0794fdf
e4899c7
53bca53
94119f4
c7874a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import importlib | ||
| import sys | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| def reload_main_with_env(monkeypatch): | ||
| monkeypatch.delenv("NO_COLOR", raising=False) | ||
| with patch("sys.stderr") as mock_stderr, patch("sys.stdout") as mock_stdout: | ||
| mock_stderr.isatty.return_value = True | ||
| mock_stdout.isatty.return_value = True | ||
|
|
||
| module = sys.modules.get("main") | ||
| if module is None: | ||
| module = importlib.import_module("main") | ||
|
|
||
| importlib.reload(module) | ||
| return module | ||
|
|
||
|
|
||
| def test_verify_access_and_get_folders_filters_malicious_ids(monkeypatch): | ||
| """ | ||
| Verify that verify_access_and_get_folders filters out malicious Folder IDs | ||
| containing path traversal characters (../). | ||
| """ | ||
| m = reload_main_with_env(monkeypatch) | ||
| mock_client = MagicMock() | ||
|
|
||
| # Malicious Folder ID with path traversal | ||
| malicious_id = "../../etc/passwd" | ||
| # Malicious Folder ID with dangerous characters | ||
| malicious_id_2 = "foo;rm -rf /" | ||
|
|
||
| mock_response = MagicMock() | ||
| mock_response.json.return_value = { | ||
| "body": { | ||
| "groups": [ | ||
| {"group": "Safe Folder", "PK": "safe_id_123"}, | ||
| {"group": "Safe Folder 2", "PK": "safe-id-456_789"}, | ||
| {"group": "Malicious Folder", "PK": malicious_id}, | ||
| {"group": "Malicious Folder 2", "PK": malicious_id_2} | ||
| ] | ||
| } | ||
| } | ||
| mock_client.get.return_value = mock_response | ||
| mock_response.raise_for_status.return_value = None | ||
|
|
||
| # Function should filter out malicious IDs | ||
| result = m.verify_access_and_get_folders(mock_client, "valid_profile") | ||
|
|
||
| assert result is not None | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| # Check that valid IDs are preserved | ||
| assert "Safe Folder" in result | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert result["Safe Folder"] == "safe_id_123" | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert "Safe Folder 2" in result | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert result["Safe Folder 2"] == "safe-id-456_789" | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
|
||
| # Check that malicious IDs are removed | ||
| assert "Malicious Folder" not in result | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
| assert "Malicious Folder 2" not in result | ||
Check noticeCode scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.