Validate filename both before and after resolving the path (elastic/x-pack-elasticsearch#1775)
This change ensures we fail early with validation before we even attempt to resolve a path as the
path resolution can fail with invalid characters on some operating systems.
relates elastic/x-pack-elasticsearch#1757
Original commit: elastic/x-pack-elasticsearch@3a4243b6d644f84bfeefe17d6daab6e8b62e67d4
@@ -617,7 +617,8 @@ public class CertificateTool extends EnvironmentAwareCommand {
}
static boolean isValidFilename(String name) {
- return ALLOWED_FILENAME_CHAR_PATTERN.matcher(resolvePath(name).toString()).matches()
+ return ALLOWED_FILENAME_CHAR_PATTERN.matcher(name).matches()
+ && ALLOWED_FILENAME_CHAR_PATTERN.matcher(resolvePath(name).toString()).matches()
&& name.startsWith(".") == false;
}
}
