diff options
| author | Sean Reed <sean@sean-reed.com> | 2025-12-19 22:09:25 +0100 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-12-24 14:46:41 -0300 |
| commit | 165c3599965e63f88649a46fcc2ff681c52f2f66 (patch) | |
| tree | 43114e5fe32dd3d465f8fc618ef2b1fb5a5a89db /django/utils | |
| parent | 3923ebac28672ef4ebfbf2685fbc93206e6c136e (diff) | |
Refs #36810 -- Avoided infinite recursion in LazyNonce.__repr__().
Moved nonce generation in ``django.utils.csp.LazyNonce`` to a function
to avoid infinite recursion in ``SimpleLazyObject.__repr__`` for
unevaluated instances.
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/csp.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/django/utils/csp.py b/django/utils/csp.py index d57fc98995..08a9d0752e 100644 --- a/django/utils/csp.py +++ b/django/utils/csp.py @@ -71,15 +71,16 @@ class LazyNonce(SimpleLazyObject): """ def __init__(self): - super().__init__(self._generate) - - def _generate(self): - return secrets.token_urlsafe(16) + super().__init__(generate_nonce) def __bool__(self): return self._wrapped is not empty +def generate_nonce(): + return secrets.token_urlsafe(16) + + def build_policy(config, nonce=None): policy = [] |
