Skip to content

Commit a80acc4

Browse files
committed
add support for configurable max key length
Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com> add configurable for bucket name length Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>
1 parent 9dece0e commit a80acc4

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,22 @@ config.S3_RESTORE_REQUEST_MAX_DAYS = 30;
198198
*/
199199
config.S3_RESTORE_REQUEST_MAX_DAYS_BEHAVIOUR = 'TRUNCATE';
200200

201+
/**
202+
* S3_MAX_KEY_LENGTH controls the maximum key length that will be accepted
203+
* by NooBaa endpoints.
204+
*
205+
* This value is 1024 bytes for S3 but the default is `Infinity`
206+
*/
207+
config.S3_MAX_KEY_LENGTH = Infinity;
208+
209+
/**
210+
* S3_MAX_BUCKET_NAME_LENGTH controls the maximum bucket name length that
211+
* will be accepted by NooBaa endpoints.
212+
*
213+
* This value is 63 bytes for S3 but the default is `Infinity`
214+
*/
215+
config.S3_MAX_BUCKET_NAME_LENGTH = Infinity;
216+
201217
/////////////////////
202218
// SECRETS CONFIG //
203219
/////////////////////

src/endpoint/s3/s3_errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ S3Error.InvalidURI = Object.freeze({
249249
message: 'Couldn\'t parse the specified URI.',
250250
http_code: 400,
251251
});
252-
S3Error.KeyTooLong = Object.freeze({
253-
code: 'KeyTooLong',
252+
S3Error.KeyTooLongError = Object.freeze({
253+
code: 'KeyTooLongError',
254254
message: 'Your key is too long.',
255255
http_code: 400,
256256
});

src/endpoint/s3/s3_rest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,14 @@ function get_bucket_and_key(req) {
362362
key = suffix;
363363
}
364364
}
365+
366+
if (key?.length > config.S3_MAX_KEY_LENGTH) {
367+
throw new S3Error(S3Error.KeyTooLongError);
368+
}
369+
if (bucket?.length > config.S3_MAX_BUCKET_NAME_LENGTH) {
370+
throw new S3Error(S3Error.InvalidBucketName);
371+
}
372+
365373
return {
366374
bucket,
367375
// decode and replace hadoop _$folder$ in key

0 commit comments

Comments
 (0)