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 symlinks #42

Closed
wants to merge 5 commits into from
Closed

Fix symlinks #42

wants to merge 5 commits into from

Conversation

vmchale
Copy link

@vmchale vmchale commented Feb 16, 2019

This fixes #32

We no longer fail when a symlink points to ../../Makefile.gen (for instance), provided that it does not go outside of the unpacking directory.

(This is dependent on #41)

@hasufell
Copy link
Member

Is this project still maintained? Most PRs seem unattended, except for simple bound bumping.

Copy link
Member

@emilypi emilypi left a comment

Choose a reason for hiding this comment

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

<approval dismissed - see Bodigrim's comment>

check name
| FilePath.Native.isAbsolute name
| checkCommon name
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously when not (FilePath.Native.isValid name) we returned InvalidFileName, but now it is AbsoluteFileName. Why?

@@ -65,24 +65,46 @@ checkSecurity = checkEntries checkEntrySecurity
checkEntrySecurity :: Entry -> Maybe FileNameError
Copy link
Contributor

Choose a reason for hiding this comment

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

If filepaths now allow .., a comment for checkSecurity needs to be updated.


where getDepth [] = 0
getDepth ("..":fps) = 1 + getDepth fps
getDepth (_:fps) = getDepth fps - 1
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel uneasy merging such changes without any regression tests. Could we please add some?

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if one of the elements is "."? It should not affect the depth, right? Imagine a symbolic link of form ./.././.. or similar.

@hasufell is my understanding correct here?

Copy link
Member

@hasufell hasufell Apr 7, 2021

Choose a reason for hiding this comment

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

Yeah, I think we need to normalise first. I followed the codepath and I don't see that normalisation happens anywhere else. The link target is potentially read directly from the tar archive data and can contain anything.

= Just $ InvalidFileName name

| otherwise = Nothing

linkDepth :: FilePath -- ^ Name of link
Copy link
Member

Choose a reason for hiding this comment

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

It's somewhat confusing what the arguments exactly are.

First argument is:

  • the path of the symlink file relative to the tar root

Second argument is:

  • the link target, which must always be a relative path

in getDepth allPaths

where getDepth [] = 0
getDepth ("..":fps) = 1 + getDepth fps
Copy link
Member

@hasufell hasufell Apr 8, 2021

Choose a reason for hiding this comment

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

There's a bug here I believe. link itself (which is the filepath of the symlink) can already contain ... Although this is uncommon and most tools avoid doing this, our implementation does not. Note that the existence of a .. doesn't necessarily mean it's a tarbomb.

Try something like:

htar -c 'doc/../..' > /tmp/foo.tar

Afais getDepth will report a problem here and cause failure, although the symlink target itself might not be to blame. This is likely a tarbomb, but for that we have https://hackage.haskell.org/package/tar-0.5.1.1/docs/Codec-Archive-Tar-Check.html#v:checkTarbomb

@Bodigrim
Copy link
Contributor

Bodigrim commented Apr 9, 2021

@vmchale would you be interested to proceed with this PR? It's understandable, if you lost interest after two years.

@Bodigrim
Copy link
Contributor

Bodigrim commented Dec 7, 2023

Superseded by #82.

@Bodigrim Bodigrim closed this Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbolic link to .. should be valid in a nested directory
4 participants