Skip to content

Commit 6220fbd

Browse files
committed
review
1 parent 3e5f576 commit 6220fbd

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/java/org/apache/cassandra/service/snapshot/SnapshotOptions.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@
3939

4040
import static java.lang.String.format;
4141
import static org.apache.cassandra.schema.SchemaConstants.FILENAME_LENGTH;
42+
import static org.apache.cassandra.utils.FBUtilities.now;
4243

4344
public class SnapshotOptions
4445
{
4546
public static final String SKIP_FLUSH = "skipFlush";
4647
public static final String TTL = "ttl";
4748

48-
// Follows AWS S3 "Safe characters" for object keys:
49-
// 0-9 a-z A-Z ! - _ . * ' ( )
50-
// See https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-guidelines
49+
// Conservative subset of the AWS S3 "Safe characters" set: 0-9 a-z A-Z - _ .
50+
// See the validation site in validateTag for the full rationale on excluded characters.
5151
// Hyphen is placed last in the character class, so it stays literal and never becomes a range operator.
5252
private static final Pattern SAFE_SNAPSHOT_NAME = Pattern.compile("[a-zA-Z0-9_.-]+");
53+
5354
public final SnapshotType type;
5455
public final String tag;
5556
public final DurationSpec.IntSecondsBound ttl;
@@ -232,15 +233,15 @@ private void validateTag(String tag)
232233
// it e.g. prepends timestamp and type for system snapshots, and we need to validate it as a whole.
233234
// If, for example, tag would be less than max allowed FILENAME_LENGTH,
234235
// we might in fact produce a snapshot name longer than FILENAME_LENGTH if we prepended a timestamp to it.
235-
String resolvedSnapshotname = SnapshotOptions.getSnapshotName(type, tag, Instant.now());
236+
String resolvedSnapshotName = SnapshotOptions.getSnapshotName(type, tag, now());
236237

237238
// the length of valid snapshot name has to be less than or equal to FILENAME_LEGTH - that is 255 -
238239
// we are following the max length as it is in SchemaConstants for table name.
239-
if (resolvedSnapshotname.length() > SchemaConstants.FILENAME_LENGTH)
240+
if (resolvedSnapshotName.length() > SchemaConstants.FILENAME_LENGTH)
240241
{
241242
throw new IllegalArgumentException(format("Snapshot name must not be more than %d characters long for " +
242243
"resolved snapshot name (got %d characters for \"%s\")",
243-
FILENAME_LENGTH, resolvedSnapshotname.length(), resolvedSnapshotname));
244+
FILENAME_LENGTH, resolvedSnapshotName.length(), resolvedSnapshotName));
244245
}
245246

246247
// Allowed characters are a conservative subset of the AWS S3 "Safe characters" set
@@ -249,9 +250,9 @@ private void validateTag(String tag)
249250
// The remaining S3-safe characters (! * ' ( )) are intentionally excluded as they are
250251
// shell-significant and error-prone in paths, and the path separator '/' is excluded too,
251252
// which is what blocks traversal attempts such as "../../mysnapshot"
252-
if (!SAFE_SNAPSHOT_NAME.matcher(resolvedSnapshotname).matches())
253+
if (!SAFE_SNAPSHOT_NAME.matcher(resolvedSnapshotName).matches())
253254
{
254-
throw new IllegalArgumentException("Snapshot name contains illegal characters: " + resolvedSnapshotname);
255+
throw new IllegalArgumentException("Snapshot name contains illegal characters: " + resolvedSnapshotName);
255256
}
256257
}
257258

0 commit comments

Comments
 (0)