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

snoopdave pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/roller.git


The following commit(s) were added to refs/heads/master by this push:
     new 3d6c9910e Keep mail subjects on one line (#403)
3d6c9910e is described below

commit 3d6c9910e785169cd8bd9485c8cc238ccac0d9bd
Author: David M. Johnson <[email protected]>
AuthorDate: Sun Nov 29 12:17:44 2026 -0500

    Keep mail subjects on one line (#403)
    
    - Line breaks and other control characters in a subject, which can come
      from an entry title or weblog name, are sent as a single space.
    - The security model says what mail Roller sends may carry from members
      and commenters.
    - MailUtilSubjectTest checks the sent headers.
---
 CHANGES.md                                         |   2 +
 .../org/apache/roller/weblogger/util/MailUtil.java |  12 ++-
 .../roller/weblogger/util/MailUtilSubjectTest.java | 100 +++++++++++++++++++++
 docs/security-model.md                             |   8 ++
 4 files changed, 121 insertions(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index 0929c14c2..ec14dff12 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -54,6 +54,8 @@
 
 ### Bug fixes
 
+- **Mail subjects stay on one line.** Line breaks in an entry title or
+  weblog name are sent as spaces in notification and invitation subjects.
 - **The comment filter works after editing a comment.** Saving a comment
   on the Comments page left the filter form with a used-up form token, so
   filtering then failed with an error.
diff --git a/app/src/main/java/org/apache/roller/weblogger/util/MailUtil.java 
b/app/src/main/java/org/apache/roller/weblogger/util/MailUtil.java
index 18b65242f..8ccc4eb1a 100644
--- a/app/src/main/java/org/apache/roller/weblogger/util/MailUtil.java
+++ b/app/src/main/java/org/apache/roller/weblogger/util/MailUtil.java
@@ -603,6 +603,16 @@ public class MailUtil {
     }
     
     
+    /**
+     * Subjects include entry titles and weblog names, so keep them to one
+     * line: each run of line breaks or other control characters becomes a
+     * single space.
+     */
+    static String singleLine(String text) {
+        return text.replaceAll("\\p{Cntrl}+", " ").trim();
+    }
+
+
     // agangolli: Incorporated suggested changes from Ken Blackler.
     
     /**
@@ -671,7 +681,7 @@ public class MailUtil {
             }
             message.setRecipients(Message.RecipientType.BCC, copyTo);
         }
-        message.setSubject((subject == null) ? "(no subject)" : subject, 
"UTF-8");
+        message.setSubject((subject == null) ? "(no subject)" : 
singleLine(subject), "UTF-8");
         message.setContent(content, mimeType);
         message.setSentDate(new java.util.Date());
         
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/util/MailUtilSubjectTest.java 
b/app/src/test/java/org/apache/roller/weblogger/util/MailUtilSubjectTest.java
new file mode 100644
index 000000000..1aa3e977b
--- /dev/null
+++ 
b/app/src/test/java/org/apache/roller/weblogger/util/MailUtilSubjectTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.roller.weblogger.util;
+
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import jakarta.mail.Address;
+import jakarta.mail.Message;
+import jakarta.mail.Session;
+import jakarta.mail.Transport;
+import jakarta.mail.internet.MimeMessage;
+
+import org.apache.roller.weblogger.business.MailProvider;
+import org.apache.roller.weblogger.business.startup.WebloggerStartup;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+/**
+ * A subject built from an entry title or weblog name stays one header line.
+ */
+class MailUtilSubjectTest {
+
+    private MockedStatic<WebloggerStartup> startup;
+    private final List<MimeMessage> sent = new ArrayList<>();
+
+    @BeforeEach
+    void setUp() throws Exception {
+        Transport transport = mock(Transport.class);
+        doAnswer(invocation -> {
+            sent.add((MimeMessage) invocation.getArgument(0));
+            return null;
+        }).when(transport).sendMessage(any(Message.class), 
any(Address[].class));
+        MailProvider mail = mock(MailProvider.class);
+        when(mail.getSession()).thenReturn(Session.getInstance(new 
Properties()));
+        when(mail.getTransport()).thenReturn(transport);
+        startup = mockStatic(WebloggerStartup.class);
+        startup.when(WebloggerStartup::getMailProvider).thenReturn(mail);
+    }
+
+    @AfterEach
+    void tearDown() {
+        startup.close();
+    }
+
+    @Test
+    void lineBreaksInTheSubjectDoNotStartNewHeaders() throws Exception {
+        MailUtil.sendTextMessage("[email protected]", new String[] 
{"[email protected]"}, null, null,
+                "Pending: Notice\r\nReply-To: 
[email protected]\r\nContent-Type: text/html\r\n\r\nText",
+                "body");
+
+        assertEquals(1, sent.size());
+        MimeMessage message = sent.get(0);
+        assertEquals("Pending: Notice Reply-To: [email protected] 
Content-Type: text/html Text",
+                message.getSubject());
+        assertNull(message.getHeader("Reply-To"));
+
+        ByteArrayOutputStream raw = new ByteArrayOutputStream();
+        message.writeTo(raw);
+        String headers = 
raw.toString(StandardCharsets.UTF_8.name()).split("\r\n\r\n", 2)[0];
+        assertTrue(headers.lines().noneMatch(line -> 
line.startsWith("Reply-To")), headers);
+        assertEquals(1, headers.lines().filter(line -> 
line.startsWith("Content-Type")).count(), headers);
+        assertTrue(headers.contains("Content-Type: text/plain; 
charset=utf-8"), headers);
+    }
+
+    @Test
+    void otherControlCharactersBecomeSpaces() {
+        assertEquals("a b c", MailUtil.singleLine("a\tb\u0000\u001fc\n"));
+        assertEquals("Plain title", MailUtil.singleLine("Plain title"));
+    }
+}
diff --git a/docs/security-model.md b/docs/security-model.md
index b2f848cc8..3c828a4f5 100644
--- a/docs/security-model.md
+++ b/docs/security-model.md
@@ -227,6 +227,10 @@ flowchart LR
      links and author URLs must be `http` or `https`.
    - Templates run in the sandbox.
    - Uploaded files are never served as active content (see below).
+   - Mail Roller sends (comment notices, moderation notices, invitations)
+     carries member and commenter text only in the subject and the body,
+     escaped when the body is HTML. That text cannot add headers, change the
+     recipients or change the content type.
 4. **Server → network.** Users below global admin cannot make the server fetch
    a URL of their choice. Entry enclosure URLs are stored, not fetched. Global
    admins can point the server at any URL through Planet feeds.
@@ -358,6 +362,10 @@ Roller does not protect against:
 - **What the aggregated front-page weblog's templates show.** Its Admins are
   trusted to read across the site (see
   [The aggregated front-page weblog](#the-aggregated-front-page-weblog)).
+- **What notification mail quotes.** Notices quote entry titles, weblog names
+  and comment text, so that text can say anything, including a misleading
+  link. Who receives mail, and whether mail is sent at all, is the operator's
+  and the weblog Admin's setting.
 - **Partial writes** when a multi-step operation fails. That is a bug, not a
   vulnerability.
 

Reply via email to