Skip to content

Tar: symbolic link targets outside extract dir #74140

Closed as not planned
Closed as not planned

Description

@tmds

.NET doesn't allow to extract symbolic links that have a target outside the extraction folder.

This should not be disallowed.

Instead it should be disallowed to extract in a location that is a link.

An archive like this should extract successfully:

link: SymbolicLink to /tmp

And an archive like this should fail when trying to extract link/file:

link: SymbolicLink to /tmp
link/file: RegularFile

cc @carlossanlop @dotnet/area-system-io

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Aug 18, 2022
  2. removed
    untriagedNew issue has not been triaged by the area owner
    on Aug 18, 2022
  3. added this to the 8.0.0 milestone on Aug 18, 2022
  4. tmds commented on Aug 18, 2022

    @tmds
    MemberAuthor

    @carlossanlop I can implement this if you want.

  5. carlossanlop commented on Aug 18, 2022

    @carlossanlop
    Contributor

    @GrabYourPitchforks is this a scenario we would allow? Extracting a symlink entry that points to an absolute path that is outside of the extract directory, and whose middle segments are not symlinks.

  6. carlossanlop commented on Aug 18, 2022

    @carlossanlop
    Contributor

    Talked to @GrabYourPitchforks offline: This is a scenario we want to explicitly avoid for security reasons. We don't want the archive extraction to unexpectedly add a symlink where it could cause trouble. This also has a workaround: The user has to iterate the archive, then read the Name and explicitly choose the destination for extraction. We don't want the TarFile helper methods to do it.

  7. added
    needs-author-actionAn issue or pull request that requires more info or actions from the author.
    on Aug 18, 2022
  8. tmds commented on Aug 18, 2022

    @tmds
    MemberAuthor

    @GrabYourPitchforks @carlossanlop because tar allows, I think .NET should too. Without this you can't backup and restore a directory which links with absolute paths.

  9. ghost added
    needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
    on Aug 18, 2022
  10. ghost removed
    needs-author-actionAn issue or pull request that requires more info or actions from the author.
    on Aug 18, 2022
  11. jozkee commented on Nov 9, 2022

    @jozkee
    Member

    I agree with @tmds, there may be scenarios where you want to have symlinks pointing outside of the destination. Plus, symlinks are allowed to have anything on their target; they won't be resolved until required.

    @GrabYourPitchforks @blowdart, could you please reconsider?

    cc @bartonjs

  12. blowdart commented on Nov 9, 2022

    @blowdart
    Contributor

    What you're describing is the zipslip vulnerability (except, well, in tar files). The workaround of iterating through the directly structure is there should you want it, but if we enable it by default lots of windows users won't understand the problem (because symlinks in Windows are just odd), and we'd have path escapes everywhere. So, I'm still thinking no on this.

  13. bartonjs commented on Nov 9, 2022

    @bartonjs
    Member

    I agree with @blowdart. If you want the insecure thing you have to write it yourself.

  14. jozkee commented on Nov 9, 2022

    @jozkee
    Member

    In that case, we can close this as won't fix.
    cc @am11

  15. removed
    needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
    on Nov 9, 2022
  16. bartonjs commented on Nov 9, 2022

    @bartonjs
    Member

    In longer form:

    While creating just the symlink doesn't sound like a threat, consider a system that accepts a tar payload of some sort, extracts it into a place, and runs some sort of validation on the contents. A symlink could now point outside the (semi-)sandbox causing the validator to do one of two unsurprising things:

    1. Validate the payload, when it shouldn't have (e.g. by pointing validation_bypass to /var/whatever/current_validation_bypass_key)
    2. Cause the validator to be a source of exfiltration.

    Exfiltration isn't terribly unlikely, after all, the system "knows" that it's reading user data, so it can send back contents without concern.

    • The tarfile says to link manifest to /etc/group
    • The validator reports back to the user something like "Manifest failed to parse as UTF8 JSON. Manifest begins '{0}'", manifest.SubstringIfLongerThan(300)).
    • Cool, now the submitter (probably) knows who all is in the sudo group, and knows what accounts to focus their attacks on.

    If one of "service developers" and "backup/restore software developers" have to be categorically smarter than the other, I'd say it's the backup/restore developers (there are fewer of them, and they're specialized). So if one of them needs to do more work than the other to get the more correct set of behaviors for their need, it should be the backup/restore developers.

  17. tmds commented on Nov 9, 2022

    @tmds
    MemberAuthor

    If this were a known vulnerability, or a major source of security issues, it would not be the default behavior of tar.

  18. bartonjs commented on Nov 9, 2022

    @bartonjs
    Member

    That's not really true. The tar CLI tool is designed for being operated by humans who have the capability to use a giant inference engine to decide something isn't copacetic using dynamic sources of information (applying context like "where did this file come from?"). The TarFile API is designed for being operated by a computer, which only takes into context the things we thought of ahead of time; and we're designing it to assume that the input is untrusted.

    A human might use tar to extract a thing, run ls, see that manifest is colorized differently than other things, and move into an exception flow. The API doesn't get that possibility of running ls to see that the manifest is "wrong" unless we build that in ahead of time.

    A CLI tool and an API don't have the same basic set of assumptions.

    Could we add a knob here? Perhaps. Can it be a default behavior? No, unless we can change File.Open to not read through symlinks (which would be disastrous).

  19. tmds commented on Nov 9, 2022

    @tmds
    MemberAuthor

    ok, I see your point: once the files are extracted, the user may be unaware he's using links because they get de-referenced automatically.

    I agree it makes sense to disallow links to point outside the extract dir by default.

  20. tmds commented on Nov 10, 2022

    @tmds
    MemberAuthor

    Also, I think a knob is desired. I think it's good the default behavior assumes the tar file may be evil, but if you have a trusted tar file, like a backup, you don't want to have to re-write the extraction logic.

  21. jozkee commented on Nov 10, 2022

    @jozkee
    Member

    @tmds would you like to submit the API proposal issue?

  22. ghost locked as resolved and limited conversation to collaborators on Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions