diff --git a/core/src/main/java/org/apache/struts2/dispatcher/multipart/UploadedFile.java b/core/src/main/java/org/apache/struts2/dispatcher/multipart/UploadedFile.java index fd5c9f2c1f..d995eac7a5 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/multipart/UploadedFile.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/multipart/UploadedFile.java @@ -43,18 +43,17 @@ public interface UploadedFile extends Serializable { String getName(); /** - * The raw file name submitted by the client -- untrusted input. It may contain - * directory-traversal sequences or drive/UNC prefixes and must not be used to build a - * filesystem path. See {@link #getOriginalBaseName()}. + * The file name as sent by the client, unmodified; it may include a directory part, so do not + * use it to build a filesystem path. See {@link #getOriginalBaseName()}. * - * @return original file name from upload source, exactly as the client supplied it + * @return original file name from upload source */ String getOriginalName(); /** - * The last path segment of {@link #getOriginalName()}, intended for display. It is still - * client-controlled and may be empty, {@code ..}, or otherwise unsafe, so validate it before - * using it in a filesystem path. + * The last path segment of {@link #getOriginalName()}, intended for display. It may be empty, + * {@code ..}, or keep a drive prefix such as {@code C:}, so validate it before using it in a + * filesystem path. * * @return the last path segment of {@link #getOriginalName()} * @since 7.6.0 diff --git a/core/src/main/java/org/apache/struts2/interceptor/ActionFileUploadInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/ActionFileUploadInterceptor.java index d95340afe2..10b0e83ca0 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/ActionFileUploadInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/ActionFileUploadInterceptor.java @@ -187,7 +187,7 @@ * this.uploadedFile = uploadedFiles.get(0); * this.fileName = uploadedFile.getName(); * this.contentType = uploadedFile.getContentType(); - * // getOriginalName() is untrusted client input; getOriginalBaseName() is the basename, for display + * // getOriginalBaseName() keeps only the part of the client's file name after the last / or \ * this.originalName = uploadedFile.getOriginalBaseName(); * } * }