Fix FileNotFoundError handling in rename_file methods#1548
Merged
Zsailer merged 6 commits intojupyter-server:mainfrom Aug 20, 2025
Merged
Fix FileNotFoundError handling in rename_file methods#1548Zsailer merged 6 commits intojupyter-server:mainfrom
Zsailer merged 6 commits intojupyter-server:mainfrom
Conversation
- Add FileNotFoundError exception handling to both sync and async rename_file methods - Return HTTP 404 error instead of generic 500 error when file/directory doesn't exist - Improves error specificity for file rename operations
- Test that renaming non-existent files returns 404 instead of 500 - Covers both file and directory rename scenarios - Validates proper error message format
7247bb0 to
c2a2533
Compare
cc82c64 to
76b898d
Compare
9a3d547 to
96b8eb5
Compare
for more information, see https://pre-commit.ci
dlqqq
approved these changes
Aug 14, 2025
Contributor
dlqqq
left a comment
There was a problem hiding this comment.
@aws-jasakshi Thank you for contributing this! Code changes look good to me, but I don't have permissions on this repo to merge.
@Zsailer Can you give this PR a review and merge if it looks good to you as well?
Zsailer
approved these changes
Aug 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix FileNotFoundError handling in rename_file methods
Summary
This PR fixes a security issue where the JupyterLab API returns HTTP 500 Internal Server Errors when attempting to rename non-existent files or directories. The fix ensures that proper HTTP 404 errors are returned instead, preventing information disclosure through verbose error messages.
Problem
/jupyterlab/default/api/contents/with a non-existent file path, the API returns HTTP 500 with verbose error messages including stack tracesSolution
FileNotFoundErrorexception handling to both synchronous and asynchronousrename_filemethods inFileContentsManagerChanges Made
Modified
jupyter_server/services/contents/filemanager.py:FileNotFoundErrorexception handling inrename_filemethod (line ~605)FileNotFoundErrorexception handling in asyncrename_filemethod (line ~1073)Added test coverage:
test_rename_nonexistentintests/services/contents/test_manager.pyTesting
Security Considerations
Related Issues
Checklist
Breaking Changes
None. This change only affects error responses for invalid operations and maintains backward compatibility for all valid operations.
Additional Notes
This fix addresses a security vulnerability where verbose error messages could expose internal system information. The change is minimal and focused, affecting only the error handling path for non-existent files during rename operations.