Bugzilla – Attachment 156949 Details for
Bug 29523
Add a way to prevent embedding objects that should not be allowed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29523: Add redaction for inaccessible objects
Bug-29523-Add-redaction-for-inaccessible-objects.patch (text/plain), 3.94 KB, created by
Martin Renvoize (ashimema)
on 2023-10-12 10:52:58 UTC
(
hide
)
Description:
Bug 29523: Add redaction for inaccessible objects
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2023-10-12 10:52:58 UTC
Size:
3.94 KB
patch
obsolete
>From 5e6e322bb102296b84c45919513efd56fc238e62 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 31 Aug 2023 14:13:54 +0200 >Subject: [PATCH] Bug 29523: Add redaction for inaccessible objects > >This patch switches from removing inaccessible items from the responses >to instead redacting all the core fields in innaccessible responses. > >This allows for embed traversal and keeps counts etc correct but also >hides the data we want to hide. >--- > Koha/Object.pm | 17 ++++++++++++++++- > Koha/Patron.pm | 2 +- > t/db_dependent/Koha/Object.t | 5 ++--- > 3 files changed, 19 insertions(+), 5 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index c05a923cfee..529ec503436 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -406,6 +406,10 @@ sub TO_JSON { > and looks_like_number( $unblessed->{$col} ) > ) { > >+ if ( $self->{_redact} ) { >+ $unblessed->{$col} = 0; >+ } >+ > # TODO: Remove once the solution for > # https://github.com/perl5-dbi/DBD-mysql/issues/212 > # is ported to whatever distro we support by that time >@@ -415,6 +419,9 @@ sub TO_JSON { > elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} ) > and looks_like_number( $unblessed->{$col} ) > ) { >+ if ( $self->{_redact} ) { >+ $unblessed->{$col} = 0.00; >+ } > > # TODO: Remove once the solution for > # https://github.com/perl5-dbi/DBD-mysql/issues/212 >@@ -423,6 +430,9 @@ sub TO_JSON { > $unblessed->{$col} += 0.00; > } > elsif ( _datetime_column_type( $columns_info->{$col}->{data_type} ) ) { >+ if ( $self->{_redact} ) { >+ $unblessed->{$col} = "0000-01-01 00:00:01"; >+ } > eval { > return unless $unblessed->{$col}; > $unblessed->{$col} = output_pref({ >@@ -431,6 +441,9 @@ sub TO_JSON { > }); > }; > } >+ elsif ( $self->{_redact} ) { >+ $unblessed->{$col} = '*****'; >+ } > } > return $unblessed; > } >@@ -552,7 +565,9 @@ Returns a representation of the object, suitable for API output. > sub to_api { > my ( $self, $params ) = @_; > >- return unless $self->is_accessible($params); >+ unless ( $self->is_accessible($params) ) { >+ $self->{_redact} = 1; >+ } > > my $json_object = $self->TO_JSON; > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 0bffc050241..2006ad5087f 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -2289,7 +2289,7 @@ sub set_default_messaging_preferences { > > if ( $patron->is_accessible({ user => $logged_in_user }) ) { ... } > >-This overloaded method validates wether the current I<Koha::Patron> object can be accessed >+This overloaded method validates whether the current I<Koha::Patron> object can be accessed > by the logged in user. > > Returns 0 if the I<user> parameter is missing. >diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t >index ba1b82de5ef..cd1425983e3 100755 >--- a/t/db_dependent/Koha/Object.t >+++ b/t/db_dependent/Koha/Object.t >@@ -555,7 +555,6 @@ subtest "to_api() tests" => sub { > } > ); > >- > my $patron_1 = $builder->build_object( > { class => 'Koha::Patrons', value => { branchcode => $library_1->id } } > ); >@@ -565,8 +564,8 @@ subtest "to_api() tests" => sub { > > t::lib::Mocks::mock_userenv( { patron => $patron } ); > >- is( ref($patron_1->to_api({ user => $patron })), 'HASH', 'Returns the object hash' ); >- is( $patron_2->to_api({ user => $patron }), undef, 'Not accessible, returns undef' ); >+ is( $patron_1->to_api({ user => $patron })->{firstname}, $patron_1->firstname, 'Returns unredacted object hash' ); >+ is( $patron_2->to_api({ user => $patron })->{firstname}, "*****", 'Returns redacted object hash' ); > > $schema->storage->txn_rollback; > }; >-- >2.41.0
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 29523
:
127886
|
127887
|
127888
|
127889
|
127991
|
127992
|
127993
|
127994
|
128042
|
128043
|
128044
|
128045
|
128046
|
128047
|
128048
|
128688
|
128689
|
128690
|
128691
|
128692
|
128693
|
128694
|
131326
|
131331
|
131332
|
136684
|
136685
|
136686
|
136687
|
136688
|
136689
|
136690
|
136691
|
136692
|
136706
|
136714
|
148736
|
148737
|
148738
|
148739
|
148740
|
148741
|
148742
|
148743
|
148744
|
148745
|
150989
|
150990
|
150991
|
150992
|
150993
|
150994
|
150995
|
150996
|
150997
|
150998
|
156939
|
156940
|
156941
|
156942
|
156943
|
156944
|
156945
|
156946
|
156947
|
156948
|
156949
|
156965
|
157049
|
157071
|
157072
|
157073
|
157074
|
157075
|
157076
|
157077
|
157078
|
157079
|
157080
|
157081
|
157406
|
157407
|
157408
|
157409
|
157410
|
157411
|
157412
|
157413
|
157414
|
157415
|
157416
|
157673
|
157679
|
157683
|
157799
|
157881
|
157882
|
157883
|
157884
|
157885
|
157886
|
157887
|
157888
|
157889
|
157890
|
157891
|
157892
|
157893
|
158013