3939
4040import static java .lang .String .format ;
4141import static org .apache .cassandra .schema .SchemaConstants .FILENAME_LENGTH ;
42+ import static org .apache .cassandra .utils .FBUtilities .now ;
4243
4344public 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_.-]+" );
5353 public final SnapshotType type ;
@@ -232,15 +232,15 @@ private void validateTag(String tag)
232232 // it e.g. prepends timestamp and type for system snapshots, and we need to validate it as a whole.
233233 // If, for example, tag would be less than max allowed FILENAME_LENGTH,
234234 // 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 ());
235+ String resolvedSnapshotName = SnapshotOptions .getSnapshotName (type , tag , now ());
236236
237237 // the length of valid snapshot name has to be less than or equal to FILENAME_LEGTH - that is 255 -
238238 // we are following the max length as it is in SchemaConstants for table name.
239- if (resolvedSnapshotname .length () > SchemaConstants .FILENAME_LENGTH )
239+ if (resolvedSnapshotName .length () > SchemaConstants .FILENAME_LENGTH )
240240 {
241241 throw new IllegalArgumentException (format ("Snapshot name must not be more than %d characters long for " +
242242 "resolved snapshot name (got %d characters for \" %s\" )" ,
243- FILENAME_LENGTH , resolvedSnapshotname .length (), resolvedSnapshotname ));
243+ FILENAME_LENGTH , resolvedSnapshotName .length (), resolvedSnapshotName ));
244244 }
245245
246246 // Allowed characters are a conservative subset of the AWS S3 "Safe characters" set
@@ -249,9 +249,9 @@ private void validateTag(String tag)
249249 // The remaining S3-safe characters (! * ' ( )) are intentionally excluded as they are
250250 // shell-significant and error-prone in paths, and the path separator '/' is excluded too,
251251 // which is what blocks traversal attempts such as "../../mysnapshot"
252- if (!SAFE_SNAPSHOT_NAME .matcher (resolvedSnapshotname ).matches ())
252+ if (!SAFE_SNAPSHOT_NAME .matcher (resolvedSnapshotName ).matches ())
253253 {
254- throw new IllegalArgumentException ("Snapshot name contains illegal characters: " + resolvedSnapshotname );
254+ throw new IllegalArgumentException ("Snapshot name contains illegal characters: " + resolvedSnapshotName );
255255 }
256256 }
257257
0 commit comments