Bugzilla – Attachment 179000 Details for
Bug 28907
Potential unauthorized access in public REST routes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28907: [With corrected bug id] REST - Remove allow-owner from public password route
Bug-28907-With-corrected-bug-id-REST---Remove-allo.patch (text/plain), 5.27 KB, created by
Paul Derscheid
on 2025-03-05 17:31:34 UTC
(
hide
)
Description:
Bug 28907: [With corrected bug id] REST - Remove allow-owner from public password route
Filename:
MIME Type:
Creator:
Paul Derscheid
Created:
2025-03-05 17:31:34 UTC
Size:
5.27 KB
patch
obsolete
>From 9f9bc2299e11ff81ee64305559132c5e4278f340 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Wed, 18 Sep 2024 08:39:48 +0000 >Subject: [PATCH] Bug 28907: [With corrected bug id] REST - Remove allow-owner > from public password route > >To test: >1. prove t/db_dependent/api/v1/patrons_password.t >2. Apply patch >3. prove t/db_dependent/api/v1/patrons_password.t > >Observe success in both cases. > >https://bugs.koha-community.org/show_bug.cgi?id=28907 >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/REST/V1/Patrons/Password.pm | 39 +++++++++++------------- > api/v1/swagger/paths/public_patrons.yaml | 2 -- > t/db_dependent/api/v1/patrons_password.t | 23 ++++++++++---- > 3 files changed, 35 insertions(+), 29 deletions(-) > >diff --git a/Koha/REST/V1/Patrons/Password.pm b/Koha/REST/V1/Patrons/Password.pm >index 1c117d0d64..a6c69d4fe7 100644 >--- a/Koha/REST/V1/Patrons/Password.pm >+++ b/Koha/REST/V1/Patrons/Password.pm >@@ -90,29 +90,24 @@ sub set_public { > > my $user = $c->stash('koha.user'); > >- unless ( $user->borrowernumber == $patron_id ) { >- return $c->render( >- status => 403, >- openapi => { error => "Changing other patron's password is forbidden" } >- ); >- } >+ return try { >+ $c->auth->public($patron_id); > >- unless ( $user->category->effective_change_password ) { >- return $c->render( >- status => 403, >- openapi => { error => "Changing password is forbidden" } >- ); >- } >+ unless ( $user->category->effective_change_password ) { >+ return $c->render( >+ status => 403, >+ openapi => { error => "Changing password is forbidden" } >+ ); >+ } > >- my $old_password = $body->{old_password}; >- my $password = $body->{password}; >- my $password_2 = $body->{password_repeated}; >+ my $old_password = $body->{old_password}; >+ my $password = $body->{password}; >+ my $password_2 = $body->{password_repeated}; > >- unless ( $password eq $password_2 ) { >- return $c->render( status => 400, openapi => { error => "Passwords don't match" } ); >- } >+ unless ( $password eq $password_2 ) { >+ return $c->render( status => 400, openapi => { error => "Passwords don't match" } ); >+ } > >- return try { > unless ( checkpw_internal( $user->userid, $old_password ) ) { > return $c->render( > status => 400, >@@ -130,9 +125,11 @@ sub set_public { > status => 400, > openapi => { error => "$_" } > ); >+ } elsif ( blessed $_ and $_->isa('Koha::Exceptions::REST::Public::Unauthorized') ) { >+ return $c->render( status => 403, json => { error => "Changing other patron's password is forbidden" } ); >+ } else { >+ $c->unhandled_exception($_); > } >- >- $c->unhandled_exception($_); > }; > } > >diff --git a/api/v1/swagger/paths/public_patrons.yaml b/api/v1/swagger/paths/public_patrons.yaml >index 2f2526e827..9a987ee0ed 100644 >--- a/api/v1/swagger/paths/public_patrons.yaml >+++ b/api/v1/swagger/paths/public_patrons.yaml >@@ -60,8 +60,6 @@ > description: Under maintenance > schema: > $ref: "../swagger.yaml#/definitions/error" >- x-koha-authorization: >- allow-owner: true > "/public/patrons/{patron_id}/checkouts": > post: > x-mojo-to: Checkouts#add >diff --git a/t/db_dependent/api/v1/patrons_password.t b/t/db_dependent/api/v1/patrons_password.t >index 1551a36150..e9886932bf 100755 >--- a/t/db_dependent/api/v1/patrons_password.t >+++ b/t/db_dependent/api/v1/patrons_password.t >@@ -102,7 +102,7 @@ subtest 'set() (authorized user tests)' => sub { > > subtest 'set_public() (unprivileged user tests)' => sub { > >- plan tests => 18; >+ plan tests => 21; > > $schema->storage->txn_begin; > >@@ -141,19 +141,30 @@ subtest 'set_public() (unprivileged user tests)' => sub { > } > )->status_is(403)->json_is( { error => 'Changing password is forbidden' } ); > >- t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 ); >- > $t->post_ok( >- "//$userid:$password@/api/v1/public/patrons/" . $other_patron->id . "/password" => json => { >+ "/api/v1/public/patrons/" . $patron->id . "/password" => json => { > password => $new_password, > password_repeated => $new_password, > old_password => $password > } >- )->status_is(403)->json_is( >+ )->status_is(401)->json_is( > '/error', >- "Authorization failure. Missing required permission(s)." >+ "Authentication failure." > ); > >+ >+ t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 ); >+ >+ $t->post_ok( >+ "//$userid:$password@/api/v1/public/patrons/" . $other_patron->id . "/password" => json => { >+ password => $new_password, >+ password_repeated => $new_password, >+ old_password => $password >+ } >+ )->status_is(403) >+ ->json_is( '/error', >+ "Changing other patron's password is forbidden" ); >+ > $t->post_ok( > "//$userid:$password@/api/v1/public/patrons/" . $patron->id . "/password" => json => { > password => $new_password, >-- >2.48.1
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 28907
:
171666
|
171667
|
171668
|
171669
|
171670
|
171671
|
171672
|
171673
|
171674
|
172434
|
172435
|
172436
|
172437
|
172438
|
172439
|
172440
|
172441
|
172442
|
174662
|
174663
|
174664
|
174665
|
174666
|
174667
|
174668
|
174669
|
174670
|
176708
|
176709
|
176710
|
176711
|
176712
|
176713
|
176714
|
176715
|
176716
|
177679
|
177680
|
177681
|
177682
|
177683
|
177684
|
177685
|
177686
|
177687
|
179000