Bugzilla – Attachment 162511 Details for
Bug 35955
New CSRF token generated everytime we need one
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35955: Cache CSRF token in template plugin
Bug-35955-Cache-CSRF-token-in-template-plugin.patch (text/plain), 1.62 KB, created by
Nick Clemens (kidclamp)
on 2024-02-27 15:25:46 UTC
(
hide
)
Description:
Bug 35955: Cache CSRF token in template plugin
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-02-27 15:25:46 UTC
Size:
1.62 KB
patch
obsolete
>From 23d249e759c9e99d4808e5aa5fa9067cd980eb4c Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Tue, 27 Feb 2024 06:05:24 +0000 >Subject: [PATCH] Bug 35955: Cache CSRF token in template plugin > >This change uses the Koha::Cache::Memory::Lite cache to >cache the CSRF token, so that it is only generated once, >and is re-used by the Koha::Template::Plugin::Koha object >throughout the entire template processing for the HTTP request. > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/Template/Plugin/Koha.pm | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > >diff --git a/Koha/Template/Plugin/Koha.pm b/Koha/Template/Plugin/Koha.pm >index ec5f975eb74..55671d2199d 100644 >--- a/Koha/Template/Plugin/Koha.pm >+++ b/Koha/Template/Plugin/Koha.pm >@@ -24,6 +24,7 @@ use base qw( Template::Plugin ); > use C4::Context; > use Koha::Token; > use Koha; >+use Koha::Cache::Memory::Lite; > > =head1 NAME > >@@ -107,8 +108,16 @@ Generate a new CSRF token. > > sub GenerateCSRF { > my ($self) = @_; >+ >+ my $memory_cache = Koha::Cache::Memory::Lite->get_instance; >+ my $cache_key = "CSRF_TOKEN"; >+ my $cached = $memory_cache->get_from_cache($cache_key); >+ return $cached if $cached; >+ > my $session_id = $self->{_CONTEXT}->stash->{sessionID}; >- return Koha::Token->new->generate_csrf( { session_id => scalar $session_id } ); >+ my $csrf_token = Koha::Token->new->generate_csrf( { session_id => scalar $session_id } ); >+ $memory_cache->set_in_cache( $cache_key, $csrf_token ); >+ return $csrf_token; > } > > 1; >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35955
:
162485
|
162486
| 162511 |
162512