From 1d5309bdc20886a48a12cd0b20406d4345fbac99 Mon Sep 17 00:00:00 2001 From: Aayush Chouhan Date: Thu, 26 Dec 2024 22:10:05 +0530 Subject: [PATCH] Added a check for duplicate Id in bucket lifecycle rules Signed-off-by: Aayush Chouhan --- src/endpoint/s3/ops/s3_put_bucket_lifecycle.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/endpoint/s3/ops/s3_put_bucket_lifecycle.js b/src/endpoint/s3/ops/s3_put_bucket_lifecycle.js index b54024cc4f..68f7cac640 100644 --- a/src/endpoint/s3/ops/s3_put_bucket_lifecycle.js +++ b/src/endpoint/s3/ops/s3_put_bucket_lifecycle.js @@ -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: {}, @@ -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);