Skip to content

Improve zipfile: add support for symlinks #82102

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

Open
zaphodef mannequin opened this issue Aug 22, 2019 · 5 comments
Open

Improve zipfile: add support for symlinks #82102

zaphodef mannequin opened this issue Aug 22, 2019 · 5 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@zaphodef
Copy link
Mannequin

zaphodef mannequin commented Aug 22, 2019

BPO 37921
Nosy @serhiy-storchaka, @zaphodef
PRs
  • bpo-37921: Better handle symlinks in the zipfile module #15401
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2019-08-22.21:14:36.379>
    labels = ['type-feature', 'library', '3.9']
    title = 'Improve zipfile: add support for symlinks'
    updated_at = <Date 2021-09-25.17:47:38.187>
    user = 'https://github.com/zaphodef'

    bugs.python.org fields:

    activity = <Date 2021-09-25.17:47:38.187>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2019-08-22.21:14:36.379>
    creator = 'zaphodef'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37921
    keywords = ['patch']
    message_count = 4.0
    messages = ['350231', '352932', '362217', '402638']
    nosy_count = 3.0
    nosy_names = ['serhiy.storchaka', 'Henning.von.Bargen', 'zaphodef']
    pr_nums = ['15401']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue37921'
    versions = ['Python 3.9']

    @zaphodef
    Copy link
    Mannequin Author

    zaphodef mannequin commented Aug 22, 2019

    The module tarfile contains some methods for knowing whether an archive member is a regular file/a directory/a symlink. Apart from an "is_dir()" method, there was nothing alike in the zipfile module. For an on-going project, I needed to know whether an archive member was a symlink or not, to prevent zip symlinks attacks.

    I thought this could be of used for other people, given I struggled a little to find a way of saying if an archive member is a symlink or not.

    This is why I think adding support for symlinks in the zipfile module could be a good idea.

    @zaphodef zaphodef mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 22, 2019
    @zaphodef
    Copy link
    Mannequin Author

    zaphodef mannequin commented Sep 21, 2019

    The PR went through review and has been awaiting core review for almost a month, anyone to have a look at it? :)

    @HenningvonBargen
    Copy link
    Mannequin

    HenningvonBargen mannequin commented Feb 18, 2020

    If I understand correctly,
    this bug is about supporting symlinks on *creating* ZIP files.

    Please see also https://bugs.python.org/issue27318 for a proposal to support symlinks while *unpacking* ZIP files.

    Maybe a preserve_symlinks optional argument should be added to the extract and extractall method as well (the same argument name is used in distutils.dir_util.copy_tree).

    Anyway, I think symlink support should be added for packing *and* unpacking or not at all.

    @serhiy-storchaka
    Copy link
    Member

    Adding support of symlinks in ZIP files will make the zipfile module vulnerable to symlink attacks like like with TAR files (see https://en.wikipedia.org/wiki/Tar_(computing)#Duplicates). Until we find a solution to this, adding support of symlinks is dangerous.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @gpshead gpshead removed the 3.9 only security fixes label Sep 25, 2022
    @gpshead
    Copy link
    Member

    gpshead commented Sep 25, 2022

    If symlink support is ever added to zipfile, it needs to be off by default for both zipfile creation and zipfile extraction.

    Getting extraction correct without security problems in the presence of symbolic links is extremely difficult. Even if you think you've done it...

    For example, see #88189 (comment)

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    Status: No status
    Development

    No branches or pull requests

    2 participants