-
Notifications
You must be signed in to change notification settings - Fork 37
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
Rework checkEntrySecurity #82
Conversation
213a39d
to
2f4b331
Compare
I'm challenging whether symlinks pointing outside the archive is a security issue.
tar/Codec/Archive/Tar/Unpack.hs Lines 183 to 196 in ffc123f
The only danger I can see is buggy implementations doing recursive deletion and following symlinks during that operation. In that case, you have much bigger problems on your hands. |
2f4b331
to
e52c6ec
Compare
Codec/Archive/Tar/Check/Internal.hs
Outdated
SymbolicLink link -> check (FilePath.Native.takeDirectory (entryPath entry) | ||
FilePath.Native.</> fromLinkTarget link) |
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.
Why Native
? tar
expects unix style separators ("slash" in the spec text) for its entries and so we should also expect these semantics for symlink target.
Now I also realize we're quite sloppy about this fact in unpack
and pack
. I think a symlink created on windows might not survive unpack on unix.
I'll probably have to test that.
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.
Yes, I tested it. Symlinks are broken when packed on windows and trying to unpack on unix. We have to splitPath and joinPath them.
Codec/Archive/Tar/Check/Internal.hs
Outdated
OtherEntryType 'K' longPath _ | ||
-- We don't know yet whether it's a hard or a soft link. | ||
-- Let's err on the safe side and validate as a hard one. | ||
-> check (Char8.unpack $ Char8.takeWhile (/= '\0') longPath) |
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.
Why are we not considering the basepath ((entryPath entry)
) here? Will that not yield false-positives?
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.
See cases for hard and soft links above. AFAIU from the difference between handleHardLinks
and handleSymLinks
in Unpack.hs
, hard links are "absolute" in the context of an archive (thus check longPath
) and relative to the current position in the archive (thus check $ takeDirectory tarPath </> longPath
). Here we don't know whether it's a hard or a soft link, so assuming the worst.
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.
What I mean is that symlink targets like ./../../bar
will throw here afaiu, because it's assumed to be the tar root.
However, it may be a safe symlink.
I've written a patch where we don't use checkEntrySecurity
but only operate on Entries e
and can look as far ahead as we want, similar to unpack
. It's a bit involved, so I haven't finished yet.
Looking at other We can probably benefit from implementing a transformation Entries e -> [(FilePath /* path */, Maybe (FilePath /* link */, Bool /* is hard link? */))] and expressing all the checks in terms of |
I agree that such check does not make much sense for a general purpose archiver. But given that the main clients of Potentially we can refactor the module, providing more flexible and fine-grained checks. |
Can we not expose a stricter I've used That said, it isn't a regression, so a follow-up PR could introduce different "strictness" properties for unpack? |
We can add |
I think the callback stuff introduced a slight performance regression for |
c117d6f
to
acfdfe0
Compare
acfdfe0
to
efc9224
Compare
I factored out the support of long file names into a separate module. Hopefully I did not break anything else %) |
Key points:
..
in a path should be allowed as long as it does not point outside of the archive,This is meant to close #27, enabling us to unpack https://nodejs.org/dist/v8.9.3/node-v8.9.3-linux-x64.tar.xz.