Skip to content

Bandit fails when using importlib with named arguments #694

@mkielar

Description

@mkielar

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Save this code in a test.py file
    import importlib
    importlib.import_module(name=foo, package='bar.baz')
    
  2. Run:
    > bandit test.py
    [main]  INFO    profile include tests: None
    [main]  INFO    profile exclude tests: None
    [main]  INFO    cli include tests: None
    [main]  INFO    cli exclude tests: None
    [main]  INFO    running on Python 3.8.3
    [node_visitor]  INFO    Unable to find qualified name for module: test.py
    [tester]        ERROR   Bandit internal error running: blacklist on file test.py at line 4: list index out of rangeTraceback (most recent call last):
      File "[MASKED]/venv/lib64/python3.8/site-packages/bandit/core/tester.py", line 52, in run_tests
        result = test(context, test._config)
      File "[MASKED]/venv/lib64/python3.8/site- packages/bandit/core/blacklisting.py", line 50, in blacklist
        name = context.call_args[0]
    IndexError: list index out of range
    
  3. Observe the error

Expected behavior
I'd expect it to scan the file with no errors.

Bandit version

bandit 1.7.0
  python version = 3.8.3 (default, Feb 26 2020, 00:00:00) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]

Additional context
This line: https://github.com/PyCQA/bandit/blob/master/bandit/core/blacklisting.py#L50 only expects module name passed directly, and not as named argument.

Metadata

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