-
Notifications
You must be signed in to change notification settings - Fork 867
S3 DeleteObjects Key Validation Fix #3832
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
generator/.DevConfigs/a5cb7525-8e50-4583-ae7b-36180442d7e3.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"services": [ | ||
{ | ||
"serviceName": "S3", | ||
"type": "patch", | ||
"changeLogMessages": [ | ||
"Fixed a bug in DeleteObjects where valid objects would not be deleted when the request included invalid keys" | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
|
@@ -20,6 +20,7 @@ | |
|
||
using Amazon.Runtime; | ||
using Amazon.Runtime.Internal; | ||
using Amazon.Runtime.Internal.Util; | ||
|
||
namespace Amazon.S3.Model | ||
{ | ||
|
@@ -30,13 +31,69 @@ namespace Amazon.S3.Model | |
/// </summary> | ||
public partial class DeleteObjectsRequest : AmazonWebServiceRequest | ||
{ | ||
private List<DeleteError> validationErrors; | ||
|
||
/// <summary> | ||
/// Gets the list of keys that were skipped during client-side validation. | ||
/// </summary> | ||
public List<DeleteError> ValidationErrors | ||
{ | ||
get | ||
{ | ||
if (validationErrors == null) | ||
{ | ||
validationErrors = new List<DeleteError>(); | ||
} | ||
return validationErrors; | ||
} | ||
} | ||
|
||
private static Logger Logger | ||
{ | ||
get | ||
{ | ||
return Logger.GetLogger(typeof(DeleteObjectsRequest)); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Add a key to the set of keys of objects to be deleted. | ||
/// </summary> | ||
/// <param name="key">Object key</param> | ||
/// <remarks> | ||
/// Invalid keys (null, empty, or longer than 1024 characters) are skipped with an INFO-level log message. | ||
/// These validation errors are also tracked in the ValidationErrors collection. | ||
/// This allows the DeleteObjects operation to proceed with valid keys even when some keys are invalid. | ||
/// </remarks> | ||
public void AddKey(string key) | ||
{ | ||
// Skip invalid keys instead of throwing exceptions | ||
// This allows the DeleteObjects operation to proceed with valid keys | ||
if (string.IsNullOrEmpty(key)) | ||
{ | ||
string message = "Skipping null or empty key in DeleteObjects request"; | ||
Logger.InfoFormat(message); | ||
|
||
ValidationErrors.Add(new DeleteError { | ||
Key = key ?? "(null)", | ||
Code = "InvalidKey", | ||
Message = "Key cannot be null or empty" | ||
}); | ||
return; | ||
} | ||
if (key.Length > 1024) | ||
{ | ||
string message = string.Format("Skipping key in DeleteObjects request: key length {0} exceeds maximum of 1024 characters", key.Length); | ||
Logger.InfoFormat(message); | ||
|
||
ValidationErrors.Add(new DeleteError { | ||
Key = key.Substring(0, Math.Min(key.Length, 128)) + (key.Length > 128 ? "..." : ""), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Min here is not truly required, also does it make sense to trim it it 128 when 1024 length is legit it can be issue when you have common prefix of 128 chars length |
||
Code = "KeyTooLongError", | ||
Message = string.Format("Key length {0} exceeds maximum of 1024 characters", key.Length) | ||
}); | ||
return; | ||
} | ||
|
||
AddKey(new KeyVersion { Key = key }); | ||
} | ||
|
||
|
@@ -45,8 +102,40 @@ public void AddKey(string key) | |
/// </summary> | ||
/// <param name="key">Key of the object to be deleted.</param> | ||
/// <param name="version">Version of the object to be deleted.</param> | ||
/// <remarks> | ||
/// Invalid keys (null, empty, or longer than 1024 characters) are skipped with an INFO-level log message. | ||
/// These validation errors are also tracked in the ValidationErrors collection. | ||
/// This allows the DeleteObjects operation to proceed with valid keys even when some keys are invalid. | ||
/// </remarks> | ||
public void AddKey(string key, string version) | ||
{ | ||
// Skip invalid keys instead of throwing exceptions | ||
// This allows the DeleteObjects operation to proceed with valid keys | ||
if (string.IsNullOrEmpty(key)) | ||
{ | ||
string message = "Skipping null or empty key in DeleteObjects request"; | ||
Logger.InfoFormat(message); | ||
|
||
ValidationErrors.Add(new DeleteError { | ||
Key = key ?? "(null)", | ||
Code = "InvalidKey", | ||
Message = "Key cannot be null or empty" | ||
}); | ||
return; | ||
} | ||
if (key.Length > 1024) | ||
{ | ||
string message = string.Format("Skipping key in DeleteObjects request: key length {0} exceeds maximum of 1024 characters", key.Length); | ||
Logger.InfoFormat(message); | ||
|
||
ValidationErrors.Add(new DeleteError { | ||
Key = key.Substring(0, Math.Min(key.Length, 128)) + (key.Length > 128 ? "..." : ""), | ||
Code = "KeyTooLongError", | ||
Message = string.Format("Key length {0} exceeds maximum of 1024 characters", key.Length) | ||
}); | ||
return; | ||
} | ||
|
||
AddKey(new KeyVersion { Key = key, VersionId = version }); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexDaines I understand this change just skips invalid keys and just sends valid ones with the request to the server. I'm wondering shouldn't this behavior be handled on the server side and proper
DeleteObjectsResponse
be returned from the server in that case?