fix(csrf): centraliser l'injection des tokens CSRF via un dcc.Store et un callback pattern-matching
Remplace les 7 callbacks CSRF individuels (un par formulaire, avec IDs string
page-spécifiques) par un seul dcc.Store(id="csrf-token") dans le layout principal
et un callback pattern-matching Output({"type": "csrf-input", "index": ALL}).
Évite les erreurs Dash "id non trouvé dans le layout" sans recourir à
suppress_callback_exceptions=True.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import dash_bootstrap_components as dbc
|
||||
from dash import Input, Output, callback, dcc, html, register_page
|
||||
from flask_wtf.csrf import generate_csrf
|
||||
from dash import dcc, html, register_page
|
||||
|
||||
NAME = "Inscription"
|
||||
|
||||
@@ -36,7 +35,11 @@ def layout(error: str | None = None, email: str | None = None, **_):
|
||||
method="POST",
|
||||
action="/auth/signup",
|
||||
children=[
|
||||
dcc.Input(type="hidden", id="csrf-signup", name="csrf_token"),
|
||||
dcc.Input(
|
||||
type="hidden",
|
||||
id={"type": "csrf-input", "index": "signup"},
|
||||
name="csrf_token",
|
||||
),
|
||||
dbc.Label("Adresse email"),
|
||||
dbc.Input(
|
||||
type="email",
|
||||
@@ -68,8 +71,3 @@ def layout(error: str | None = None, email: str | None = None, **_):
|
||||
dcc.Link("Déjà un compte ? Se connecter", href="/connexion"),
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@callback(Output("csrf-signup", "value"), Input("csrf-signup", "id"))
|
||||
def _fill_csrf(_):
|
||||
return generate_csrf()
|
||||
|
||||
Reference in New Issue
Block a user