Skip to content

Commit 43d341c

Browse files
committed
Pleasing bandit
1 parent df305e3 commit 43d341c

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

.banditrc.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
skips:
22
# Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
3-
# => OK, we don't care thought
3+
# => OK, we don't care though
44
- B101
5+
56
# Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.
67
# cf. https://github.com/PyFPDF/fpdf2/issues/345
78
- B301
8-
# Use of insecure MD2, MD4, MD5, or SHA1 hash function.
9-
# => the md5 module is only used to build a cache key, this is secure
10-
- B303
9+
1110
# Consider possible security implications associated with pickle module.
1211
# cf. https://github.com/PyFPDF/fpdf2/issues/345
1312
- B403

fpdf/fpdf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2732,11 +2732,11 @@ def image(
27322732
if isinstance(name, str):
27332733
img = None
27342734
elif isinstance(name, Image.Image):
2735-
name, img = hashlib.md5(name.tobytes()).hexdigest(), name
2735+
name, img = hashlib.md5(name.tobytes()).hexdigest(), name # nosec B303,B324 # we just build a cache key, this is secure
27362736
elif isinstance(name, io.BytesIO):
27372737
if _is_xml(name):
27382738
return self._vector_image(name, x, y, w, h, link, title, alt_text)
2739-
name, img = hashlib.md5(name.getvalue()).hexdigest(), name
2739+
name, img = hashlib.md5(name.getvalue()).hexdigest(), name # nosec B303,B324 # we just build a cache key, this is secure
27402740
else:
27412741
name, img = str(name), name
27422742
info = self.images.get(name)

fpdf/image_parsing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def load_image(filename):
2222
return filename
2323
# by default loading from network is allowed for all images
2424
if filename.startswith(("http://", "https://")):
25-
with urlopen(filename) as url_file: # nosec B310
25+
with urlopen(filename) as url_file: # nosec B310 # permitted schemes are whitelisted
2626
return BytesIO(url_file.read())
2727
elif filename.startswith("data"):
2828
return _decode_base64_image(filename)

0 commit comments

Comments
 (0)