Skip to content

Commit 6ef4e38

Browse files
added 20kb limit for put bucket policy
Issue : CLDSRV-700
1 parent a283aa0 commit 6ef4e38

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ const constants = {
8989
// Maximum HTTP headers size allowed
9090
maxHttpHeadersSize: 14122,
9191

92+
// AWS sets the maximum size for bucket policies to 20 KB
93+
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/add-bucket-policy.html
94+
bucketPolicyMaxBytesSize: 20480,
95+
96+
9297
// hex digest of sha256 hash of empty string:
9398
emptyStringHash: crypto.createHash('sha256')
9499
.update('', 'binary').digest('hex'),

lib/api/bucketPutPolicy.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const metadata = require('../metadata/wrapper');
55
const { standardMetadataValidateBucket } = require('../metadata/metadataUtils');
66
const { validatePolicyResource, validatePolicyConditions } =
77
require('./apiUtils/authorization/permissionChecks');
8+
const constants = require('../../constants');
89
const { BucketPolicy } = models;
910

1011
/**
@@ -31,6 +32,14 @@ function _checkNotImplementedPolicy(policyString) {
3132
function bucketPutPolicy(authInfo, request, log, callback) {
3233
log.debug('processing request', { method: 'bucketPutPolicy' });
3334

35+
if (request.post && request.post.length > constants.bucketPolicyMaxBytesSize) {
36+
return callback(errorInstances.MalformedPolicy.customizeDescription(
37+
`The provided Bucket Policy is too large : ${request.post.length} bytes. ` +
38+
`The AWS standard allows 20KB maximum. ` +
39+
`Our current limit is set at ${constants.bucketPolicyMaxBytesSize} bytes. `
40+
));
41+
}
42+
3443
const { bucketName } = request;
3544
const metadataValParams = {
3645
authInfo,

0 commit comments

Comments
 (0)