Confused by nosec: encountered B104, but no failed test
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 67/100
Direzione di ricerca
Start by reproducing the warning with the supplied function-call example, then compare how Bandit handles nosec markers in that case and in the two examples that work. Trace the nosec handling and its tests; done means warnings refer only to lines containing markers and suppressions apply to the intended line without false negatives.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
% bandit -q -c pyproject.toml -r .
[tester] WARNING nosec encountered (B104), but no failed test on file ./tests/tpsrv/test_cli.py:405
[tester] WARNING nosec encountered (B104), but no failed test on file ./tests/tpsrv/test_cli.py:407
% sed -ne '404,413p' ./tests/tpsrv/test_cli.py
@pytest.mark.parametrize(
"args, host, port",
[
(["--host", "0.0.0.0"], "0.0.0.0", 8000), # nosec: B104
(["-h", "::1"], "::1", 8000),
(["--port", "9999"], "127.0.0.1", 9999),
(["-p", "1024"], "127.0.0.1", 1024),
(["-p", "65535"], "127.0.0.1", 65535),
(["-h", "localhost", "-p", "8080"], "localhost", 8080),
],
There is no nosec on line 405, but reported as found.
And if I remove the nosec on line 407, then B104 is reported on that line:
% sed -e 's,# nosec:.*,,' ./tests/tpsrv/test_cli.py | bandit -c pyproject.toml - 2>&1 | grep -A8 B104
>> Issue: [B104:hardcoded_bind_all_interfaces] Possible binding to all interfaces.
Severity: Medium Confidence: Medium
CWE: CWE-605 (https://cwe.mitre.org/data/definitions/605.html)
More Info: https://bandit.readthedocs.io/en/1.9.4/plugins/b104_hardcoded_bind_all_interfaces.html
Location: <stdin>:407:20
406 [
407 (["--host", "0.0.0.0"], "0.0.0.0", 8000),
408 (["-h", "::1"], "::1", 8000),
--
>> Issue: [B104:hardcoded_bind_all_interfaces] Possible binding to all interfaces.
Severity: Medium Confidence: Medium
CWE: CWE-605 (https://cwe.mitre.org/data/definitions/605.html)
More Info: https://bandit.readthedocs.io/en/1.9.4/plugins/b104_hardcoded_bind_all_interfaces.html
Location: <stdin>:407:32
406 [
407 (["--host", "0.0.0.0"], "0.0.0.0", 8000),
408 (["-h", "::1"], "::1", 8000),
Reproduction steps
Interestingly,
% echo -e "IP = '0.0.0.0' # nosec B104\nprint(IP)" | bandit -
does not have this problem, and neither does
% echo -e "IP = [\n '0.0.0.0' # nosec: B104,\n '127.0.0.1'\n]\nprint(IP)" | bandit -
It seems to do with being inside a function call:
% echo -e "print(\n [\n (['--host', '0.0.0.0'], '0.0.0.0'), # nosec: B104\n ]\n)\n" | bandit -
[…]
[tester] WARNING nosec encountered (B104), but no failed test on file <stdin>:3
[…]
Expected behavior
- No false negatives about use of
# nosecmarkers - No warnings/errors about
nosecon lines that do not havenosec - No more errors about
nosecthan actualnosecuse - The ability to silence the warning just for the very line that it's expected to warn about.
Bandit version
1.9.1 (Default)
Python version
3.14 (Default)
Additional context
Bandit 1.9.4, which I cannot select in the above.
- Lingua principale
- Python
- Stelle
- 8.4k
- Fork
- 893
- Merge medio
- 6h 52m
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di PyCQA/bandit
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Turn off progress bar in CIForse già presa @silvatechf l’ha presa 28 giorni fa. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
-
`bandit -ii -ll -ii -ll` raises an `IndexError`Forse già presa @botbikamordehai2-sketch l’ha presa 181 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Tutte le issue di PyCQA/bandit
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Library sweep logs an ERROR at start for the valkey instrumentor when valkey-py is not installedAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
JoahanMorales/upiixia-agentic-kit#99 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
NatLabRockies/openstudio-mcp#286 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100