Check imports created from importlib

Bug #1718516 reported by Rajath Agasthya
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bandit
Fix Released
Medium
Rajath Agasthya

Bug Description

Bandit only checks for imports if 'import' keyword or '__import__()' function is used. It should also check for imports using 'importlib.import_module()' and 'importlib.__import__()' functions.

Example:

$ cat import.py

import importlib
s = importlib.import_module('subprocess')
t = importlib.__import__('subprocess')

$ bandit import.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 2.7.13
[node_visitor] INFO Unable to find qualified name for module: import.py
Run started:2017-09-20 18:31:32.185419

Test results:
 No issues identified.

Code scanned:
 Total lines of code: 3
 Total lines skipped (#nosec): 0

Run metrics:
 Total issues (by severity):
  Undefined: 0
  Low: 0
  Medium: 0
  High: 0
 Total issues (by confidence):
  Undefined: 0
  Low: 0
  Medium: 0
  High: 0
Files skipped (0):

I'm happy to help fix this if this is confirmed.

summary: - Check imports created from importlib.import_module()
+ Check imports created from importlib
Luke Hinds (lhinds)
Changed in bandit:
status: New → Confirmed
importance: Undecided → High
importance: High → Medium
assignee: nobody → Rajath Agasthya (rajagast)
Revision history for this message
Colin Best (cbest47) wrote :

Official Python documentation suggests the use of importlib.import_module(), and not importlib._import_() for programmatic imports. The bug fix will only additionally support the importlib.import_module() function.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to bandit (master)

Reviewed: https://review.openstack.org/530335
Committed: https://git.openstack.org/cgit/openstack/bandit/commit/?id=bb1bf81856c1467f85ee138b727568d192bd179a
Submitter: Zuul
Branch: master

commit bb1bf81856c1467f85ee138b727568d192bd179a
Author: Tin Lam <email address hidden>
Date: Thu Dec 28 04:09:01 2017 -0600

    Add module loaded through importlib

    Bandit only checks if imports is done using keyword ``import`` or
    ``__import__()`` and does not check for blacklisted module loaded
    via importlib. This patch set adds additional check for blacklisted
    modules loaded via importlib.

    Change-Id: I97ed93af1066fa39dfc5be0868ab814c8eadd147
    Closes-Bug: #1718516
    Signed-off-by: Tin Lam <email address hidden>

Changed in bandit:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.