@@ -204,6 +204,13 @@ and the risk of command injection is significantly reduced.
204
204
# Removing shell=True and using a list
205
205
subprocess.run([" echo" , user_input]) # User input is not executed as a shell command
206
206
207
+ .. note ::
208
+
209
+ Bandit warning remains even after deactivating the `shell=True ` argument.
210
+ If you are sure that the command is safe, you can ignore the Bandit warning. Please
211
+ check the `Ignore Bandit warnings `_ section for more information on how to do so.
212
+
213
+
207
214
208
215
**try except continue statements **
209
216
@@ -285,3 +292,43 @@ provides a secure way to generate random numbers.
285
292
286
293
secure_random_number = secrets.randbelow(100 ) # Secure random number generation
287
294
secure_random_letter = secrets.choice([" a" , " b" , " c" ]) # Secure choice from a list
295
+
296
+
297
+ Ignore Bandit warnings
298
+ ----------------------
299
+
300
+ In-line comment
301
+ ~~~~~~~~~~~~~~~
302
+
303
+ When using Bandit, you may encounter warnings that you believe are not relevant to your codebase
304
+ or that you have already addressed. In such cases, you can ignore specific Bandit warnings by
305
+ adding a comment to the end of the line that triggers the warning. The comment should be in the
306
+ format ``# nosec <warning_id> ``, where ``<warning_id> `` is the ID of the warning you want to ignore.
307
+
308
+ When you ignore a Bandit warning, it is essential to provide a clear comment explaining why
309
+ the warning is being ignored. This helps maintainers and other developers understand the context
310
+ and rationale behind the decision.
311
+
312
+ For example, to ignore the B404 warning, you would add `# nosec B404 ` to the end of the line:
313
+
314
+ .. code :: python
315
+
316
+ # Subprocess is needed to start the backend. But
317
+ # the input is controlled by the library. Excluding bandit check.
318
+ import subprocess # nosec B404
319
+
320
+
321
+ .. warning ::
322
+
323
+ Please note that ignoring Bandit warnings should be done with caution, and you should ensure
324
+ that the code is safe and does not introduce any security risks. It is recommended to review the
325
+ `bandit documentation `_ for more information on each warning and the potential risks involved.
326
+
327
+
328
+ Security considerations file
329
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
330
+
331
+ In addition to ignoring specific Bandit warnings, it is a good practice to document the ignored
332
+ advisories in a dedicated file. You can find an example of such a file in the `PyACP security
333
+ considerations `_ documentation page. This way, you can provide to the users a clear overview of
334
+ the vulnerabilities that need to be taken into account when using the library.
0 commit comments