Skip to content

Codacy: stop Bandit B105 flagging the cls_token keys - #1546

Closed
bruAristimunha wants to merge 3 commits into
braindecode:masterfrom
bruAristimunha:codacy-bandit-b105
Closed

bruAristimunha wants to merge 3 commits into
braindecode:masterfrom
bruAristimunha:codacy-bandit-b105

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Codacy's Bandit flags every "cls_token": None key in the foundation-model return_features dicts as B105 hardcoded_password_string, because the key contains "token". These are model tokens, not secrets. Each one has needed a # nosec B105 (11 in braindecode/ today), and new models keep tripping it (Codacy's "1 new issue" on #1540).

This adds a root bandit.yml, one of the config files Codacy reads for Bandit, that skips B105.

When Codacy uses a Bandit config file, Bandit runs all its default checks, not only the patterns enabled in Codacy's UI. So the file also skips B101 (assert_used), which Codacy does not report today. Without it, the switch would surface about 3,700 pytest asserts.

bandit -r braindecode test, measured in a Voyager job:

findings B101 B105 others
no config 3,748 3,716 15 17
bandit.yml 17 0 0 17 (unchanged: B301/B403 pickle and B603/B404 subprocess in tests, B310, B311, B615)

After merging: on Codacy → braindecode → Code patterns → Bandit, turn on "Use configuration file". Codacy ignores the file until that toggle is set. The existing # nosec B105 comments can be removed in a follow-up once the toggle is confirmed.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review identifies no active issues with the Bandit configuration update.

No open issues 🎉

What changed in this PR

Updates the repository’s Bandit configuration to suppress B105 false positives on foundation-model cls_token keys when Codacy’s configuration-file option is enabled.

Changes:

  • Adds B105 to the skipped checks while preserving the existing B101 exclusion.
  • Documents why both checks are skipped and when Codacy reads the configuration.
File Description
bandit.yml Skips B105 alongside B101 and explains the exclusions.

Review effort: Balanced

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.38%. Comparing base (0d9cd36) to head (a5458a7).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1546   +/-   ##
=======================================
  Coverage   91.37%   91.38%           
=======================================
  Files         170      170           
  Lines       22123    22137   +14     
=======================================
+ Hits        20214    20229   +15     
+ Misses       1909     1908    -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 15:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the Bandit configuration changes and accompanying changelog update.

No open issues 🎉

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the Bandit configuration and changelog updates.

No open issues 🎉

Review effort: Balanced

@bruAristimunha

Copy link
Copy Markdown
Collaborator Author

Landed on master as 7e42230. The merge API call returned a 502 mid-merge and left this PR open, but the squash commit is on master with exactly this PR's changes (bandit.yml + whats_new). Closing to match.

bruAristimunha added a commit to bruAristimunha/braindecode that referenced this pull request Nov 5, 2026
* Codacy: Bandit config that skips B105 (cls_token keys) and B101 (test asserts)

* whats_new: Bandit config for Codacy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants