@@ -3,6 +3,7 @@ const cors = require('cors');
33const { v4 : uuidv4 , NIL : SYSTEM_USER } = require ( 'uuid' ) ;
44
55const {
6+ AuthType,
67 DEFAULTCORS ,
78 DownloadMode,
89 MAXCOPYOBJECTLENGTH ,
@@ -26,7 +27,8 @@ const {
2627 mixedQueryToArray,
2728 toLowerKeys,
2829 getBucket,
29- renameObjectProperty
30+ renameObjectProperty,
31+ hasOnlyPermittedKeys
3032} = require ( '../components/utils' ) ;
3133const utils = require ( '../db/models/utils' ) ;
3234
@@ -1057,10 +1059,30 @@ const controller = {
10571059 } ;
10581060 // if scoping to current user permissions on objects
10591061 if ( getConfigBoolean ( 'server.privacyMask' ) ) {
1062+
1063+ if ( req . currentUser . authType === AuthType . NONE ) {
1064+ const permittedPublicSearchParams = [ 'bucketId' , 'objectId' , 'public' , 'page' , 'limit' , 'sort' ] ;
1065+
1066+ if ( ! hasOnlyPermittedKeys ( req . query , permittedPublicSearchParams ) || ! params . public ) {
1067+ throw new Problem ( 403 , {
1068+ detail : 'User lacks permission to complete this action' ,
1069+ instance : req . originalUrl
1070+ } ) ;
1071+ }
1072+ }
10601073 params . userId = await userService . getCurrentUserId ( getCurrentIdentity ( req . currentUser , SYSTEM_USER ) ) ;
10611074 }
1075+
10621076 const response = await objectService . searchObjects ( params ) ;
1063- res . setHeader ( 'X-Total-Rows' , response . total ) . status ( 200 ) . json ( response . data ) ;
1077+ const redactedFields = [ 'createdBy' , 'updatedBy' , 'lastSyncedDate' ] ;
1078+
1079+ if ( req . currentUser . authType === AuthType . NONE ) {
1080+ const redactedResponseData = response . data . map ( object => utils . redactSecrets ( object , redactedFields ) ) ;
1081+ res . setHeader ( 'X-Total-Rows' , response . total ) . status ( 200 ) . json ( redactedResponseData ) ;
1082+ }
1083+ else {
1084+ res . setHeader ( 'X-Total-Rows' , response . total ) . status ( 200 ) . json ( response . data ) ;
1085+ }
10641086 } catch ( error ) {
10651087 next ( error ) ;
10661088 }
0 commit comments