This is an automated email from the ASF dual-hosted git repository.
snoopdave pushed a commit to branch roller-6.1.x
in repository https://gitbox.apache.org/repos/asf/roller.git
The following commit(s) were added to refs/heads/roller-6.1.x by this push:
new 65b083836 Keep mail subjects on one line (#402)
65b083836 is described below
commit 65b083836ebb11803fc808cc5572b27ef86aeb7d
Author: David M. Johnson <[email protected]>
AuthorDate: Sat Nov 28 10:07:07 2026 -0500
Keep mail subjects on one line (#402)
- 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 f7bc2a721..07865cae3 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -141,6 +141,8 @@
- **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.
+- **Mail subjects stay on one line.** Line breaks in an entry title or
+ weblog name are sent as spaces in notification and invitation subjects.
- **Media filenames keep their punctuation** when inserted into an entry.
- **"Upload more" and "Cancel" work after a media upload.** Both buttons on
the upload-complete page failed with a script error instead of opening the
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 57e6caaeb..2b323d0da 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
@@ -602,6 +602,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.
/**
@@ -670,7 +680,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..920915471
--- /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 javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.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 786998a2e..fccdc7581 100644
--- a/docs/security-model.md
+++ b/docs/security-model.md
@@ -230,6 +230,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 and ping
targets.
@@ -361,6 +365,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.