@@ -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,34 @@ 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+
1065+ const permittedPublicSearchParams = [ 'bucketId' , 'objectId' , 'public' , 'page' , 'limit' , 'sort' ] ;
1066+
1067+ // no-auth requests MUST have all of the following:
1068+ // (a) only the permitted search params; (b) ?public=true; (c) an object or bucket id
1069+ if ( ! hasOnlyPermittedKeys ( req . query , permittedPublicSearchParams ) || ! params . public ||
1070+ ! ( params . bucketId || params . id ) ) {
1071+ throw new Problem ( 403 , {
1072+ detail : 'User lacks permission to complete this action' ,
1073+ instance : req . originalUrl
1074+ } ) ;
1075+ }
1076+ }
10601077 params . userId = await userService . getCurrentUserId ( getCurrentIdentity ( req . currentUser , SYSTEM_USER ) ) ;
10611078 }
1079+
10621080 const response = await objectService . searchObjects ( params ) ;
1063- res . setHeader ( 'X-Total-Rows' , response . total ) . status ( 200 ) . json ( response . data ) ;
1081+
1082+ if ( req . currentUser . authType === AuthType . NONE ) {
1083+ const redactedFields = [ 'path' , 'createdBy' , 'updatedBy' , 'lastSyncedDate' ] ;
1084+ const redactedResponseData = response . data . map ( object => utils . redactSecrets ( object , redactedFields ) ) ;
1085+ res . setHeader ( 'X-Total-Rows' , response . total ) . status ( 200 ) . json ( redactedResponseData ) ;
1086+ }
1087+ else {
1088+ res . setHeader ( 'X-Total-Rows' , response . total ) . status ( 200 ) . json ( response . data ) ;
1089+ }
10641090 } catch ( error ) {
10651091 next ( error ) ;
10661092 }
0 commit comments