checks: Mark justified partial-path subprocess calls as nosec B607 - #7713
Conversation
|
The way you added the exclude here means that we will not be able to catch if a new valid violation of this rule is introduced, effectively removing the tool. It would be better for justified exclusions to write them inline in the code that uses it, so that even if a new violation in the same file appears, it should be caught. |
Address review feedback: instead of skipping Bandit B607 globally (which would also stop catching newly introduced violations), suppress it inline at each existing call site. These are developer, build, and test helpers that invoke known tools (git, gh, svn, msgfmt, mdl, man, grass) by name, intentionally resolved through PATH, the same rationale as the already-skipped B603. The g.region call in pygrass grid is addressed separately in the shell=True cleanup (OSGeo#7703).
c3d24e4 to
8bc5ad8
Compare
|
I've reworked this to drop the global The suppressed calls are developer, build, and test helpers that run known tools ( One site, the |
Name the specific tool in each suppression and state why the partial path is permanent: these are fixed external tools (git, gh, svn, svnversion, msgfmt, mdl, grass) with no portable absolute path, and g.manual launches the user's own system man. PATH resolution is required by design, so the exclusion cannot become stale.
|
@echoix see below. Is the justification permanent? Yes. Every suppressed call runs a fixed, hardcoded tool name ( By context these are also not runtime-with-untrusted-input paths:
Wording, agreed it was too generic. I've updated each comment to name the specific tool and state the durable reason, e.g. If you'd still prefer an active resolution over a suppression for the non-shipped tooling, I can switch those to |
Skips 15 Bandit B607 (
start_process_with_partial_path, note severity) code scanning alerts by addingB607to the[tool.bandit] skipslist inpyproject.toml.All flagged sites invoke tools by bare name (
git,gh,mdl,msgfmt) from developer and build-time helpers, not from runtime code handling untrusted input:utils/mkdocs.py,utils/generate_release_notes.py,utils/generate_last_commit_file.py,utils/md_isvalid.py(doc build and release tooling)locale/grass_po_stats.py(translation stats)scripts/g.manual,python/grass/gunittest/reporters.py,python/grass/pygrass/modules/gridGRASS resolves executables through
PATHby design (using an absolute path would actually break portability across install layouts). B607 is the natural companion of B603 (subprocess_popen_with_shell_equals_false/ untrusted input), which the project already skips (#3839); this follows the same rationale and the project's established preference for category skips over per-line# nosec.Verified with bandit 1.9.4: the flagged directories report the B607 findings before the change and none after.
This is part of a larger effort to work through the open code scanning alerts, grouped into small PRs by issue type.
Written with the assistance of Claude Code.