PyCQA / PyCQA/bandit

No detection when passing keyword args to subprocess/shell functions

Open
#156 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
8.3k
Forks
836
Avg merge
5d 3h
Merged PRs (30d)
1

Description

Multiple plugins in bandit/plugins/injection_shell.py assume that a command will be passed in as a positional argument. When keyword arguments are used, the plugins don't even report that a call occurred.

The only issue that Bandit reports against the below Python 2 code is the import of "subprocess":

import commands
commands.getoutput(cmd='ls')

import os
os.popen2(mode='r', cmd='ls')

import subprocess
subprocess.Popen(args='ls', shell=True)

I think a solution for the shell injection plugins is to check for either args[0] or kwargs['cmd']/kwargs['args']/etc., depending on the function.

Note: this quirk only applies to Python-defined functions. Built-in functions, like os.system() on Python 2, won't accept keyword arguments.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in bandit/plugins/injection_shell.py and inspect how the shell-injection plugins read positional arguments. Reproduce the keyword-argument examples from the issue, then update detection so the listed calls are reported; done means equivalent positional and supported keyword forms are detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.