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 ] Prevent relative path traversal in elaborator scripts #3101

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

AlgebraicWolf
Copy link
Contributor

Description

Compile-time file operations introduced in #3099 attempt to check file paths and prevent exiting the directory specified by LookupDir. This safeguard, however, can be easily fooled by the use of ./ as part of the path. For instance, the following call would result in the creation or modification of a file outside the project directory:

%runElab writeFile ProjectDir "./../outerFile" "uh oh"

This occurs because the introduced function pathDoesNotEscape performs the check by tracking how deep the provided relative path goes down in the directory tree, making sure it doesn't go up more than it goes down. It, however, treats "." like a regular directory, allowing the user to increase the depth perceived by the function "for free". This PR adds special handling of the "." directory in the path to prevent escaping via this mechanism.

Copy link
Member

@gallais gallais left a comment

Choose a reason for hiding this comment

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

Haha, nice one!

@gallais gallais merged commit 3e5d8a5 into idris-lang:main Oct 16, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants