Skip to content

Commit

Permalink
Amend the check on IllegalAttachmentFileNameException
Browse files Browse the repository at this point in the history
  • Loading branch information
bhou committed May 3, 2024
1 parent 0dbdd3d commit f45b037
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ public Set<URI> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,30 @@ class LocalFileSystemAttachmentServiceImplSpec extends Specification {
then:
thrown(IllegalAttachmentFileNameException)
}
def "reject attachments with illegal filename is ."() {
Set<Resource> attachments = new HashSet<Resource>()
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<Resource> attachments = new HashSet<Resource>()
Resource attachment = Mockito.mock(Resource.class)
Mockito.doReturn("..").when(attachment).getFilename()
attachments.add(attachment)
when:
service.saveAttachments(null, attachments)
then:
thrown(IllegalAttachmentFileNameException)
}
}

0 comments on commit f45b037

Please sign in to comment.