Bugzilla – Attachment 54471 Details for
Bug 17109
sendbasket: Remove second authentication, add CSRF token
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17109: Add CSRF token to [opac-]sendbasket
Bug-17109-Add-CSRF-token-to-opac-sendbasket.patch (text/plain), 8.08 KB, created by
Marc Véron
on 2016-08-15 13:05:52 UTC
(
hide
)
Description:
Bug 17109: Add CSRF token to [opac-]sendbasket
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2016-08-15 13:05:52 UTC
Size:
8.08 KB
patch
obsolete
>From c2d77ad76bae781418c624ef4c834ebfd2afd688 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 11 Aug 2016 14:17:14 +0200 >Subject: [PATCH] Bug 17109: Add CSRF token to [opac-]sendbasket >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >If you have no (valid) token, you will not be able to send the message. > >Test plan: >[1] Verify if you can still send the cart from opac and intranet. >[2] While still being logged in, try to send the cart from opac by > using the following URL: > /cgi-bin/koha/opac-sendbasket.pl?email_add=you@somedomain.com&comment=csrf_test&bib_list=doesnotmatter&csrf_token=justsomeguess12345 > This should now result in a csrf error. > >Signed-off-by: Marc Véron <veron@veron.ch> >--- > basket/sendbasket.pl | 25 +++++++++++++++++++--- > .../prog/en/modules/basket/sendbasketform.tt | 13 +++++++---- > .../bootstrap/en/modules/opac-sendbasketform.tt | 5 +++++ > opac/opac-sendbasket.pl | 25 +++++++++++++++++++--- > 4 files changed, 58 insertions(+), 10 deletions(-) > >diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl >index 16155d7..802ca33 100755 >--- a/basket/sendbasket.pl >+++ b/basket/sendbasket.pl >@@ -20,16 +20,18 @@ use Modern::Perl; > use CGI qw ( -utf8 ); > use Encode qw(encode); > use Carp; >- >+use Digest::MD5 qw(md5_base64); > use Mail::Sendmail; > use MIME::QuotedPrint; > use MIME::Base64; >+ > use C4::Biblio; > use C4::Items; > use C4::Auth; > use C4::Output; > use C4::Templates (); > use Koha::Email; >+use Koha::Token; > > my $query = new CGI; > >@@ -43,12 +45,24 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( > } > ); > >-my $bib_list = $query->param('bib_list'); >+my $bib_list = $query->param('bib_list') || ''; > my $email_add = $query->param('email_add'); > > my $dbh = C4::Context->dbh; > >+my $csrf_err; > if ( $email_add ) { >+ $csrf_err = 1 unless Koha::Token->new->check_csrf({ >+ id => C4::Context->userenv->{id}, >+ secret => md5_base64( C4::Context->config('pass') ), >+ token => scalar $query->param('csrf_token'), >+ }); >+} >+ >+if( $csrf_err ) { >+ $template->param( csrf_error => 1, email_add => 1 ); >+ output_html_with_http_headers $query, $cookie, $template->output; >+} elsif ( $email_add ) { > my $email = Koha::Email->new(); > my %mail = $email->create_message_headers({ to => $email_add }); > my $comment = $query->param('comment'); >@@ -165,11 +179,16 @@ END_OF_BODY > output_html_with_http_headers $query, $cookie, $template->output; > } > else { >- $template->param( bib_list => $bib_list ); > $template->param( >+ bib_list => $bib_list, > url => "/cgi-bin/koha/basket/sendbasket.pl", > suggestion => C4::Context->preference("suggestion"), > virtualshelves => C4::Context->preference("virtualshelves"), >+ csrf_token => Koha::Token->new->generate_csrf( >+ { id => C4::Context->userenv->{id}, >+ secret => md5_base64( C4::Context->config('pass') ), >+ } >+ ), > ); > output_html_with_http_headers $query, $cookie, $template->output; > } >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt >index ef116fc..07d004d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasketform.tt >@@ -10,6 +10,10 @@ > <p>The cart was sent to: [% email_add |html %]</p> > <p><a class="focus close" href="#">Close window</a></p> > [% END %] >+ [% IF csrf_error %] >+ <p>No valid CSRF token!</p> >+ <p><a class="focus close" href="#">Close window</a></p> >+ [% END %] > [% IF ( error ) %] > <p>Problem sending the cart...</p> > [% END %] >@@ -28,10 +32,11 @@ > <label for="comment">Comment:</label> > <textarea id="comment" name="comment" rows="4" cols="40"></textarea> > </li> >- <li> >- <input type="hidden" name="bib_list" value="[% bib_list %]" /> >- </li></ol></fieldset> >- <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset> >+ </ol> >+ </fieldset> >+ <fieldset class="action"> <input type="submit" value="Send" /> <a class="cancel close" href="#">Cancel</a> </fieldset> >+ <input type="hidden" name="bib_list" value="[% bib_list %]" /> >+ <input type="hidden" name="csrf_token" value="[% csrf_token %]" /> > </form> > > [% END %]</div> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt >index 25b248b..e1f8f60 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-sendbasketform.tt >@@ -19,6 +19,10 @@ > <p><a class="focus close" href="#">Close window</a></p> > [% END %] > >+ [% IF csrf_error %] >+ <p>No valid CSRF token!</p> >+ <p><a class="focus close" href="#">Close window</a></p> >+ [% END %] > [% IF ( error ) %] > <div class="alert"> > <p>There was an error sending the cart.</p> >@@ -34,6 +38,7 @@ > <label for="comment">Comment:</label> > <textarea id="comment" name="comment" rows="4" cols="40"></textarea> > <input type="hidden" name="bib_list" value="[% bib_list %]" /> >+ <input type="hidden" name="csrf_token" value="[% csrf_token %]" /> > </fieldset> > <fieldset class="action"> > <input type="submit" class="btn" value="Send" /> >diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl >index baa88b5..b1f6f3e 100755 >--- a/opac/opac-sendbasket.pl >+++ b/opac/opac-sendbasket.pl >@@ -22,10 +22,11 @@ use Modern::Perl; > use CGI qw ( -utf8 ); > use Encode qw(encode); > use Carp; >- >+use Digest::MD5 qw(md5_base64); > use Mail::Sendmail; > use MIME::QuotedPrint; > use MIME::Base64; >+ > use C4::Biblio; > use C4::Items; > use C4::Auth; >@@ -33,6 +34,7 @@ use C4::Output; > use C4::Members; > use C4::Templates (); > use Koha::Email; >+use Koha::Token; > > my $query = new CGI; > >@@ -45,12 +47,24 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( > } > ); > >-my $bib_list = $query->param('bib_list'); >+my $bib_list = $query->param('bib_list') || ''; > my $email_add = $query->param('email_add'); > > my $dbh = C4::Context->dbh; > >+my $csrf_err; > if ( $email_add ) { >+ $csrf_err = 1 unless Koha::Token->new->check_csrf({ >+ id => C4::Context->userenv->{id}, >+ secret => md5_base64( C4::Context->config('pass') ), >+ token => scalar $query->param('csrf_token'), >+ }); >+} >+ >+if( $csrf_err ) { >+ $template->param( csrf_error => 1, email_add => 1 ); >+ output_html_with_http_headers $query, $cookie, $template->output; >+} elsif ( $email_add ) { > my $email = Koha::Email->new(); > my $user = GetMember(borrowernumber => $borrowernumber); > my $user_email = GetFirstValidEmailAddress($borrowernumber) >@@ -185,11 +199,16 @@ END_OF_BODY > output_html_with_http_headers $query, $cookie, $template->output; > } > else { >- $template->param( bib_list => $bib_list ); > $template->param( >+ bib_list => $bib_list, > url => "/cgi-bin/koha/opac-sendbasket.pl", > suggestion => C4::Context->preference("suggestion"), > virtualshelves => C4::Context->preference("virtualshelves"), >+ csrf_token => Koha::Token->new->generate_csrf( >+ { id => C4::Context->userenv->{id}, >+ secret => md5_base64( C4::Context->config('pass') ), >+ } >+ ), > ); > output_html_with_http_headers $query, $cookie, $template->output; > } >-- >2.1.4
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 17109
:
54309
|
54310
|
54325
|
54470
|
54471
|
54472
|
54503
|
54705
|
54706
|
54707
|
54708