-
Notifications
You must be signed in to change notification settings - Fork 334
Fix Path Traversal in validate_assignment via Path Normalization #1978
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 1 commit
cb21dd4
43c4041
a8c4774
49b4e74
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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,7 +38,10 @@ def load_config(self): | |||||||||||||||||||||
| return app.config | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def validate_notebook(self, path): | ||||||||||||||||||||||
| fullpath = os.path.join(self.root_dir, path) | ||||||||||||||||||||||
| fullpath = os.path.normpath(os.path.join(self.root_dir, path)) | ||||||||||||||||||||||
| root_normalized = os.path.normpath(self.root_dir) | ||||||||||||||||||||||
| if not fullpath.startswith(root_normalized + os.sep): | ||||||||||||||||||||||
| raise web.HTTPError(403, "Access denied: path outside allowed directory") | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
||||||||||||||||||||||
| if not fullpath.startswith(root_normalized + os.sep): | |
| raise web.HTTPError(403, "Access denied: path outside allowed directory") | |
| try: | |
| common = os.path.commonpath([fullpath, root_normalized]) | |
| except ValueError: | |
| # Incomparable paths (e.g. different drives on Windows): treat as outside. | |
| raise web.HTTPError(403, "Access denied: path outside allowed directory") | |
| if common != root_normalized: | |
| raise web.HTTPError(403, "Access denied: path outside allowed directory") |
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 normalization order may not properly handle all path traversal cases. When the user-supplied
pathcontains absolute paths or path traversal sequences at the beginning,os.path.join(self.root_dir, path)might not behave as expected. Ifpathstarts with a slash (absolute path),os.path.joinwill discardself.root_dirand return justpath, which could then bypass the security check after normalization.Consider validating that the user-supplied
pathis relative and doesn't start with "/" or contain absolute path components before joining it withroot_dir.