Skip to content

Commit 270ecea

Browse files
author
Mateo Lostanlen
committed
fix: drop passlib, hash with bcrypt directly
passlib 1.7.4 imports bcrypt.__about__ at module load to detect the bcrypt version. That attribute was removed in bcrypt 4.x, so once the dependabot bcrypt 5.0.0 bump lands, passlib raises AttributeError on import and the backend fails its health check at startup. passlib is effectively unmaintained (last release 2020). Rather than work around the import, replace the CryptContext usage in src/app/core/security.py with direct bcrypt calls — the API surface we use is just hashpw/checkpw plus a salt. Also pin the pyro-camera-api-client git dep via [tool.uv.sources] so 'uv sync --locked' stays stable after this lockfile change.
1 parent 1b59043 commit 270ecea

3 files changed

Lines changed: 7 additions & 37 deletions

File tree

‎pyproject.toml‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package = false
1212

1313
[tool.uv.sources]
1414
pyroclient = { path = "client", editable = true }
15+
pyro-camera-api-client = { git = "https://github.com/pyronear/pyro-engine.git", subdirectory = "pyro_camera_api/client", rev = "6d525b150a764447e62beec26e39702f71d8461e" }
1516

1617
[dependency-groups]
1718
server = [
@@ -21,7 +22,6 @@ server = [
2122
"pydantic-settings>=2.0.0,<3.0.0",
2223
"requests>=2.32.0,<3.0.0",
2324
"PyJWT>=2.12.0,<3.0.0",
24-
"passlib[bcrypt]>=1.7.4,<2.0.0",
2525
"bcrypt==5.0.0",
2626
"uvicorn>=0.11.1,<1.0.0",
2727
"asyncpg>=0.25.0,<1.0.0",
@@ -33,7 +33,7 @@ server = [
3333
"python-magic>=0.4.17,<0.5.0",
3434
"boto3>=1.26.0,<1.36.0", # https://github.com/boto/boto3/issues/4435
3535
"httpx>=0.24.0,<1.0.0",
36-
"pyro-camera-api-client @ git+https://github.com/pyronear/pyro-engine.git@main#subdirectory=pyro_camera_api/client",
36+
"pyro-camera-api-client",
3737
"geopy>=2.4.0,<3.0.0",
3838
"networkx>=3.2.0,<4.0.0",
3939
"numpy>=2.4.4,<3.0.0",
@@ -48,7 +48,6 @@ quality = [
4848
"types-requests>=2.0.0",
4949
"types-python-dateutil>=2.8.0,<3.0.0",
5050
"sqlalchemy-stubs>=0.4,<0.5",
51-
"types-passlib>=1.7.0",
5251
]
5352
test = [
5453
"pytest==9.0.3",

‎src/app/core/security.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
from datetime import timedelta
77
from typing import Any, Dict, Optional
88

9+
import bcrypt
910
import jwt
10-
from passlib.context import CryptContext
1111

1212
from app.core.config import settings
1313
from app.core.time import utcnow
1414

1515
__all__ = ["create_access_token", "hash_password", "verify_password"]
1616

17-
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
18-
1917

2018
def create_access_token(content: Dict[str, Any], expires_minutes: Optional[int] = None) -> str:
2119
"""Encode content dict using security algorithm, setting expiration."""
@@ -25,8 +23,8 @@ def create_access_token(content: Dict[str, Any], expires_minutes: Optional[int]
2523

2624

2725
def verify_password(plain_password: str, hashed_password: str) -> bool:
28-
return pwd_context.verify(plain_password, hashed_password)
26+
return bcrypt.checkpw(plain_password.encode("utf-8"), hashed_password.encode("utf-8"))
2927

3028

3129
def hash_password(password: str) -> str:
32-
return pwd_context.hash(password)
30+
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode("utf-8")

‎uv.lock‎

Lines changed: 2 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)