False positive when yaml.load is used with "Loader=yaml.SafeLoader"

Bug #1508490 reported by Cyril Roelandt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bandit
Fix Released
Medium
Matt Valdes

Bug Description

Consider this piece of code:

yaml.load("dt: !!python/object/apply:time.gmtime []")

Bandit will report an issue (use of unsafe yaml load). A possible fix is:

yaml.safe_load("dt: !!python/object/apply:time.gmtime []")

Bandit will not complain when reading the above line. But it will emit a warning for the following line:

dt = yaml.load("dt: !!python/object/apply:time.gmtime []", Loader=yaml.SafeLoader)

Even though it is exactly as safe as using "yaml.safe_load".

Bandit should not emit a warning when "yaml.load" is used with "Loader=yaml.SafeLoader", though it might be ok in complex cases such as "yaml.load(..., Loader=<variable>)".

Revision history for this message
Travis McPeak (travis-mcpeak) wrote :

Good point

Changed in bandit:
status: New → Confirmed
Revision history for this message
Tim Kelsey (tim-kelsey) wrote :

good catch Cyril

Changed in bandit:
assignee: nobody → Tim Kelsey (tim-kelsey)
importance: Undecided → Medium
Ian Cordasco (icordasc)
Changed in bandit:
assignee: Tim Kelsey (tim-kelsey) → Matt Valdes (matthew-valdes)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to bandit (master)

Fix proposed to branch: master
Review: https://review.openstack.org/267747

Changed in bandit:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to bandit (master)

Reviewed: https://review.openstack.org/267747
Committed: https://git.openstack.org/cgit/openstack/bandit/commit/?id=b09c0e38c685785fc48f9d7c6146edf1447683df
Submitter: Jenkins
Branch: master

commit b09c0e38c685785fc48f9d7c6146edf1447683df
Author: mattvaldes <email address hidden>
Date: Thu Jan 14 12:02:59 2016 -0600

    Split yaml blacklist check into its own file

    Allow SafeLoader to be passed to the Loader parameter
    Closes-bug: 1508490

    Change-Id: I7459577e175b5f2a623316e22c63b2d42ba1db25

Changed in bandit:
status: In Progress → 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.