-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Remove expand home (~
) by default in File.expand_path and Path#expand, now opt-in argument
#7903
Conversation
ef4207d
to
1436e26
Compare
I don't think I can relate Maybe we can add an optional argument to But it's always better to discuss this is an issue, not a PR. |
@asterite Absolute is pretty standard and the normal term.
C# is an outlier calling the function Almost all implementations have the 2nd arg as the root directory to allow for caching of Absolute path is what people search for. Not fullpath. And finally |
I think the outlier is actually correct. Absolute seems like unix baggage. Just my opinion. |
@asterite Seeing |
@asterite Perhaps I didn't write enough about the problems with Most application probably want There are also serious security implications for any application using Depending on the application mkdir -p expand/~/.ssh
touch expand/~/.ssh/authorized_keys Dir.cd "expand"
Dir.glob("*/*/*") do |file| # Not sure why ** isn't working.
#Dir.new(".").children.each do |file|
path = Path[file]
puts "path #{path} expanded to #{path.expand}"
end Output:
If anything expand should work the other way around and not expand ~ by default. Or provide |
Okay, disregard my comments. |
1436e26
to
871fd08
Compare
All of the code reviews were addressed. Is there anything else needed to get this PR approved? |
Someone needs to approve it. I won't because I'm not too familiar with Path's API so you'll have to wait for someone else. But don't worry, I'm sure this will be merged. |
The described behaviour is not different from But I'm not convinced we need a separate method for this when it's just a simple delegate. The return value of
This is completely unrelated. If you want to restrict the resulting path to a specific path prefix, you need a different solution anyway. |
Great. Tell me which will be accepted and I'll rework this PR. Home argument on or off by default? Finding the absolute path is a more common operation than home directory lookups. Perhaps off should be the default?
Incorrect. You are describing sanitizing user input which is a different problem. I am describing taking data returned from the file system and turning a relative path in to an absolute path. A file can't be named See my post above on using |
I don't follow what you describe as a security issue regarding |
Let's say you make a file watching application which watches an input dir and performs actions on any file saved there. Maybe it's a javascript minifier, compressor, decompressor, encryption etc service. It works as follows:
Output:
Another example is #7768 which was almost hit by this misfeature. Depending on how he wrote his application the files he downloaded may have read or overwritten any files under his home directory including .bashrc or .ssh/authorized_keys. The files he downloaded were in the form of The default is not safe and there's no current standardized way to get a safe absolute path to a file. |
Okay, I see. This is about the ambiguity of a I agree there needs to be a way to expand a path without There is unfortunately no reliable way to escape a It seems fine to me when you can toggle
Alternatively, we could also remove |
871fd08
to
ad578ad
Compare
I think I wouldn't accept a But don't implement that right away. I'd like to hear some thoughts from others as well. |
Too late. |
Please add specs which pass in |
ad578ad
to
ea8ea6e
Compare
ea8ea6e
to
5512210
Compare
Maybe. It's a breaking change and I'd like feedback from @waj before merging it. |
0.32.0 is the release after next, i meant, wait until after the imminent release to merge this |
@asterite The breaking change is probably not a huge issue because |
Never mind. |
If |
I'd avoid having different behaviour. |
Is there anything for me to do? |
@didactic-drunk May I ask for a rebase on master? After that, if we have a couple of confirmation of the reviews (since it's been a while) we are good to go. I think the other needed thing is to update the PR title and opening comment to reflect the final state of the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to go! Thanks four your patience ❤️
Co-Authored-By: Sijawusz Pur Rahnama <sija@sija.pl> Co-Authored-By: Johannes Müller <johannes.mueller@smj-fulda.org>
7f0a5e6
to
cf2b5f9
Compare
@bcardiff Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a big breaking change that might make fail a lot of apps out there with no indication as to why it fails, other than looking at the changelog and hoping users will find a reference to the File.expand_path
entry, and also hoping users will figure out why their code is suddenly failing on non-expanded paths. But we can give it a try.
Actually, maybe not that many apps will fail. Only those with a hardcoded "~/" in their code will, because I guess if you want to pass that as a command line argument the shell will expand it for you first. The other possibility is that these paths are in a config file but I'm not sure how likely is that. |
~
) by default in File.expand_path and Path#expand, now opt-in argument
I think this title makes it more clear that this is a breaking change. The main change here is not adding an argument, it's changing a feature that was previously enabled by default. |
Fixes a small regression from crystal-lang#7903
Path#absolute doesn't expand "~/" and may be used for secure path
resolution.
(final behavior)
home
specifies the home directory which~
will expand to.home
.false
(default), home is not expanded.true
, it is expanded to the user's home directory (Path.home
).