quart-security 2.0.4__tar.gz → 2.0.5__tar.gz

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.
Files changed (33) hide show
  1. {quart_security-2.0.4 → quart_security-2.0.5}/PKG-INFO +1 -1
  2. {quart_security-2.0.4 → quart_security-2.0.5}/pyproject.toml +1 -1
  3. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/password.py +12 -0
  4. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/views.py +13 -5
  5. {quart_security-2.0.4 → quart_security-2.0.5}/LICENSE +0 -0
  6. {quart_security-2.0.4 → quart_security-2.0.5}/README.md +0 -0
  7. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/__init__.py +0 -0
  8. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/breach.py +0 -0
  9. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/core.py +0 -0
  10. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/datastore.py +0 -0
  11. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/decorators.py +0 -0
  12. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/email.py +0 -0
  13. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/forms.py +0 -0
  14. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/models.py +0 -0
  15. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/proxies.py +0 -0
  16. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/py.typed +0 -0
  17. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/signals.py +0 -0
  18. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/state.py +0 -0
  19. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/_macros.html +0 -0
  20. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/change_password.html +0 -0
  21. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/login_user.html +0 -0
  22. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/mf_recovery.html +0 -0
  23. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/mf_recovery_codes.html +0 -0
  24. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/register_user.html +0 -0
  25. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/two_factor_select.html +0 -0
  26. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/two_factor_setup.html +0 -0
  27. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/two_factor_verify_code.html +0 -0
  28. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/wan_register.html +0 -0
  29. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/wan_signin.html +0 -0
  30. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/templates/security/wan_verify.html +0 -0
  31. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/totp.py +0 -0
  32. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/utils.py +0 -0
  33. {quart_security-2.0.4 → quart_security-2.0.5}/quart_security/webauthn.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quart-security
3
- Version: 2.0.4
3
+ Version: 2.0.5
4
4
  Summary: Native async auth for Quart
5
5
  Author: quart-security maintainers
6
6
  Requires-Python: >=3.11
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
4
4
 
5
5
  [project]
6
6
  name = "quart-security"
7
- version = "2.0.4"
7
+ version = "2.0.5"
8
8
  description = "Native async auth for Quart"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -1,6 +1,7 @@
1
1
  """Password hashing and validation helpers."""
2
2
 
3
3
  import asyncio
4
+ import secrets
4
5
 
5
6
  from passlib.context import CryptContext
6
7
  from quart import current_app
@@ -82,6 +83,17 @@ async def verify_password_async(password: str, password_hash: str, *, app=None)
82
83
  return await asyncio.to_thread(verify_password, password, password_hash, app=app)
83
84
 
84
85
 
86
+ async def unknown_user_hash_async(*, app=None) -> str:
87
+ """A hash to verify against when no account matches, so a login for an
88
+ unknown or inactive email costs the same as a wrong password."""
89
+ app = app or current_app._get_current_object()
90
+ cached = app.extensions.get("quart_security_unknown_hash")
91
+ if cached is None:
92
+ cached = await hash_password_async(secrets.token_urlsafe(32), app=app)
93
+ app.extensions["quart_security_unknown_hash"] = cached
94
+ return cached
95
+
96
+
85
97
  def validate_password(password: str, min_length: int = 12) -> list[str]:
86
98
  errors: list[str] = []
87
99
  if len(password) < min_length:
@@ -37,6 +37,7 @@ from .forms import (
37
37
  from .password import (
38
38
  hash_password_async,
39
39
  password_needs_rehash,
40
+ unknown_user_hash_async,
40
41
  validate_password,
41
42
  verify_password_async,
42
43
  )
@@ -364,11 +365,14 @@ async def login():
364
365
  user.locked_until = None
365
366
  await _commit()
366
367
 
367
- if (
368
- user
369
- and getattr(user, "active", True)
370
- and await verify_password_async(form.password.data, user.password)
371
- ):
368
+ # Always run one verify, so response time does not reveal which emails
369
+ # have an active account.
370
+ known = user is not None and getattr(user, "active", True)
371
+ password_ok = await verify_password_async(
372
+ form.password.data,
373
+ user.password if known else await unknown_user_hash_async(),
374
+ )
375
+ if known and password_ok:
372
376
  # Transparent rehash: upgrade weak/legacy hash on successful login
373
377
  if password_needs_rehash(user.password):
374
378
  user.password = await hash_password_async(form.password.data)
@@ -929,7 +933,11 @@ async def wan_register_response():
929
933
  await flash("Passkey registration failed.", "error")
930
934
  return redirect(url_for_security("wan_register"))
931
935
 
936
+ # Look across all users too: a software authenticator can pick any credential
937
+ # ID, and sign-in resolves the owner by ID alone.
932
938
  existing = await _find_webauthn_credential(
939
+ verification["credential_id"], user=None
940
+ ) or await _find_webauthn_credential(
933
941
  verification["credential_id"], user=current_user
934
942
  )
935
943
  if existing:
File without changes
File without changes