Fix FileNotFoundError handling in rename_file methods #1548
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
FileNotFoundError
exception handling to both synchronous and asynchronousrename_file
methods inFileContentsManager
Changes Made
Modified
jupyter_server/services/contents/filemanager.py
:FileNotFoundError
exception handling inrename_file
method (line ~605)FileNotFoundError
exception handling in asyncrename_file
method (line ~1073)Added test coverage:
test_rename_nonexistent
intests/services/contents/test_manager.py
Testing
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.