Skip to content
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

Fix rename_file to handle relative paths properly (related to GHSA-v7vq-3x77-87vg?) #6609

Merged
merged 4 commits into from
Dec 9, 2022

Conversation

yacchin1205
Copy link

@yacchin1205 yacchin1205 commented Nov 2, 2022

Fix #6473 and I assume that this completely resolves GHSA-v7vq-3x77-87vg.

As @jinzhen-lin mentions in #6473, if a path of the same length as notebook_dir is given in rename_file, it is interpreted as an attempt to rename a file named .ipynb, which is misjudged as a hidden file because the first character is ..
This problem could be caused by old_path and new_path of rename_file are relative paths, but is_hidden is assumed to be an absolute path. Therefore, I modified the code of rename_file so that absolute paths are provided to is_hidden.

Additionally, the test was also fixed. The test passed until now, but it did not test if rename_file raises the expected error. Because the FileContentsManager.new before it raised HTTPError and marks it as success. (is_hidden is also called in new.)

[Related to the security advisory?]
The original commit seems to be jupyter-server/jupyter_server@877da10 on jupyter_server. (This commit seems to handle absolute paths properly.) This appears to be related to Security Advisory GHSA-v7vq-3x77-87vg So I consider this PR may be an important fix.

@RRosio
Copy link
Collaborator

RRosio commented Nov 15, 2022

Hi @yacchin1205, thank you for submitting this PR! One point of interest that has come up while speaking with @echarles, would it be possible to update the tests to be more in line with the testing done for this functionality in jupyter-server? After this PR is merged it would be great to have these changes added to the 6.5.x branch as well!

@yacchin1205
Copy link
Author

Thank you for your reply, @RRosio . OK, I will update the tests!

@yacchin1205
Copy link
Author

@RRosio I referred to jupyter-server and found the same problem in the test of jupyter-server, so I fixed the test and found the (new) problem 😓 .
I made a Pull Request for the issue. jupyter-server/jupyter_server#1073 .
I will wait for it to be accepted and try to fix this Pull Request as well.

@yacchin1205
Copy link
Author

Hi @RRosio , The fixes to the test on jupyter-server have also been merged, and I have modified this test accordingly. Please review it.

@RRosio
Copy link
Collaborator

RRosio commented Nov 23, 2022

Hi @yacchin1205 thank you for implementing these updates. I have brought up this PR in the notebook community meeting and there was interest in a little more testing on our end to ensure that these updates have no other side-effects.

@RRosio
Copy link
Collaborator

RRosio commented Dec 2, 2022

Hi @yacchin1205, thank you again for your work with this update. One question we have is in regards to the order of the is_hidden function call in the delete_file methods. The changes recently merged into jupyter_server mean the is_hidden checks happen at a different point than in Notebook. Would you please share with us the reason this may be necessary? Thank you in advance!

delete_file_difference

@yacchin1205
Copy link
Author

Hi @RRosio , The reason why delete_file checks for hidden files before checking for existence, I understand, is due to a problem that allows some files (e.g. .ssh/id_rsa) to be checked for existence.
(So I assume that the current implementation of rename_file also checks whether the file is hidden first.)

If you would like to add the same fix to delete_file of jupyter_server here, I can add it this PR. How about it?

@RRosio
Copy link
Collaborator

RRosio commented Dec 6, 2022

Thank you for your response @yacchin1205!

If you would like to add the same fix to delete_file of jupyter_server here, I can add it this PR. How about it?

Yes, if you could please add that fix here, that would be great!

@yacchin1205
Copy link
Author

Hi @RRosio , I have committed a fix regarding delete_file. Please review it!

@echarles
Copy link
Member

echarles commented Dec 9, 2022

I have tested the latest commit and confirms the hidden files are not shown on my env and can not be addressed directly.

@RRosio RRosio added the bug label Dec 9, 2022
@RRosio
Copy link
Collaborator

RRosio commented Dec 9, 2022

Thank you for the updates @yacchin1205! This looks great! Feel free to let us know whether you would like to submit these same updates to 6.5.x as well.

@yacchin1205
Copy link
Author

yacchin1205 commented Dec 10, 2022

Thank you for the merge @RRosio ! I have also created a Pull Request for 6.5.x (PR #6660). I would appreciate it if you could check that as well.

RRosio pushed a commit that referenced this pull request Dec 12, 2022
…dden files properly) (#6660)

* Fix the path form for rename_file

* Fix tests for rename_file to give values in relative paths

* Fix tests to be in line with jupyter-server

* Fix for determining whether a file is hidden and tests for delete_file

Co-authored-by: yacchin1205 <968739+yacchin1205@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants