This is an automated email from the ASF dual-hosted git repository.

chibenwa pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new e263c33d72 [FIX] JMAP Downloads should sanitize empty content type 
(#3163)
e263c33d72 is described below

commit e263c33d72cb963b85169f8439825502e78dfd1f
Author: Benoit TELLIER <[email protected]>
AuthorDate: Thu Sep 10 12:54:45 2026 +0200

    [FIX] JMAP Downloads should sanitize empty content type (#3163)
---
 .../jmap/rfc8621/contract/DownloadContract.scala   | 43 ++++++++++++++++++++++
 .../apache/james/jmap/routes/DownloadRoutes.scala  |  1 +
 2 files changed, 44 insertions(+)

diff --git 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala
 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala
index 8f4e58c101..da38520e97 100644
--- 
a/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala
+++ 
b/server/protocols/jmap-rfc-8621-integration-tests/jmap-rfc-8621-integration-tests-common/src/main/scala/org/apache/james/jmap/rfc8621/contract/DownloadContract.scala
@@ -365,6 +365,49 @@ trait DownloadContract {
       .contentType("text/markdown")
   }
 
+  @Test
+  def emptyContentTypeShouldFallBackToTheBlobContentType(server: 
GuiceJamesServer): Unit = {
+    val path = MailboxPath.inbox(bobUsername)
+    server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)
+    val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl])
+      .appendMessage(bobUsername.asString, path, AppendCommand.from(
+        
ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    `given`
+      .basePath("")
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .queryParam("type", "")
+    .when
+      .get(s"/download/$bobAccountId/${messageId.serialize()}_3")
+    .`then`
+      .statusCode(SC_OK)
+      .contentType("text/plain")
+  }
+
+  @Test
+  def emptyNameShouldBeDiscarded(server: GuiceJamesServer): Unit = {
+    val path = MailboxPath.inbox(bobUsername)
+    server.getProbe(classOf[MailboxProbeImpl]).createMailbox(path)
+    val messageId: MessageId = server.getProbe(classOf[MailboxProbeImpl])
+      .appendMessage(bobUsername.asString, path, AppendCommand.from(
+        
ClassLoaderUtils.getSystemResourceAsSharedStream("eml/multipart_simple.eml")))
+      .getMessageId
+
+    val contentDisposition = `given`
+      .basePath("")
+      .header(ACCEPT.toString, ACCEPT_RFC8621_VERSION_HEADER)
+      .queryParam("name", "")
+    .when
+      .get(s"/download/$bobAccountId/${messageId.serialize()}_3")
+    .`then`
+      .statusCode(SC_OK)
+      .extract()
+      .header("Content-Disposition")
+
+    assertThat(contentDisposition).isNullOrEmpty()
+  }
+
   @Test
   def downloadPartShouldDiscardNameWhenNotSuppliedByTheClient(server: 
GuiceJamesServer): Unit = {
     val path = MailboxPath.inbox(bobUsername)
diff --git 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/DownloadRoutes.scala
 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/DownloadRoutes.scala
index 942accf14a..8481609322 100644
--- 
a/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/DownloadRoutes.scala
+++ 
b/server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/routes/DownloadRoutes.scala
@@ -438,6 +438,7 @@ class DownloadRoutes 
@Inject()(@Named(InjectionKeys.RFC_8621) val authenticator:
       .toList
       .flatMap(_.asScala)
       .headOption
+      .filter(_.nonEmpty)
 
   private def respondDetails(httpServerResponse: HttpServerResponse, details: 
ProblemDetails): SMono[Unit] =
     if (httpServerResponse.hasSentHeaders) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to