mdb-engine 0.5.0__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mdb_engine/auth/csrf.py CHANGED
@@ -315,7 +315,10 @@ class CSRFMiddleware(BaseHTTPMiddleware):
315
315
 
316
316
  # Cookie-based authentication requires CSRF protection
317
317
  # Check if authentication token cookie is present
318
- auth_token_cookie = request.cookies.get("token")
318
+ # Use same cookie name as SharedAuthMiddleware for consistency
319
+ from .shared_middleware import AUTH_COOKIE_NAME
320
+
321
+ auth_token_cookie = request.cookies.get(AUTH_COOKIE_NAME)
319
322
  if auth_token_cookie:
320
323
  # For WebSocket upgrades, CSRF protection relies on:
321
324
  # 1. Origin validation (already done above) - primary defense
@@ -395,13 +395,17 @@ async def authenticate_websocket(
395
395
 
396
396
  try:
397
397
  # Extract token from httpOnly cookie
398
+ # Use same cookie name as SharedAuthMiddleware for consistency
399
+ from ..auth.shared_middleware import AUTH_COOKIE_NAME
400
+
398
401
  cookies = _get_cookies_from_websocket(websocket)
399
- token = cookies.get("token") # Standard auth token cookie name
402
+ token = cookies.get(AUTH_COOKIE_NAME) # Use mdb_auth_token (same as shared middleware)
400
403
 
401
404
  if not token:
402
- logger.warning(
403
- f"No token cookie found for WebSocket connection to app '{app_slug}' "
405
+ logger.error(
406
+ f"No token cookie found for WebSocket connection to app '{app_slug}' "
404
407
  f"(require_auth={require_auth}). "
408
+ f"Available cookies: {list(cookies.keys()) if cookies else 'none'}. "
405
409
  f"Ensure httpOnly cookie is set during authentication."
406
410
  )
407
411
  if require_auth:
@@ -428,8 +432,11 @@ async def authenticate_websocket(
428
432
  f"(method: cookie)"
429
433
  )
430
434
  return user_id, user_email
431
- except (jwt.ExpiredSignatureError, jwt.InvalidTokenError) as decode_error:
432
- logger.error(f"JWT decode error for app '{app_slug}': {decode_error}", exc_info=True)
435
+ except (jwt.ExpiredSignatureError, jwt.InvalidTokenError):
436
+ logger.exception(
437
+ f"❌ JWT decode error for app '{app_slug}'. "
438
+ f"Token present: {bool(token)}, Token length: {len(token) if token else 0}"
439
+ )
433
440
  raise
434
441
 
435
442
  except WebSocketDisconnect:
@@ -689,12 +696,26 @@ def create_websocket_endpoint(
689
696
  # CRITICAL: Authenticate BEFORE accepting connection
690
697
  # This prevents CSRF middleware from rejecting established connections
691
698
  # We can access headers/query_params before accept() is called
699
+
700
+ # Debug: Log cookies before authentication
701
+ try:
702
+ cookies = _get_cookies_from_websocket(websocket)
703
+ cookie_names = list(cookies.keys()) if cookies else []
704
+ logger.info(
705
+ f"🔍 WebSocket cookies for app '{app_slug}': {cookie_names} "
706
+ f"(require_auth={require_auth})"
707
+ )
708
+ except (AttributeError, TypeError, KeyError, RuntimeError) as cookie_error:
709
+ logger.warning(f"Could not extract cookies for debugging: {cookie_error}")
710
+
692
711
  user_id, user_email = await authenticate_websocket(websocket, app_slug, require_auth)
693
712
 
694
713
  # Handle authentication failure
695
714
  if require_auth and not user_id:
696
- logger.warning(
697
- f"WebSocket authentication failed for app '{app_slug}' - rejecting connection"
715
+ logger.error(
716
+ f"WebSocket authentication FAILED for app '{app_slug}' - "
717
+ f"rejecting connection. require_auth={require_auth}, "
718
+ f"user_id={user_id}, user_email={user_email}"
698
719
  )
699
720
  # Reject without accepting - FastAPI will send 403 if accept() not called
700
721
  # We can't call websocket.close() before accept(), so we just return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdb-engine
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: MongoDB Engine
5
5
  Home-page: https://github.com/ranfysvalle02/mdb-engine
6
6
  Author: Fabian Valle
@@ -14,7 +14,7 @@ mdb_engine/auth/casbin_models.py,sha256=7XtFmRBhhjw1nKprnluvjyJoTj5fzdPeQwVvo6fI
14
14
  mdb_engine/auth/config_defaults.py,sha256=1YI_hIHuTiEXpkEYMcufNHdLr1oxPiJylg3CKrJCSGY,2012
15
15
  mdb_engine/auth/config_helpers.py,sha256=Qharb2YagLOKDGtE7XhYRDbBoQ_KGykrcIKrsOwWIJ4,6303
16
16
  mdb_engine/auth/cookie_utils.py,sha256=glsSocSmy-_wRTLro0xy17s84oBk3HPDPL-FVXl7Rv8,5302
17
- mdb_engine/auth/csrf.py,sha256=1MQuLI1gtWtm6ce0NhARRkD7bk6JfUaLUR0YCL7RL4Q,20393
17
+ mdb_engine/auth/csrf.py,sha256=O6q7BOZuzUy6N71EUuabhBqYsRYHuAcCr5Fyabcy1vw,20538
18
18
  mdb_engine/auth/decorators.py,sha256=LkVVEuRrT0Iz8EwctN14BEi3fSV-xtN6DaGXgtbiYYo,12287
19
19
  mdb_engine/auth/dependencies.py,sha256=JB1iYvZJgTR6gcaiGe_GJFCS6NdUKMxWBZRv6vVxnzw,27112
20
20
  mdb_engine/auth/helpers.py,sha256=BCrid985cYh-3h5ZMUV9TES0q40uJXio4oYKQZta7KA,1970
@@ -86,12 +86,12 @@ mdb_engine/repositories/mongo.py,sha256=Wg32_6v0KHAHumhz5z8QkoqJRWAMJFA7Y2lYIJ7L
86
86
  mdb_engine/repositories/unit_of_work.py,sha256=XvmwGOspEDj4hsfOULPsQKjB1QZqh83TJo6vGV4tiqU,5118
87
87
  mdb_engine/routing/README.md,sha256=WVvTQXDq0amryrjkCu0wP_piOEwFjLukjmPz2mroWHY,13658
88
88
  mdb_engine/routing/__init__.py,sha256=reupjHi_RTc2ZBA4AH5XzobAmqy4EQIsfSUcTkFknUM,2438
89
- mdb_engine/routing/websockets.py,sha256=WBdJui0VMi5n30suXa8RPGkGgeHON4x3FyjbdsqHudY,30860
89
+ mdb_engine/routing/websockets.py,sha256=ox9mKDVhQmKdAtdomQ99UXxp9ZrBn-OkMhR6rtZ_HiA,31887
90
90
  mdb_engine/utils/__init__.py,sha256=lDxQSGqkV4fVw5TWIk6FA6_eey_ZnEtMY0fir3cpAe8,236
91
91
  mdb_engine/utils/mongo.py,sha256=Oqtv4tQdpiiZzrilGLEYQPo8Vmh8WsTQypxQs8Of53s,3369
92
- mdb_engine-0.5.0.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
93
- mdb_engine-0.5.0.dist-info/METADATA,sha256=15KsimjJFGd_mmGzVJG9S4PIV-gI9m4yHuGmqAev7dM,15810
94
- mdb_engine-0.5.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
95
- mdb_engine-0.5.0.dist-info/entry_points.txt,sha256=INCbYdFbBzJalwPwxliEzLmPfR57IvQ7RAXG_pn8cL8,48
96
- mdb_engine-0.5.0.dist-info/top_level.txt,sha256=PH0UEBwTtgkm2vWvC9He_EOMn7hVn_Wg_Jyc0SmeO8k,11
97
- mdb_engine-0.5.0.dist-info/RECORD,,
92
+ mdb_engine-0.5.1.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
93
+ mdb_engine-0.5.1.dist-info/METADATA,sha256=5_gq3GBHSvvct52eMIi7zXDZ_KOK_A3rzDSc7RXmhRU,15810
94
+ mdb_engine-0.5.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
95
+ mdb_engine-0.5.1.dist-info/entry_points.txt,sha256=INCbYdFbBzJalwPwxliEzLmPfR57IvQ7RAXG_pn8cL8,48
96
+ mdb_engine-0.5.1.dist-info/top_level.txt,sha256=PH0UEBwTtgkm2vWvC9He_EOMn7hVn_Wg_Jyc0SmeO8k,11
97
+ mdb_engine-0.5.1.dist-info/RECORD,,