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

Never allow '..' in OS.get_safe_dir_name(), fixes minor security concern, add unit tests for it #65755

Closed

Conversation

nathanfranke
Copy link
Contributor

Previous behavior: '..' is allowed if 'allow_dir_separator' is false, which doesn't really make sense, I think it was a mistake in original implementation.

…ern, add unit tests for it

Previous behavior: '..' is allowed if 'allow_dir_separator' is false, which doesn't really make sense, I think it was a mistake in original implementation.
@nathanfranke nathanfranke requested a review from a team as a code owner September 13, 2022 18:11
@nathanfranke nathanfranke changed the title Never allow '..' in OS.get_safe_dir_name(), fixes minor security concern Never allow '..' in OS.get_safe_dir_name(), fixes minor security concern, add unit tests for it Sep 13, 2022

// Never allow '..', it is dangerous! (whether that is an overstatement depends on the use case, but we should always be careful with user input).
CHECK_MESSAGE(
OS::get_singleton()->get_safe_dir_name("../../secret/files.txt") == "----secret-files.txt",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ---- makes sense, but if someone disagrees let me know here.

Suggested change
OS::get_singleton()->get_safe_dir_name("../../secret/files.txt") == "----secret-files.txt",
OS::get_singleton()->get_safe_dir_name("../../secret/files.txt") == "secret-files.txt",

@Calinou Calinou added this to the 4.0 milestone Sep 13, 2022
@mortarroad
Copy link
Contributor

mortarroad commented Sep 14, 2022

Won't this turn something like "a/../b" into "a/--/b" if p_allow_dir_separator is true?
I kind of doubt that that's desirable.

@akien-mga
Copy link
Member

Superseded by #71396.

@akien-mga akien-mga closed this Feb 13, 2023
@nathanfranke nathanfranke deleted the never-allow-dot-dot branch February 19, 2023 02:09
@nathanfranke nathanfranke restored the never-allow-dot-dot branch February 19, 2023 04:39
@nathanfranke nathanfranke deleted the never-allow-dot-dot branch February 19, 2023 04:39
@nathanfranke nathanfranke restored the never-allow-dot-dot branch February 19, 2023 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants