Repository navigation
fix(tier1): skip Bandit test and artifact dirs, not substring names - #818
Conversation
The code check passed bare names to Bandit's --exclude (tests, test, evals, results, versions, .git and the other artifact folders). Bandit drops a file when an entry is a substring of its whole path, so a skill called webapp-testing or unit-conversions, a checkout folder such as skills-test, or a skill under .github/skills had no file left to scan and the check passed. The entries are now the paths of the folders and test files that exist below the skill, written as patterns that match only there. Folders named tests or test, test_*.py and *_test.py files and artifact folders are still skipped. A file such as contest.py no longer is. Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
chrisknvidia
left a comment
There was a problem hiding this comment.
Thanks, this is a real gap and the fix is right. I reproduced it on main: a skill named webapp-testing, a file under contests/, and a skill under .github/skills/ all came back with zero Bandit findings for a file that trips B602, and with this branch each one is flagged. Bandit treats every --exclude entry both as a glob and as a plain substring of the full path, so bare names could never work; the per-path entries with glob.escape and the comma-to-? replacement held up in my probes too (commas and brackets in names, a skill root itself named tests, a nested tests/ folder, a symlinked tests/, build/ and dist/ still scanned).
It also brings Bandit in line with the other scanners: Gitleaks has anchored its allowlist to path segments since #92, SkillSpector prunes by exact directory name, and Semgrep's --exclude already matched segments (Semgrep scanned webapp-testing and contests/ on main while Bandit did not). One leftover difference that is not from this PR: Semgrep still scans test_*.py and *_test.py files while Bandit skips them.
One thing to consider, in the inline comment: the per-file entries make the --exclude argument grow with the number of test files, and on Windows that caps out around a few hundred files. The check goes INCOMPLETE then, so it fails closed, but main handled those skills.
Not for this PR, more a note for us: exclude_tests is always on, nothing toggles it, and the docs do not say the code check skips tests/, test/ and test-named files, while the SkillSpector section says it does cover tests/. A doc line would help, and maybe an issue on whether Bandit and Semgrep should skip tests/ at all for untrusted skills.
The new tests pass here with the real Bandit; against main 13 of 14 fail and the exclude_tests=False case is the expected control. The related validator test files pass at this head, the CHANGELOG entry sits under Unreleased, DCO is fine, and there are no conflicts with main.
Each test_*.py and *_test.py file below the skill was its own entry in the --exclude option, so the option grew with the number of test files, and a skill with a few hundred of them did not fit a Windows command line. Bandit then failed to start and the check was incomplete. The option now holds the test and artifact folders only. Test files outside those folders are scanned, and their findings and parse errors are left out when the output is read. A plain folder path is passed as it is, which Bandit skips with everything below it. Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
The Tier 1 reference did not mention that Bandit and Semgrep skip test and artifact folders, or that Bandit skips test files by name. Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
The option still held the path of every test and artifact folder below the skill, so a tree with a few hundred tests folders, such as a vendored library, did not fit a Windows command line. Each excluded name is now two patterns anchored at the skill, one for a folder of that name right below it and one for any depth. The folders that are skipped are the same, including a differently cased artifact folder where the filesystem ignores case. Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
rng1995
left a comment
There was a problem hiding this comment.
I found one portability issue in the new regression coverage.
rng1995
left a comment
There was a problem hiding this comment.
I also reproduced an incomplete scan caused by an excluded test file.
Test files outside the tests folders were read by Bandit and dropped from the report afterwards. One that Bandit cannot finish reading, such as a named pipe, then held the whole scan until it timed out, where the old exclude list had skipped it. They are excluded by name again, as three patterns anchored at the skill, so the option keeps the same size for any tree. Bandit's * also matches a path separator, so test_*.py would hide every Python file below a folder such as test_tools. When a skill has such a folder with other code in it, those patterns are left out and the report is filtered as before. Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
A folder cannot be called a*b?c on Windows, so that case failed at mkdir before it got to Bandit. The other names still run there. Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
|
@chrisknvidia @rng1995 fixed everything from the review, it's all pushed. |
Bandit's "*" also matches a path separator, so the exclude pattern for test_*.py hides every Python file below a folder such as test_tools. When a skill had such a folder with other code in it, the pattern was left out and the test files were read and dropped from the report. A test file that is a named pipe then stopped the scan, and the check ended INCOMPLETE on the timeout. The patterns are now always passed, so no test file is opened. A file they hide that the scan covers goes to Bandit by name in a further run that excludes nothing, in batches that keep each command line short. Bandit adds its own "*" to an entry that is the path of a folder, and with such an entry every file is passed by name instead. The findings of all runs make one report, the runs share the 120 seconds one run had, and a run that fails leaves the scan incomplete with the findings read so far. The check for such an entry now uses os.path.isdir, as Bandit does. Path.is_dir raised for a folder that cannot be searched, which ended the check with a traceback. The report filter for test files is gone, since Bandit no longer reads them. Without the fix, the tests fail. Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
A skill with a folder such as test_tools needs its other files passed to Bandit by name, because the pattern for test files hides them. They went in batches sized for a Windows command line, after a run over the tree, so a package of 2,001 modules took about ten Bandit runs and three times as long as one run. Other systems tell how much room a command line has. A batch now takes a quarter of what the environment leaves there, never less than the Windows size and never more than a million bytes. When every file of the scan fits one batch, that run is all the scan takes and the tree is not walked. The test files are still not opened, and the runs still share the 120 seconds. Without the change, the new tests fail. Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
### Description Package version 1.0.0 of `nvidia-nvflare` for the NVFlare `2.9` branch. I packaged the eight released user-facing skills and their shared resources in a self-contained plugin with manifests for Agent Plugins, Claude Code, Codex, and Cursor. The existing `skills/` directories remain the source of truth. The plugin has no MCP server, hooks, or automatic installer. The released skill instructions, executable behavior, references, and member evaluation cases are preserved. I updated the license declarations in nine `SKILL.md` files and the copyright and SPDX headers in 52 Python files. The license scope is Apache-2.0 for code and CC-BY-4.0 for NVIDIA-authored skill content, as documented in the package. The nine refreshed member cards and their detached signatures match their bundled copies. The plugin includes the signed [plugin card](https://github.com/NVIDIA/NVFlare/blob/d4b48fdba51c0018d51e6e4ee05c034d630d6aa1/plugins/nvidia-nvflare/plugin-card.md), [benchmark](https://github.com/NVIDIA/NVFlare/blob/d4b48fdba51c0018d51e6e4ee05c034d630d6aa1/plugins/nvidia-nvflare/BENCHMARK.md), and `plugin.oms.sig`. The five-case plugin suite exercises framework conversion, checkpoint-based evaluation, federated DICOM statistics, cross-skill routing, and a negative routing case. The separate 107-case regression suite remains available. Evaluation fixtures and permissions are shared across the plugin and baseline arms. ### Testing - I verified the extracted archive against the NVIDIA signing root. The plugin signature covers 188 files. All nine member signatures verified and cover 165 member resources. The public package contains 198 files including the ten signatures. Private evaluation exports are excluded. - I compared the public package with the signed source, including file modes. The packaging check validated the four manifests, documentation links, skill lint, source parity and reproducible archive generation. - All 25 focused packaging tests passed, including rejection of modified signed documents and unsigned exports. The repository style check and skill lint passed. - The five-case evaluation ran on Claude Code and Codex with and without the plugin. Quality passed with partial coverage. The saved aggregate is 77.94/100. Codex scored 80.66/100 with +37.27 points of matched lift. Of 20 planned attempts, 17 completed execution and 12 were fully graded. The saved execution-policy verdict was FAIL. Native plugin loading was outside evaluation scope. ### Risks and release status Static validation has incomplete coverage for archive inspection, encoded content, and connection analysis. Both agents showed lower efficiency on matched tasks. The signed benchmark records these limits. The existing evaluation measures the bundled workflows; the signing refresh did not rerun the agents. I updated the release-branch CI harness to run code integrity with SkillEvaluator 1.2.0, which fixes Bandit's selection of production code and evaluation fixtures. The other seven policy checks retain their existing evaluator, severity thresholds and quality floor. The two reports independently gate each skill. All 53 local Tier 1 tests passed with no skips, including 18 reports for the nine skills. A separate control caught B614 and B615 in production code and a synthetic credential. The signed package is byte-identical to the previously reviewed revision. Both previously failing Ubuntu 24.04/Python 3.13 jobs now pass. [PR check](https://github.com/NVIDIA/NVFlare/actions/runs/45637534964/job/139287063503) · [Push check](https://github.com/NVIDIA/NVFlare/actions/runs/45637502679/job/139286942728). [CI change](ca03a04) · [Upstream scanner fix](NVIDIA/SkillEvaluator#818) The plugin is signed. Product approval and catalog publication follow their respective review processes. The [catalog registration](NVIDIA/skills#953) targets the merged `2.9` package. ### Types of changes - [x] Non-breaking addition to plugin packaging, governance metadata, and evaluation setup. - [x] Tests added for packaging and signature handling. - [x] Plugin-specific documentation updated. - [ ] Full quick-test suite run locally. I ran the focused checks described above. --------- Signed-off-by: Holger Roth <hroth@nvidia.com> Signed-off-by: Mohit Gupta <mohgupta@nvidia.com> Co-authored-by: Mohit Gupta <mohgupta@nvidia.com>
Summary
The Tier 1 code check passed bare names to Bandit's --exclude (tests, test, evals, results, versions, .git and so on), and Bandit drops a file when an entry is a substring of its whole path. So a skill called webapp-testing or unit-conversions, a checkout folder like skills-test, or a skill under .github/skills had no file left to scan and the check passed. Two skills with the same risky script gave exit 1 as webapp-checks and exit 0 as webapp-testing. It's what #92 was for Gitleaks, in another scanner.
The exclude entries are now patterns anchored at the skill, so they only match below it and the list doesn't grow with the tree. Folders named tests or test, test_*.py and *_test.py files and the artifact folders are still skipped and Bandit never opens them, and a file like contest.py gets scanned now. Code that a pattern hides by accident, like test_tools/launch.py, goes to Bandit by name in a second run.
Fixes #817
Verification
make lintmake testmake buildThe new tests run the real Bandit or check the arguments it gets, and without the fix they fail apart from the controls. I also ran tier1 on the two skills from the issue and both exit 1 with B602 and B301 now. On my Mac make test has 26 failures that fail the same way without this change (local environment, secure copy and judge artifact tests). The Tier 1 reference now has a line on what the code check skips.
Release Impact
CHANGELOG.md