@codacy/tools-bandit-1

中文文档
0.28.0发布于 2026/11/09MITTypeScriptCommonJS近 30 天下载 1.2万

Bandit adapter — CLI-mode Python security linter

原始使用文档
文档目录6 节
  1. Table of Contents
  2. Overview
  3. Updating patterns
  4. Updating the Bandit version
  5. Development
  6. Notes for maintainers

@codacy/tools-bandit-1

Table of Contents


Overview

Python security linter using the Bandit binary. Uses the CLI execution strategy -- spawns bandit from a managed Python venv via spawnTool() and parses its JSON output.

PropertyValue
Tool IDBandit
Codacy UUID89b6fc6a-9137-4cf3-8b9f-dcc3bedfa738
StrategyCLI
LanguagesPython
Binarybandit (pip-installed in venv)
File patterns**/*.py

Updating patterns

# Re-fetch pattern metadata from the Codacy API
pnpm prefetch

# Commit the result
git add src/patterns.json

Pattern IDs follow the format Bandit_B602, Bandit_B301, etc.

Updating the Bandit version

  1. Update preferredVersion in src/adapter.ts
  2. Update the PIP_PACKAGES array with the new pinned version
  3. Run pnpm prefetch to check for new/removed rules
  4. Run pnpm test to verify compatibility
  5. If the major version changes, create a new adapter package (bandit-2/)

Development

pnpm build    # Build with tsup
pnpm test     # Run tests (requires bandit in PATH or venv)

To install bandit locally for testing:

pip install bandit==1.8.3

Notes for maintainers

  • Preset mappings (src/pattern-mappings.json): 18 of the 78 checks are gated on a detected PyPI dependency, because they only ever fire against one library's API. Ten were default-on and now stay out of a repo that does not declare the library — B201 (Flask), B701 (Jinja2), B702 (Mako), B601 (Paramiko), B320/B410 (lxml), B506 (PyYAML), B113/B501 (requests) and B308 (Django). Eight were default-off and are now reachable at all: B610/B611/B703 (Django SQLi/XSS), B507 (Paramiko host keys), B508/B509 (PySNMP), B413/B414 (PyCrypto vs. PyCryptodome — separate projects, so separate entities). Left universal on purpose: the stdlib checks (B301–B307, B324) and B412, whose httpoxy CGI handler has no manifest to read.

    Two of these need a second key, because gating gets its evidence from direct declarations only:

    • B701 is claimed by flask as well as jinja2. Flask hard-depends on Jinja2 (Flask → jinja2>=3.1.2), so a real Flask app usually never lists Jinja2 itself, and gating on jinja2 alone dropped a High-severity autoescape check from most Flask repos.
    • B501 is claimed by httpx as well as requests. Bandit's own crypto_request_no_cert_validation plugin inspects both libraries, so an httpx-only repo would otherwise lose the verify=False check.

    Three of these gates are inert, and deliberately kept anyway: B320, B410 (lxml) and B414 (pycryptodome) are still in Codacy's pattern catalog but Bandit 1.8.3 no longer registers the checks, so they can never fire (blacklists/calls.py: "skipped B320 as the check for a call to lxml.etree has been removed"; blacklists/imports.py: the same for B410; B414 is simply absent from gen_blacklist()). mapping-drift.test.ts cannot see this — it compares against Codacy's catalog, not the installed tool. Dropping the mappings would make three default-on High/Security patterns universal again and write them into every Python repo's config, so the gate is the lesser evil until the catalog catches up. See docs/tech-debt.md.

  • Bandit requires Python 3 as a runtime. The adapter uses an isolated venv at ~/.codacy/runtimes/bandit-1/venv/.

  • Exit code 0 = no findings, 1 = findings found (normal), >1 = error.

  • col_offset in bandit output is 0-based; the adapter adds 1 for the 1-based Issue model.

  • Bandit's issue_confidence (LOW/MEDIUM/HIGH) maps to numeric confidence (1/2/3) on the Issue.

  • CWE information from issue_cwe is appended to the issue message as (CWE-{id}).

  • Config file detection supports .bandit (INI, passed with --ini), bandit.yml (YAML, passed with -c), and pyproject.toml (TOML, passed with -c).

  • Pattern filtering uses the -t flag to pass comma-separated test IDs to bandit.

  • The errors array in bandit's JSON output (file-level errors like syntax errors) is mapped to AnalysisError objects with level "warning".

版本与发布记录

@codacy/tools-bandit-1 共发布 36 个版本,首次发布于 2026/03/24;过去 12 个月发布了 36 个版本。

版本发布日期距今
0.28.0latest2026/11/09今天
0.27.12026/11/054 天前
0.27.02026/11/036 天前
0.26.02026/10/3010 天前
0.25.02026/10/1921 天前
0.24.02026/09/251 个月前

关于 @codacy/tools-bandit-1 的常见问题

@codacy/tools-bandit-1 是什么?

Bandit adapter — CLI-mode Python security linter

如何安装 @codacy/tools-bandit-1?

在项目目录运行 npm install @codacy/tools-bandit-1,或使用 pnpm add / yarn add / bun add。

@codacy/tools-bandit-1 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codacy/tools-bandit-1 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@codacy/tools-bandit-1 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@codacy/tools-bandit-1 可以商用吗?

@codacy/tools-bandit-1 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codacy/tools-bandit-1 的下载量有多少?

根据 npm 官方下载统计,@codacy/tools-bandit-1 在 2026/10/10 – 2026/11/08 这 30 天内被下载 11,879 次,日均约 396 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codacy/tools-bandit-1 还在维护吗?

最新版本 0.28.0 发布于 2026/11/09(今天);至今共发布 36 个版本,其中过去 12 个月发布了 36 个;首次发布于 2026/03/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。