Skip to content

Fix symlinks - #42

Closed
vmchale wants to merge 5 commits into
haskell:masterfrom
vmchale:fix-symlinks
Closed

vmchale wants to merge 5 commits into
haskell:masterfrom
vmchale:fix-symlinks

Conversation

@vmchale

@vmchale vmchale commented Feb 16, 2019

Copy link
Copy Markdown

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
Copy Markdown
Member

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

@emilypi emilypi left a comment •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

@hasufell hasufell Apr 7, 2021 •

Copy link
Copy Markdown
Member

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.


| otherwise = Nothing

linkDepth :: FilePath -- ^ Name of link

Copy link
Copy Markdown
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

@hasufell hasufell Apr 8, 2021 •

Copy link
Copy Markdown
Member

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

Bodigrim commented Apr 9, 2021

Copy link
Copy Markdown
Contributor

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

@Bodigrim

Bodigrim commented Dec 7, 2023

Copy link
Copy Markdown
Contributor

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