From a80acc4d7f1cbd860135bdf2a61705a568ad6ecb Mon Sep 17 00:00:00 2001 From: Utkarsh Srivastava Date: Mon, 28 Oct 2024 15:19:39 +0530 Subject: [PATCH] add support for configurable max key length Signed-off-by: Utkarsh Srivastava add configurable for bucket name length Signed-off-by: Utkarsh Srivastava --- config.js | 16 ++++++++++++++++ src/endpoint/s3/s3_errors.js | 4 ++-- src/endpoint/s3/s3_rest.js | 8 ++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/config.js b/config.js index f404044cce..06c4d3d4c0 100644 --- a/config.js +++ b/config.js @@ -198,6 +198,22 @@ config.S3_RESTORE_REQUEST_MAX_DAYS = 30; */ config.S3_RESTORE_REQUEST_MAX_DAYS_BEHAVIOUR = 'TRUNCATE'; +/** + * S3_MAX_KEY_LENGTH controls the maximum key length that will be accepted + * by NooBaa endpoints. + * + * This value is 1024 bytes for S3 but the default is `Infinity` + */ +config.S3_MAX_KEY_LENGTH = Infinity; + +/** + * S3_MAX_BUCKET_NAME_LENGTH controls the maximum bucket name length that + * will be accepted by NooBaa endpoints. + * + * This value is 63 bytes for S3 but the default is `Infinity` + */ +config.S3_MAX_BUCKET_NAME_LENGTH = Infinity; + ///////////////////// // SECRETS CONFIG // ///////////////////// diff --git a/src/endpoint/s3/s3_errors.js b/src/endpoint/s3/s3_errors.js index 6a31359a98..fbed4e796a 100644 --- a/src/endpoint/s3/s3_errors.js +++ b/src/endpoint/s3/s3_errors.js @@ -249,8 +249,8 @@ S3Error.InvalidURI = Object.freeze({ message: 'Couldn\'t parse the specified URI.', http_code: 400, }); -S3Error.KeyTooLong = Object.freeze({ - code: 'KeyTooLong', +S3Error.KeyTooLongError = Object.freeze({ + code: 'KeyTooLongError', message: 'Your key is too long.', http_code: 400, }); diff --git a/src/endpoint/s3/s3_rest.js b/src/endpoint/s3/s3_rest.js index 7e9d34a889..78142fceee 100755 --- a/src/endpoint/s3/s3_rest.js +++ b/src/endpoint/s3/s3_rest.js @@ -362,6 +362,14 @@ function get_bucket_and_key(req) { key = suffix; } } + + if (key?.length > config.S3_MAX_KEY_LENGTH) { + throw new S3Error(S3Error.KeyTooLongError); + } + if (bucket?.length > config.S3_MAX_BUCKET_NAME_LENGTH) { + throw new S3Error(S3Error.InvalidBucketName); + } + return { bucket, // decode and replace hadoop _$folder$ in key