Skip to content

Sample code for: Hardening AI-Generated Python Code With Bandit and Ruff - #933

Open
lpozo wants to merge 5 commits into
masterfrom
bandit-python
Open

lpozo wants to merge 5 commits into
masterfrom
bandit-python

Conversation

@lpozo

@lpozo lpozo commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Where to put new files:

  • New files should go into a top-level subfolder, named after the article slug. For example: my-awesome-article

How to merge your changes:

  1. Make sure the CI code style tests all pass (+ run the automatic code formatter if necessary).
  2. Find an RP Team member on Slack and ask them to review & approve your PR.
  3. Once the PR has one positive ("approved") review, GitHub lets you merge the PR.
  4. 🎉

Code examples for the Hardening AI-Generated Python Code With Bandit and Ruff tutorial. Files live in the bandit-python/ top-level folder, named after the article slug.

Notes for reviewers:

  • insecure/helpers.py is deliberately insecure teaching code. The folder's pyproject.toml has an extend-exclude = ["insecure"] line so the repo's Ruff lint passes.
  • .github/workflows/security.yml is a sample for readers' own repositories. It doesn't run from this repo.

🤖 Generated with Claude Code

lpozo and others added 5 commits November 2, 2026 13:07
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Pass "--" before host in ping_host() so caller input that starts
  with "-" can't become a ping option. This matches the article's
  rule for when a "# nosec B603 B607" suppression is acceptable.
- Use OWASP's scrypt cost (n=2**17, r=8, p=1) in hash_password(),
  with maxmem=2**28 because it needs 128 MiB and OpenSSL's default
  limit is 32 MiB.

Line numbers and scanner output shown in the article are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests run leaves out -c because pyproject.toml excludes tests, so
it must repeat the project's B404 skip on the command line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The helpers are otherwise unannotated, and the sqlite3 import only
served the hint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant