From f45b0379817f8e741c4b1e86633ad9acc782d612 Mon Sep 17 00:00:00 2001 From: bhou Date: Fri, 3 May 2024 13:52:14 -0700 Subject: [PATCH] Amend the check on IllegalAttachmentFileNameException --- .../LocalFileSystemAttachmentServiceImpl.java | 5 ++-- ...FileSystemAttachmentServiceImplSpec.groovy | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/genie-web/src/main/java/com/netflix/genie/web/services/impl/LocalFileSystemAttachmentServiceImpl.java b/genie-web/src/main/java/com/netflix/genie/web/services/impl/LocalFileSystemAttachmentServiceImpl.java index 1d596ad92a..61d8c5aaf8 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/services/impl/LocalFileSystemAttachmentServiceImpl.java +++ b/genie-web/src/main/java/com/netflix/genie/web/services/impl/LocalFileSystemAttachmentServiceImpl.java @@ -94,9 +94,10 @@ public Set saveAttachments( final long attachmentSize = attachment.contentLength(); final String filename = attachment.getFilename(); - if (filename != null && (filename.contains("/") || filename.contains("\\"))) { + if (filename != null && (filename.contains("/") || filename.contains("\\") + || filename.equals(".")) || filename.equals("..")) { throw new IllegalAttachmentFileNameException("Attachment filename " + filename + " is illegal. " - + "Filenames should not contain / or \\."); + + "Filenames should not be . or .., or contain /, \\."); } if (attachmentSize > this.attachmentServiceProperties.getMaxSize().toBytes()) { diff --git a/genie-web/src/test/groovy/com/netflix/genie/web/services/impl/LocalFileSystemAttachmentServiceImplSpec.groovy b/genie-web/src/test/groovy/com/netflix/genie/web/services/impl/LocalFileSystemAttachmentServiceImplSpec.groovy index 75f9cc700d..b95ea6ae64 100644 --- a/genie-web/src/test/groovy/com/netflix/genie/web/services/impl/LocalFileSystemAttachmentServiceImplSpec.groovy +++ b/genie-web/src/test/groovy/com/netflix/genie/web/services/impl/LocalFileSystemAttachmentServiceImplSpec.groovy @@ -179,4 +179,30 @@ class LocalFileSystemAttachmentServiceImplSpec extends Specification { then: thrown(IllegalAttachmentFileNameException) } + + def "reject attachments with illegal filename is ."() { + Set attachments = new HashSet() + Resource attachment = Mockito.mock(Resource.class) + Mockito.doReturn(".").when(attachment).getFilename() + attachments.add(attachment) + + when: + service.saveAttachments(null, attachments) + + then: + thrown(IllegalAttachmentFileNameException) + } + + def "reject attachments with illegal filename is .."() { + Set attachments = new HashSet() + Resource attachment = Mockito.mock(Resource.class) + Mockito.doReturn("..").when(attachment).getFilename() + attachments.add(attachment) + + when: + service.saveAttachments(null, attachments) + + then: + thrown(IllegalAttachmentFileNameException) + } }