Skip to content

Commit

Permalink
Added a check for duplicate Id in bucket lifecycle rules
Browse files Browse the repository at this point in the history
Signed-off-by: Aayush Chouhan <[email protected]>
  • Loading branch information
achouhan09 committed Dec 26, 2024
1 parent 23f533d commit 1d5309b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/endpoint/s3/ops/s3_put_bucket_lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function parse_lifecycle_field(field, field_parser = parseInt) {
* http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTlifecycle.html
*/
async function put_bucket_lifecycle(req) {
const id_set = new Set();
const lifecycle_rules = _.map(req.body.LifecycleConfiguration.Rule, rule => {
const current_rule = {
filter: {},
Expand All @@ -94,6 +95,13 @@ async function put_bucket_lifecycle(req) {
current_rule.id = uuid();
}

// Check for duplicate ID in the rules
if (id_set.has(current_rule.id)) {
dbg.error('Rules should not have duplicate IDs. Duplicate ID found: ', current_rule.id);
throw new S3Error(S3Error.InvalidArgument);
}
id_set.add(current_rule.id);

if (rule.Status?.length !== 1) {
dbg.error('Rule should have status', rule);
throw new S3Error(S3Error.InvalidArgument);
Expand Down

0 comments on commit 1d5309b

Please sign in to comment.