Skip to content

Commit

Permalink
Merge pull request #8484 from tangledbytes/utkarsh/feat/limit-key-length
Browse files Browse the repository at this point in the history
  • Loading branch information
guymguym authored Oct 31, 2024
2 parents 9dece0e + a80acc4 commit aef68ca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 //
/////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/endpoint/s3/s3_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
8 changes: 8 additions & 0 deletions src/endpoint/s3/s3_rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aef68ca

Please sign in to comment.