CASSANDRA-21389 trunk Harden snapshot names on server side#4826
CASSANDRA-21389 trunk Harden snapshot names on server side#4826smiklosovic wants to merge 3 commits into
Conversation
828d1ef to
b23b207
Compare
b23b207 to
394dc0d
Compare
Jollyplum
left a comment
There was a problem hiding this comment.
Had some minor nits but apart from that LGTM
| // 0-9 a-z A-Z ! - _ . * ' ( ) | ||
| // See https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-guidelines | ||
| // Hyphen is placed last in the character class, so it stays literal and never becomes a range operator. | ||
| private static final Pattern SAFE_SNAPSHOT_NAME = Pattern.compile("[a-zA-Z0-9_.-]+"); |
There was a problem hiding this comment.
Part of me is wondering if we allow folks to configure the check off, maybe it may also make sense to allow them to configure what to restrict on?
Then if they encounter some character that they do actually validly need or can't change for some reason, operators can still benefit from some restrictions.
Debatable though maybe adds more configuration/reasoning complexity where we just want simplicity.
There was a problem hiding this comment.
we are complicating it too much imho with allowing them to do that, I think that is just premature as of now, they have a way to just completely remove the validation, that is good enough imho
| throw new RuntimeException("You must supply a snapshot name."); | ||
| throw new IllegalArgumentException("You must supply a snapshot name."); | ||
|
|
||
| if (tag.contains(File.pathSeparator())) |
There was a problem hiding this comment.
I think we may need to reject both the native path separator and '/' since on windows '\' is the path separator but '/' is still treated as a path separator, so in theory the path traversal attack remains on windows via that means.
There was a problem hiding this comment.
Actually potentially this is fine it seems we've remove windows support as of:
https://issues.apache.org/jira/browse/CASSANDRA-16171
https://issues.apache.org/jira/browse/CASSANDRA-16956
There was a problem hiding this comment.
we do not support Windows
394dc0d to
88d8022
Compare
88d8022 to
6220fbd
Compare
|
From the Alex's shallow/deep review, it seems we need to include |
|
one option is to only validate the snapshot names when the input is |
| // The remaining S3-safe characters (! * ' ( )) are intentionally excluded as they are | ||
| // shell-significant and error-prone in paths, and the path separator '/' is excluded too, | ||
| // which is what blocks traversal attempts such as "../../mysnapshot" | ||
| if (!SAFE_SNAPSHOT_NAME.matcher(resolvedSnapshotName).matches()) |
There was a problem hiding this comment.
maybe consider restricting only for user snapshots?
| if (!SAFE_SNAPSHOT_NAME.matcher(resolvedSnapshotName).matches()) | |
| if (type == SnapshotType.USER && !SAFE_SNAPSHOT_NAME.matcher(resolvedSnapshotName).matches()) |
|
I played a little more with this PR, and I think we should add checks in While this has no effect at the moment, and I couldn't clear other snapshots, I think it's a good idea to fail with the validation. Also, I think we should explicitly tell users which characters are allowed when creating the snapshot. Here's the sample output from the create snapshot command We should instead say or something along those lines |
Thanks for sending a pull request! Here are some tips if you're new here:
Commit messages should follow the following format:
The Cassandra Jira