Skip to content

Commit 2a30884

Browse files
fix(security): resolve code scanning alerts in JWT and checksum handling (#309)
* fix(security): resolve code scanning alerts in JWT and checksum handling
1 parent 08b1b22 commit 2a30884

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

cloudsmith_cli/core/credentials/oidc/cache.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ def _cache_key(api_host: str, org: str, service_slug: str) -> str:
4141

4242

4343
def _decode_jwt_exp(token: str) -> float | None:
44-
"""Decode the exp claim from a JWT without verification."""
44+
"""Read the exp claim from a JWT payload.
45+
46+
The token is only inspected to determine a cache TTL; it is never used to
47+
make an authorization decision, so the signature is deliberately not
48+
verified (the API rejects tampered tokens regardless).
49+
"""
4550
try:
4651
import jwt
4752

48-
payload = jwt.decode(
49-
token,
50-
options={"verify_signature": False},
51-
algorithms=["RS256", "ES256", "HS256"],
52-
)
53+
payload = jwt.decode(token, options={"verify_signature": False})
5354
exp = payload.get("exp")
5455
if exp is not None:
5556
return float(exp)

cloudsmith_cli/core/download.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def _verify_checksum(filepath: str, expected: str) -> bool:
583583

584584
# Try SHA1
585585
if len(expected) == 40:
586-
sha1_hash = hashlib.sha1()
586+
sha1_hash = hashlib.sha1(usedforsecurity=False)
587587
with open(filepath, "rb") as f:
588588
for chunk in iter(lambda: f.read(4096), b""):
589589
sha1_hash.update(chunk)

cloudsmith_cli/core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def read_file(*path):
3535

3636
def calculate_file_md5(filepath, blocksize=2**20):
3737
"""Calculate an MD5 hash for a file."""
38-
checksum = hashlib.md5()
38+
checksum = hashlib.md5(usedforsecurity=False)
3939

4040
with click.open_file(filepath, "rb") as f:
4141

0 commit comments

Comments
 (0)