PyCQA / PyCQA/bandit

blacklist getattr calls

Open
#649 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Is your feature request related to a problem? Please describe.
One of use cases for bandit is a backdoor detection. It doesn't fit it well though, since for proper backdoor detection intermodule and runtime interactions must be addressed, i.e. with taint analysis (and the fact that using bandit for backdoor detection can be easily bypassed must be clearly stated in bold big red font).

It can detect very crude backdoors with explicit eval. But it is easy to mask them, by just obfuscating the string eval and getting the function using getattr.

Also getattr is a bad smell by itself, since it is often dangerously misused. I.e.

class A:
    b = lambda b: b

function_id = "string from the net"
getattr(A, function_id)(*args_from_the_net)

Instead a collection should be used and A[function_id], which will only allow calling an explicitly defined set of functions.

Describe the solution you'd like

getattr should be blacklisted.

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 by locating Bandit's existing blacklist checks and their tests, then review how a getattr call is represented in the issue's Python examples. Done should include a blacklist finding for getattr while accounting for the stated security-scanning scope and documenting the behavior in tests.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.