quart-security 2.2.0__tar.gz → 2.3.0__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 (41) hide show
  1. {quart_security-2.2.0 → quart_security-2.3.0}/PKG-INFO +2 -2
  2. {quart_security-2.2.0 → quart_security-2.3.0}/README.md +1 -1
  3. {quart_security-2.2.0 → quart_security-2.3.0}/pyproject.toml +1 -1
  4. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/decorators.py +14 -1
  5. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/views.py +5 -0
  6. {quart_security-2.2.0 → quart_security-2.3.0}/LICENSE +0 -0
  7. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/__init__.py +0 -0
  8. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/breach.py +0 -0
  9. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/core.py +0 -0
  10. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/datastore.py +0 -0
  11. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/email.py +0 -0
  12. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/forms.py +0 -0
  13. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/models.py +0 -0
  14. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/password.py +0 -0
  15. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/proxies.py +0 -0
  16. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/py.typed +0 -0
  17. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/signals.py +0 -0
  18. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/state.py +0 -0
  19. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/_macros.html +0 -0
  20. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/change_password.html +0 -0
  21. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/confirm_email.html +0 -0
  22. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/email/confirmation_instructions.txt +0 -0
  23. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/email/register_conflict.txt +0 -0
  24. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/email/reset_instructions.txt +0 -0
  25. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/email/reset_notice.txt +0 -0
  26. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/forgot_password.html +0 -0
  27. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/login_user.html +0 -0
  28. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/mf_recovery.html +0 -0
  29. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/mf_recovery_codes.html +0 -0
  30. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/register_user.html +0 -0
  31. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/reset_password.html +0 -0
  32. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/send_confirmation.html +0 -0
  33. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/two_factor_select.html +0 -0
  34. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/two_factor_setup.html +0 -0
  35. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/two_factor_verify_code.html +0 -0
  36. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/wan_register.html +0 -0
  37. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/wan_signin.html +0 -0
  38. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/templates/security/wan_verify.html +0 -0
  39. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/totp.py +0 -0
  40. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/utils.py +0 -0
  41. {quart_security-2.2.0 → quart_security-2.3.0}/quart_security/webauthn.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quart-security
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Native async auth for Quart
5
5
  Author: quart-security maintainers
6
6
  Requires-Python: >=3.11
@@ -210,7 +210,7 @@ Routing:
210
210
  - `SECURITY_POST_LOGIN_VIEW`
211
211
  - `SECURITY_POST_REGISTER_VIEW`
212
212
 
213
- A visit to `/login?next=/path` sends the user to `/path` after they sign in, through 2FA and passkey sign-in too. `auth_required` sends the page that was asked for. 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.
213
+ A visit to `/login?next=/path` sends the user to `/path` after they sign in, through 2FA and passkey sign-in too. `auth_required` sends the page that was asked for. 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. Only a GET records its page: a form posted after the session expired goes to plain `/login`. A user who is already signed in and visits `/login` is sent straight to the target, or to `SECURITY_POST_LOGIN_VIEW`.
214
214
 
215
215
  Registration answers the same way whether or not the email already has an account. For an existing email nothing is created and `user_register_conflict` fires with the existing user. On its own that is not enough: someone can register an email and try to sign in with the password they chose, which works only if the account is new. Turn on `SECURITY_CONFIRMABLE` to close that gap.
216
216
 
@@ -180,7 +180,7 @@ Routing:
180
180
  - `SECURITY_POST_LOGIN_VIEW`
181
181
  - `SECURITY_POST_REGISTER_VIEW`
182
182
 
183
- A visit to `/login?next=/path` sends the user to `/path` after they sign in, through 2FA and passkey sign-in too. `auth_required` sends the page that was asked for. 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.
183
+ A visit to `/login?next=/path` sends the user to `/path` after they sign in, through 2FA and passkey sign-in too. `auth_required` sends the page that was asked for. 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. Only a GET records its page: a form posted after the session expired goes to plain `/login`. A user who is already signed in and visits `/login` is sent straight to the target, or to `SECURITY_POST_LOGIN_VIEW`.
184
184
 
185
185
  Registration answers the same way whether or not the email already has an account. For an existing email nothing is created and `user_register_conflict` fires with the existing user. On its own that is not enough: someone can register an email and try to sign in with the password they chose, which works only if the account is new. Turn on `SECURITY_CONFIRMABLE` to close that gap.
186
186
 
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
4
4
 
5
5
  [project]
6
6
  name = "quart-security"
7
- version = "2.2.0"
7
+ version = "2.3.0"
8
8
  description = "Native async auth for Quart"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -11,6 +11,15 @@ from .proxies import current_user
11
11
  from .utils import url_for_security
12
12
 
13
13
 
14
+ def _is_navigation():
15
+ # Only a page visit may pick where login goes next: an EventSource or XHR
16
+ # that outlived its session would otherwise hand its URL to the next login.
17
+ mode = request.headers.get("Sec-Fetch-Mode")
18
+ if mode and mode != "navigate":
19
+ return False
20
+ return "Accept" not in request.headers or request.accept_mimetypes.accept_html
21
+
22
+
14
23
  def auth_required(*methods, fresh=False):
15
24
  """Require an authenticated user for a route."""
16
25
 
@@ -22,8 +31,12 @@ def auth_required(*methods, fresh=False):
22
31
  @wraps(func)
23
32
  async def wrapper(*args, **kwargs):
24
33
  if not current_user.is_authenticated:
25
- if request.is_json:
34
+ if request.is_json or not _is_navigation():
26
35
  abort(401)
36
+ # Only a GET can be replayed after login: a form POST whose
37
+ # session expired would otherwise land on its URL as a GET.
38
+ if request.method != "GET":
39
+ return redirect(url_for_security("login"))
27
40
  # A path, not request.url: login only follows same-site paths.
28
41
  # request.path is decoded; quote it so "%23" stays in the path.
29
42
  target = quote(request.script_root + request.path)
@@ -498,6 +498,11 @@ async def login():
498
498
  # Every visit to the form replaces the target, so an abandoned one never
499
499
  # redirects a later login. The passkey and 2FA paths finish with it too.
500
500
  next_url = _safe_redirect_target(request.args.get("next"), fallback="")
501
+ # Like Devise and Flask-Security. The session cookie is SameSite, so a
502
+ # cross-site page cannot use this redirect to learn who is signed in.
503
+ if current_user.is_authenticated:
504
+ fallback = _resolve_redirect("SECURITY_POST_LOGIN_VIEW", "login")
505
+ return redirect(next_url or fallback)
501
506
  if next_url:
502
507
  session["security_next"] = [next_url, int(time.time())]
503
508
  else:
File without changes