Skip to content

Commit 932994b

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b3017d0 commit 932994b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

doc/source/how-to/vulnerabilities.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ and the risk of command injection is significantly reduced.
193193
.. code:: python
194194
195195
import subprocess
196+
196197
user_input = "malicious_command; rm -rf /" # User input that could be malicious
197198
subprocess.run(f"echo {user_input}", shell=True) # Vulnerable to command injection
198199
@@ -201,6 +202,7 @@ and the risk of command injection is significantly reduced.
201202
.. code:: python
202203
203204
import subprocess
205+
204206
user_input = "malicious_command; rm -rf /" # User input that could be malicious
205207
# Removing shell=True and using a list
206208
subprocess.run(["echo", user_input]) # User input is not executed as a shell command
@@ -219,21 +221,21 @@ exceptions explicitly and log or raise them as needed.
219221
.. code:: python
220222
221223
try:
222-
risky_operation() # Some code that might raise an exception
224+
risky_operation() # Some code that might raise an exception
223225
except:
224-
continue # This will silently ignore all the exceptions and continue execution
226+
continue # This will silently ignore all the exceptions and continue execution
225227
226228
.. tab-item:: `try except continue` with explicit exception handling
227229

228230
.. code:: python
229231
230232
try:
231-
risky_operation()
233+
risky_operation()
232234
except SpecificException as e:
233-
continue # Handle specific exceptions and continue
235+
continue # Handle specific exceptions and continue
234236
except AnotherSpecificException as e:
235-
log_error(e) # Log the error for debugging
236-
raise # Raise the exception to notify the caller
237+
log_error(e) # Log the error for debugging
238+
raise # Raise the exception to notify the caller
237239
238240
239241
**requests.get() without timeout**
@@ -249,13 +251,15 @@ prevent this issue.
249251
.. code:: python
250252
251253
import requests
254+
252255
response = requests.get("https://example.com") # No timeout specified
253256
254257
.. tab-item:: `requests.get()` with timeout
255258

256259
.. code:: python
257260
258261
import requests
262+
259263
response = requests.get("https://example.com", timeout=5) # Timeout set to 5 seconds
260264
261265
@@ -272,6 +276,7 @@ provides a secure way to generate random numbers.
272276
.. code:: python
273277
274278
import random
279+
275280
random_number = random.randint(1, 100) # Predictable random number generation
276281
random_letter = random.choice(["a", "b", "c"]) # Predictable choice from a list
277282
@@ -280,5 +285,6 @@ provides a secure way to generate random numbers.
280285
.. code:: python
281286
282287
import secrets
288+
283289
secure_random_number = secrets.randbelow(100) # Secure random number generation
284290
secure_random_letter = secrets.choice(["a", "b", "c"]) # Secure choice from a list

0 commit comments

Comments
 (0)