Bugzilla – Attachment 172441 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: REST - Remove allow-owner from public article requests cancel route
Bug-28907-REST---Remove-allow-owner-from-public-ar.patch (text/plain), 4.21 KB, created by
Victor Grousset/tuxayo
on 2024-10-07 01:06:49 UTC
(
hide
)
Description:
Bug 28907: REST - Remove allow-owner from public article requests cancel route
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2024-10-07 01:06:49 UTC
Size:
4.21 KB
patch
obsolete
>From 2cbe2bd17316ebb3e57e3da424e8dc8c83f25592 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Wed, 18 Sep 2024 11:21:30 +0000 >Subject: [PATCH] Bug 28907: REST - Remove allow-owner from public article > requests cancel route > >To test: >1. prove t/db_dependent/api/v1/article_requests.t >2. Apply patch >3. prove t/db_dependent/api/v1/article_requests.t > >Observe success in both cases. > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >--- > Koha/REST/V1/ArticleRequests.pm | 25 +++++++++++----------- > api/v1/swagger/paths/article_requests.yaml | 2 -- > t/db_dependent/api/v1/article_requests.t | 8 +++++-- > 3 files changed, 19 insertions(+), 16 deletions(-) > >diff --git a/Koha/REST/V1/ArticleRequests.pm b/Koha/REST/V1/ArticleRequests.pm >index 9bc0c5a58b..64645790da 100644 >--- a/Koha/REST/V1/ArticleRequests.pm >+++ b/Koha/REST/V1/ArticleRequests.pm >@@ -73,22 +73,23 @@ Controller function that handles cancelling a patron's Koha::ArticleRequest obje > sub patron_cancel { > my $c = shift->openapi->valid_input or return; > >- my $patron = Koha::Patrons->find( $c->param('patron_id') ); >+ my $patron_id = $c->param('patron_id'); >+ return try { >+ $c->auth->public($patron_id); >+ my $patron = Koha::Patrons->find($patron_id); > >- return $c->render_resource_not_found("Patron") >- unless $patron; >+ return $c->render_resource_not_found("Patron") >+ unless $patron; > >- # patron_id has been validated by the allow-owner check, so the following call to related >- # article requests covers the case of article requests not belonging to the patron >- my $article_request = $patron->article_requests->find( $c->param('article_request_id') ); >+ # patron_id has been validated by the $c->auth->public check, so the following call to related >+ # article requests covers the case of article requests not belonging to the patron >+ my $article_request = $patron->article_requests->find( $c->param('article_request_id') ); > >- return $c->render_resource_not_found("Article request") >- unless $article_request; >+ return $c->render_resource_not_found("Article request") >+ unless $article_request; > >- my $reason = $c->param('cancellation_reason'); >- my $notes = $c->param('notes'); >- >- return try { >+ my $reason = $c->param('cancellation_reason'); >+ my $notes = $c->param('notes'); > > $article_request->cancel( > { >diff --git a/api/v1/swagger/paths/article_requests.yaml b/api/v1/swagger/paths/article_requests.yaml >index d0fc698557..d3413243f1 100644 >--- a/api/v1/swagger/paths/article_requests.yaml >+++ b/api/v1/swagger/paths/article_requests.yaml >@@ -113,5 +113,3 @@ > description: Under maintenance > schema: > $ref: "../swagger.yaml#/definitions/error" >- x-koha-authorization: >- allow-owner: true >diff --git a/t/db_dependent/api/v1/article_requests.t b/t/db_dependent/api/v1/article_requests.t >index 6e43ffd625..f32e96adb3 100755 >--- a/t/db_dependent/api/v1/article_requests.t >+++ b/t/db_dependent/api/v1/article_requests.t >@@ -84,7 +84,7 @@ subtest 'cancel() tests' => sub { > > subtest 'patron_cancel() tests' => sub { > >- plan tests => 14; >+ plan tests => 17; > > t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 ); > t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >@@ -116,10 +116,14 @@ subtest 'patron_cancel() tests' => sub { > > my $article_request_2 = $builder->build_object({ class => 'Koha::ArticleRequests', value => { borrowernumber => $another_patron_id } }); > >+ # delete another patron's request when unauthorized >+ $t->delete_ok( "/api/v1/public/patrons/$another_patron_id/article_requests/" . $article_request_2->id ) >+ ->status_is(401)->json_is( '/error' => "Authentication failure." ); >+ > # delete another patron's request > $t->delete_ok("//$userid:$password@/api/v1/public/patrons/$another_patron_id/article_requests/" . $article_request_2->id) > ->status_is(403) >- ->json_is( '/error' => 'Authorization failure. Missing required permission(s).' ); >+ ->json_is( '/error' => "Unprivileged user cannot access another user's resources" ); > > my $another_article_request = $builder->build_object( > { >-- >2.46.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 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