-
Notifications
You must be signed in to change notification settings - Fork 1
🛡️ Sentinel: [HIGH] Fix XSS risk in folder names #134
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
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -273,6 +273,21 @@ | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def is_valid_folder_name(name: str) -> bool: | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| Validates folder name to prevent XSS and ensure printability. | ||||||||||||||||||||||||||||||||||
| Allowed: Anything printable except < > " ' ` | ||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| if not name or not name.isprintable(): | ||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Block XSS and HTML injection characters | ||||||||||||||||||||||||||||||||||
| dangerous_chars = set("<>\"'`") | ||||||||||||||||||||||||||||||||||
| if any(c in dangerous_chars for c in name): | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+281
to
+286
|
||||||||||||||||||||||||||||||||||
| if not name or not name.isprintable(): | |
| return False | |
| # Block XSS and HTML injection characters | |
| dangerous_chars = set("<>\"'`") | |
| if any(c in dangerous_chars for c in name): | |
| # Normalize the folder name the same way it is used elsewhere | |
| stripped = name.strip() | |
| # Reject names that are empty or only whitespace after stripping | |
| if not stripped or not stripped.isprintable(): | |
| return False | |
| # Block XSS and HTML injection characters | |
| dangerous_chars = set("<>\"'`") | |
| if any(c in dangerous_chars for c in stripped): |
Check warning
Code scanning / Prospector (reported by Codacy)
Use lazy % formatting in logging functions (logging-fstring-interpolation) Warning
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Use lazy % formatting in logging functions Note
Check warning
Code scanning / Prospector (reported by Codacy)
Use lazy % formatting in logging functions (logging-fstring-interpolation) Warning
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Use lazy % formatting in logging functions Note
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||
| import pytest | ||||
Check warningCode scanning / Pylint (reported by Codacy) Missing module docstring Warning test
Missing module docstring
Check warningCode scanning / Prospector (reported by Codacy) Unable to import 'pytest' (import-error) Warning test
Unable to import 'pytest' (import-error)
Check warningCode scanning / Pylintpython3 (reported by Codacy) Missing module docstring Warning test
Missing module docstring
Check warningCode scanning / Prospector (reported by Codacy) Unused import pytest (unused-import) Warning test
Unused import pytest (unused-import)
Check noticeCode scanning / Pylint (reported by Codacy) Unused import pytest Note test
Unused import pytest
Check noticeCode scanning / Pylintpython3 (reported by Codacy) Unused import pytest Note test
Unused import pytest
|
||||
| import pytest |
Check warning
Code scanning / Pylint (reported by Codacy)
standard import "from unittest.mock import MagicMock" should be placed before "import pytest" Warning test
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
standard import "from unittest.mock import MagicMock" should be placed before "import pytest" Warning test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Check notice
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should verify additional XSS vectors and edge cases beyond the basic script tag. Consider adding tests for: HTML event handlers without script tags (e.g., "onload=alert(1)"), HTML entities (e.g., "<script>"), mixed case attempts (though these may not bypass the character check), and Unicode normalization attacks if applicable. Also consider testing the backtick character explicitly since it's in the dangerous_chars set but not tested.
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test cases should include edge cases for whitespace handling since the actual code usage strips folder names with .strip(). Consider adding test cases for: folder names with leading/trailing whitespace (e.g., " Valid Name "), folder names that are only whitespace (e.g., " "), and folder names that become empty after stripping. These edge cases are important to verify that the validation properly handles the stripping behavior seen in the main code.
Check notice
Code scanning / Remark-lint (reported by Codacy)
Warn when references to undefined definitions are found. Note