Skip to content

Commit 236f5cb

Browse files
added 20kb limit for put bucket policy
Issue : CLDSRV-700
1 parent c0b1d0c commit 236f5cb

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,9 @@
142142
},
143143
"kmip": {
144144
"providerName": "thales"
145+
},
146+
"apisLengthLimits": {
147+
"multiObjectDelete": 2097152,
148+
"bucketPutPolicy": 20480
145149
}
146150
}

constants.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ const constants = {
9696
oneMegaBytes: 1024 * 1024,
9797
halfMegaBytes: 512 * 1024,
9898

99-
// Some apis may need a custom body length limit :
100-
apisLengthLimits: {
99+
// Some apis may need a custom body length limit
100+
defaultApisLengthLimits: {
101101
// Multi Objects Delete request can be large : up to 1000 keys of 1024 bytes is
102102
// already 1mb, with the other fields it could reach 2mb
103103
'multiObjectDelete': 2 * 1024 * 1024,
104+
// AWS sets the maximum size for bucket policies to 20 KB
105+
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/add-bucket-policy.html
106+
'bucketPutPolicy': 20 * 1024,
104107
},
105108

106109
// hex digest of sha256 hash of empty string:
@@ -266,5 +269,4 @@ const constants = {
266269
onlyOwnerAllowed: ['bucketDeletePolicy', 'bucketGetPolicy', 'bucketPutPolicy'],
267270
};
268271

269-
270272
module.exports = constants;

lib/Config.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,23 @@ class Config extends EventEmitter {
16981698
}
16991699

17001700
this.supportedLifecycleRules = parseSupportedLifecycleRules(config.supportedLifecycleRules);
1701+
1702+
this.apisLengthLimits = { ...constants.defaultApisLengthLimits };
1703+
// If a value is provided in the config, it overwrites the default constant
1704+
if (config.apisLengthLimits) {
1705+
assert(typeof config.apisLengthLimits === 'object' &&
1706+
config.apisLengthLimits !== null &&
1707+
!Array.isArray(config.apisLengthLimits),
1708+
'bad config: apisLengthLimits must be an object');
1709+
1710+
for (const [apiKey, limit] of Object.entries(config.apisLengthLimits)) {
1711+
assert(Number.isInteger(limit) && limit > 0,
1712+
`bad config: apisLengthLimits for "${apiKey}" must be a positive integer`);
1713+
// Overwrite the default limit with the configured one.
1714+
this.apisLengthLimits[apiKey] = limit;
1715+
}
1716+
}
1717+
17011718
return config;
17021719
}
17031720

lib/api/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const { tagConditionKeyAuth } = require('./apiUtils/authorization/tagConditionKe
7575
const { isRequesterASessionUser } = require('./apiUtils/authorization/permissionChecks');
7676
const checkHttpHeadersSize = require('./apiUtils/object/checkHttpHeadersSize');
7777
const constants = require('../../constants');
78+
const { config } = require('../Config.js');
7879

7980
const monitoringMap = policies.actionMaps.actionMonitoringMapS3;
8081

@@ -223,7 +224,7 @@ const api = {
223224

224225
const defaultMaxPostLength = request.method === 'POST' ?
225226
constants.oneMegaBytes : constants.halfMegaBytes;
226-
const MAX_POST_LENGTH = constants.apisLengthLimits[apiMethod] || defaultMaxPostLength;
227+
const MAX_POST_LENGTH = config.apisLengthLimits[apiMethod] || defaultMaxPostLength;
227228
const post = [];
228229
let postLength = 0;
229230
request.on('data', chunk => {

0 commit comments

Comments
 (0)