Skip to content

Incorrect result for B202:tarfile_unsafe_members #1038

Open
@behnazh-w

Description

Describe the bug

The B202:tarfile_unsafe_members documentation says to pass a callable as the members argument but that’s not supported in the official type signature and not implemented in CPython stdlib. members should be used as an Iterable[TarInfo] instead.

That change was introduced in v1.7.5 based on issue #207 and PR #549
cc @yilmi @ericwb @lukehinds @sigmavirus24

The following fixes are required to address this bug:

  1. The tarfile.extractalll(members=function(tarfile)) - LOW suggestion here seems to be wrong.
  2. The check on ast.Call node here should be fixed/removed.
  3. The extractall function name look up here is too coarse and can easily result in inaccurate results for other libraries that have the same function names, e.g., ZipFile.extractall.

Reproduction steps

This PR addresses the B202:tarfile_unsafe_members by validating members Iterable argument but Bandit cannot detect the filtering of members used to fix the issue (hence the need to suppress the error)

Expected behavior

The check on ast.Call node here should be fixed/removed. We should not assume the members argument to have a Callable type.

Bandit version

1.7.5 (Default)

Python version

3.11 (Default)

Additional context

No response

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions