Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added restriction to limit the ID length to 255 characters in bucket lifecycle rules #8628

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/endpoint/s3/ops/s3_put_bucket_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const _ = require('lodash');
const s3_const = require('../s3_constants');
const { v4: uuid } = require('uuid');
const dbg = require('../../../util/debug_module')(__filename);
const S3Error = require('../s3_errors').S3Error;
Expand Down Expand Up @@ -88,7 +89,12 @@ async function put_bucket_lifecycle(req) {
};

if (rule.ID?.length === 1) {
current_rule.id = rule.ID[0];
if (rule.ID[0].length > s3_const.MAX_RULE_ID_LENGTH) {
dbg.error('Rule should not have ID length exceed allowed limit of ', s3_const.MAX_RULE_ID_LENGTH, ' characters', rule);
throw new S3Error({ ...S3Error.InvalidArgument, message: `ID length should not exceed allowed limit of ${s3_const.MAX_RULE_ID_LENGTH}` });
} else {
current_rule.id = rule.ID[0];
}
} else {
// Generate a random ID if missing
current_rule.id = uuid();
Expand Down
12 changes: 12 additions & 0 deletions src/endpoint/s3/s3_constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Copyright (C) 2016 NooBaa */
'use strict';

// `s3_const` serves as an alias for `exports` which expose constants related to s3 operations
// keeping name referencing consistent to s3_const.NAME for easier imports and searches
const s3_const = exports;

///////////////
// LIFECYCLE //
///////////////

s3_const.MAX_RULE_ID_LENGTH = 255;
16 changes: 16 additions & 0 deletions src/test/lifecycle/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const assert = require('assert');
const s3_const = require('../../endpoint/s3/s3_constants');

/*
* https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html
Expand Down Expand Up @@ -512,3 +513,18 @@ exports.test_and_prefix_size = async function(Bucket, Key, s3) {
assert(actualFilter.ObjectSizeGreaterThan === expectedFilter.ObjectSizeGreaterThan, 'and prefix size filter - ObjectSizeGreaterThan');
assert(actualFilter.ObjectSizeLessThan === expectedFilter.ObjectSizeLessThan, 'and prefix size filter - ObjectSizeLessThan');
};

exports.test_rule_id_length = async function(Bucket, Key, s3) {
const putLifecycleParams = id_lifecycle_configuration(Bucket, Key);

// set the ID to a value with more than 'MAX_RULE_ID_LENGTH' characters
const ID = 'A'.repeat(s3_const.MAX_RULE_ID_LENGTH + 5);
putLifecycleParams.LifecycleConfiguration.Rules[0].ID = ID;

try {
await s3.putBucketLifecycleConfiguration(putLifecycleParams);
assert.fail(`Expected error for ID length exceeding maximum allowed characters ${s3_const.MAX_RULE_ID_LENGTH}, but request was successful`);
} catch (error) {
assert(error.code === 'InvalidArgument', `Expected InvalidArgument: id length exceeding ${s3_const.MAX_RULE_ID_LENGTH} characters`);
}
};
1 change: 1 addition & 0 deletions src/test/system_tests/test_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function main() {
await commonTests.test_rule_id(Bucket, Key, s3);
await commonTests.test_filter_size(Bucket, s3);
await commonTests.test_and_prefix_size(Bucket, Key, s3);
await commonTests.test_rule_id_length(Bucket, Key, s3);

const getObjectParams = {
Bucket,
Expand Down
Loading