quart-security 2.0.5__tar.gz → 2.0.6__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.
- {quart_security-2.0.5 → quart_security-2.0.6}/PKG-INFO +8 -1
- {quart_security-2.0.5 → quart_security-2.0.6}/README.md +7 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/pyproject.toml +1 -1
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/__init__.py +2 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/signals.py +4 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/views.py +51 -27
- {quart_security-2.0.5 → quart_security-2.0.6}/LICENSE +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/breach.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/core.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/datastore.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/decorators.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/email.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/forms.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/models.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/password.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/proxies.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/py.typed +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/state.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/_macros.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/change_password.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/login_user.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/mf_recovery.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/mf_recovery_codes.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/register_user.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/two_factor_select.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/two_factor_setup.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/two_factor_verify_code.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/wan_register.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/wan_signin.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/wan_verify.html +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/totp.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/quart_security/utils.py +0 -0
- {quart_security-2.0.5 → quart_security-2.0.6}/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.
|
|
3
|
+
Version: 2.0.6
|
|
4
4
|
Summary: Native async auth for Quart
|
|
5
5
|
Author: quart-security maintainers
|
|
6
6
|
Requires-Python: >=3.11
|
|
@@ -169,6 +169,8 @@ Core:
|
|
|
169
169
|
|
|
170
170
|
Existing pbkdf2_sha512 and bcrypt hashes continue to verify after the argon2 default change. They are transparently rehashed to argon2id on the user's next successful login.
|
|
171
171
|
|
|
172
|
+
Until then, a failed login for an account with a legacy hash takes a different time than one for an unknown email, which is checked against an argon2id dummy, so timing can reveal that the account exists. Apps that import hashes from another system should require a password reset rather than leave them in place.
|
|
173
|
+
|
|
172
174
|
2FA:
|
|
173
175
|
- `SECURITY_TWO_FACTOR`
|
|
174
176
|
- `SECURITY_TOTP_ISSUER`
|
|
@@ -196,6 +198,10 @@ Routing:
|
|
|
196
198
|
- `SECURITY_POST_LOGIN_VIEW`
|
|
197
199
|
- `SECURITY_POST_REGISTER_VIEW`
|
|
198
200
|
|
|
201
|
+
A visit to `/login?next=/path` sends the user to `/path` after they sign in, through 2FA and passkey sign-in too. Only same-site paths are honored, the next visit to `/login` replaces the target, and a sign-in finishing more than 10 minutes after the form was shown ignores it.
|
|
202
|
+
|
|
203
|
+
Registration answers the same way whether or not the email already has an account, so it cannot be used to find accounts. For an existing email nothing is created and `user_register_conflict` fires with the existing user; send the owner a notice from it in the background, because a receiver that waits on mail slows only that response.
|
|
204
|
+
|
|
199
205
|
## Route Map
|
|
200
206
|
|
|
201
207
|
Core:
|
|
@@ -245,6 +251,7 @@ from quart_security import (
|
|
|
245
251
|
password_changed,
|
|
246
252
|
tf_profile_changed,
|
|
247
253
|
user_registered,
|
|
254
|
+
user_register_conflict,
|
|
248
255
|
url_for_security,
|
|
249
256
|
)
|
|
250
257
|
```
|
|
@@ -139,6 +139,8 @@ Core:
|
|
|
139
139
|
|
|
140
140
|
Existing pbkdf2_sha512 and bcrypt hashes continue to verify after the argon2 default change. They are transparently rehashed to argon2id on the user's next successful login.
|
|
141
141
|
|
|
142
|
+
Until then, a failed login for an account with a legacy hash takes a different time than one for an unknown email, which is checked against an argon2id dummy, so timing can reveal that the account exists. Apps that import hashes from another system should require a password reset rather than leave them in place.
|
|
143
|
+
|
|
142
144
|
2FA:
|
|
143
145
|
- `SECURITY_TWO_FACTOR`
|
|
144
146
|
- `SECURITY_TOTP_ISSUER`
|
|
@@ -166,6 +168,10 @@ Routing:
|
|
|
166
168
|
- `SECURITY_POST_LOGIN_VIEW`
|
|
167
169
|
- `SECURITY_POST_REGISTER_VIEW`
|
|
168
170
|
|
|
171
|
+
A visit to `/login?next=/path` sends the user to `/path` after they sign in, through 2FA and passkey sign-in too. Only same-site paths are honored, the next visit to `/login` replaces the target, and a sign-in finishing more than 10 minutes after the form was shown ignores it.
|
|
172
|
+
|
|
173
|
+
Registration answers the same way whether or not the email already has an account, so it cannot be used to find accounts. For an existing email nothing is created and `user_register_conflict` fires with the existing user; send the owner a notice from it in the background, because a receiver that waits on mail slows only that response.
|
|
174
|
+
|
|
169
175
|
## Route Map
|
|
170
176
|
|
|
171
177
|
Core:
|
|
@@ -215,6 +221,7 @@ from quart_security import (
|
|
|
215
221
|
password_changed,
|
|
216
222
|
tf_profile_changed,
|
|
217
223
|
user_registered,
|
|
224
|
+
user_register_conflict,
|
|
218
225
|
url_for_security,
|
|
219
226
|
)
|
|
220
227
|
```
|
|
@@ -16,6 +16,7 @@ from .signals import (
|
|
|
16
16
|
tf_profile_changed,
|
|
17
17
|
user_authenticated,
|
|
18
18
|
user_logged_out,
|
|
19
|
+
user_register_conflict,
|
|
19
20
|
user_registered,
|
|
20
21
|
)
|
|
21
22
|
from .state import SecurityState, SQLAlchemyStateStore
|
|
@@ -40,5 +41,6 @@ __all__ = [
|
|
|
40
41
|
"password_changed",
|
|
41
42
|
"tf_profile_changed",
|
|
42
43
|
"user_registered",
|
|
44
|
+
"user_register_conflict",
|
|
43
45
|
"url_for_security",
|
|
44
46
|
]
|
|
@@ -9,3 +9,7 @@ user_logged_out = _signals.signal("user-logged-out")
|
|
|
9
9
|
password_changed = _signals.signal("password-changed")
|
|
10
10
|
tf_profile_changed = _signals.signal("tf-profile-changed")
|
|
11
11
|
user_registered = _signals.signal("user-registered")
|
|
12
|
+
# Registration with an email that already has an account. The form answers as if
|
|
13
|
+
# it succeeded, so tell the owner out of band; receivers run inside the request,
|
|
14
|
+
# so send mail in the background or the delay reveals the account.
|
|
15
|
+
user_register_conflict = _signals.signal("user-register-conflict")
|
|
@@ -42,7 +42,12 @@ from .password import (
|
|
|
42
42
|
verify_password_async,
|
|
43
43
|
)
|
|
44
44
|
from .proxies import _security, current_user
|
|
45
|
-
from .signals import
|
|
45
|
+
from .signals import (
|
|
46
|
+
password_changed,
|
|
47
|
+
tf_profile_changed,
|
|
48
|
+
user_register_conflict,
|
|
49
|
+
user_registered,
|
|
50
|
+
)
|
|
46
51
|
from .utils import maybe_await, naive_utcnow, url_for_security
|
|
47
52
|
|
|
48
53
|
security_bp = Blueprint("security", __name__, template_folder="templates")
|
|
@@ -147,6 +152,22 @@ def _safe_redirect_target(candidate: str | None, fallback: str = "/") -> str:
|
|
|
147
152
|
return candidate
|
|
148
153
|
|
|
149
154
|
|
|
155
|
+
# A login that finishes later than this after the form was shown ignores its
|
|
156
|
+
# `next`, so an abandoned target cannot redirect an unrelated later sign-in.
|
|
157
|
+
NEXT_TTL_SECONDS = 600
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
async def _complete_login(user):
|
|
161
|
+
"""Log the user in and send them where `/login?next=` asked, if it was safe."""
|
|
162
|
+
# login_user clears the session, so read the target first.
|
|
163
|
+
target, stored_at = session.pop("security_next", None) or (None, 0)
|
|
164
|
+
if time.time() - stored_at > NEXT_TTL_SECONDS:
|
|
165
|
+
target = None
|
|
166
|
+
await _security.login_user(user)
|
|
167
|
+
fallback = _resolve_redirect("SECURITY_POST_LOGIN_VIEW", "login")
|
|
168
|
+
return redirect(_safe_redirect_target(target, fallback=fallback))
|
|
169
|
+
|
|
170
|
+
|
|
150
171
|
def _webauthn_rp_id() -> str:
|
|
151
172
|
configured = current_app.config.get("SECURITY_WAN_RP_ID")
|
|
152
173
|
if configured:
|
|
@@ -349,6 +370,14 @@ def _format_webauthn_credential(credential) -> dict:
|
|
|
349
370
|
async def login():
|
|
350
371
|
form = await _security.login_form_cls.from_formdata()
|
|
351
372
|
await _enforce_csrf(getattr(form, "_submitted_csrf", None))
|
|
373
|
+
if not _is_post():
|
|
374
|
+
# Every visit to the form replaces the target, so an abandoned one never
|
|
375
|
+
# redirects a later login. The passkey and 2FA paths finish with it too.
|
|
376
|
+
next_url = _safe_redirect_target(request.args.get("next"), fallback="")
|
|
377
|
+
if next_url:
|
|
378
|
+
session["security_next"] = [next_url, int(time.time())]
|
|
379
|
+
else:
|
|
380
|
+
session.pop("security_next", None)
|
|
352
381
|
|
|
353
382
|
if _is_post() and form.validate():
|
|
354
383
|
user = await _find_user(email=_normalize_email(form.email.data))
|
|
@@ -387,8 +416,7 @@ async def login():
|
|
|
387
416
|
return redirect(url_for_security("two_factor_token_validation"))
|
|
388
417
|
|
|
389
418
|
await _reset_auth_failures(user)
|
|
390
|
-
await
|
|
391
|
-
return redirect(_resolve_redirect("SECURITY_POST_LOGIN_VIEW", "login"))
|
|
419
|
+
return await _complete_login(user)
|
|
392
420
|
|
|
393
421
|
# Track failed login
|
|
394
422
|
if user:
|
|
@@ -409,12 +437,9 @@ async def register():
|
|
|
409
437
|
|
|
410
438
|
if _is_post() and form.validate():
|
|
411
439
|
email = _normalize_email(form.email.data)
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
"security/register_user.html", register_user_form=form
|
|
416
|
-
)
|
|
417
|
-
|
|
440
|
+
# Password checks come first and an existing email gets the same answer as
|
|
441
|
+
# a new one, after the same hashing work, so the form never reveals which
|
|
442
|
+
# emails have an account.
|
|
418
443
|
errors = validate_password(
|
|
419
444
|
form.password.data,
|
|
420
445
|
min_length=current_app.config.get("SECURITY_PASSWORD_LENGTH_MIN", 12),
|
|
@@ -441,20 +466,22 @@ async def register():
|
|
|
441
466
|
"security/register_user.html", register_user_form=form
|
|
442
467
|
)
|
|
443
468
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
user_kwargs
|
|
469
|
+
password = await hash_password_async(form.password.data)
|
|
470
|
+
app = current_app._get_current_object()
|
|
471
|
+
existing = await _find_user(email=email)
|
|
472
|
+
if existing:
|
|
473
|
+
await user_register_conflict.send_async(app, user=existing)
|
|
474
|
+
else:
|
|
475
|
+
user_kwargs = {"email": email, "password": password, "active": True}
|
|
476
|
+
if hasattr(form, "name") and form.name.data:
|
|
477
|
+
user_kwargs["name"] = form.name.data.strip()
|
|
451
478
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
479
|
+
user = await _create_user(**user_kwargs)
|
|
480
|
+
if hasattr(user, "confirmed_at"):
|
|
481
|
+
user.confirmed_at = naive_utcnow()
|
|
455
482
|
|
|
456
|
-
|
|
457
|
-
|
|
483
|
+
await _commit()
|
|
484
|
+
await user_registered.send_async(app, user=user)
|
|
458
485
|
|
|
459
486
|
await flash("Registration successful. Please log in.", "success")
|
|
460
487
|
return redirect(_resolve_redirect("SECURITY_POST_REGISTER_VIEW", "login"))
|
|
@@ -720,8 +747,7 @@ async def two_factor_token_validation():
|
|
|
720
747
|
return redirect(url_for_security("login"))
|
|
721
748
|
session.pop("tf_user_id", None)
|
|
722
749
|
await _reset_auth_failures(user)
|
|
723
|
-
await
|
|
724
|
-
return redirect(_resolve_redirect("SECURITY_POST_LOGIN_VIEW", "login"))
|
|
750
|
+
return await _complete_login(user)
|
|
725
751
|
|
|
726
752
|
await _record_auth_failure(user)
|
|
727
753
|
await flash("Invalid code", "error")
|
|
@@ -808,8 +834,7 @@ async def mf_recovery():
|
|
|
808
834
|
return redirect(url_for_security("login"))
|
|
809
835
|
session.pop("tf_user_id", None)
|
|
810
836
|
await _reset_auth_failures(user)
|
|
811
|
-
await
|
|
812
|
-
return redirect(_resolve_redirect("SECURITY_POST_LOGIN_VIEW", "login"))
|
|
837
|
+
return await _complete_login(user)
|
|
813
838
|
|
|
814
839
|
await _record_auth_failure(user)
|
|
815
840
|
await flash("Invalid recovery code", "error")
|
|
@@ -1062,8 +1087,7 @@ async def wan_signin_response():
|
|
|
1062
1087
|
if hasattr(stored_credential, "lastuse_datetime"):
|
|
1063
1088
|
stored_credential.lastuse_datetime = naive_utcnow()
|
|
1064
1089
|
|
|
1065
|
-
await
|
|
1066
|
-
return redirect(_resolve_redirect("SECURITY_POST_LOGIN_VIEW", "login"))
|
|
1090
|
+
return await _complete_login(user)
|
|
1067
1091
|
|
|
1068
1092
|
|
|
1069
1093
|
@security_bp.route("/wan-verify", methods=["GET", "POST"])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/_macros.html
RENAMED
|
File without changes
|
{quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/change_password.html
RENAMED
|
File without changes
|
{quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/login_user.html
RENAMED
|
File without changes
|
{quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/mf_recovery.html
RENAMED
|
File without changes
|
|
File without changes
|
{quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/register_user.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/wan_register.html
RENAMED
|
File without changes
|
{quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/wan_signin.html
RENAMED
|
File without changes
|
{quart_security-2.0.5 → quart_security-2.0.6}/quart_security/templates/security/wan_verify.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|