Skip to content

Node.js based forum software built for the modern web

fix: closes #10682, strip unicode control chars

Barış Soner Uşaklıd867d8adbb37
diff --git a/src/routes/feeds.js b/src/routes/feeds.js
index 18a780b4ef..3d680fe85f 100644
--- a/src/routes/feeds.js
+++ b/src/routes/feeds.js
@@ -61,6 +61,11 @@ async function validateTokenIfRequiresLogin(requiresLogin, cid, req, res) {
return true;
}
+function stripUnicodeControlChars(str) {
+ // eslint-disable-next-line no-control-regex
+ return str.replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/g, '');
+}
+
async function generateForTopic(req, res, next) {
if (meta.config['feeds:disableRSS']) {
return next();
@@ -80,20 +85,21 @@ async function generateForTopic(req, res, next) {
if (await validateTokenIfRequiresLogin(!userPrivileges['topics:read'], topic.cid, req, res)) {
const topicData = await topics.getTopicWithPosts(topic, `tid:${tid}:posts`, req.uid || req.query.uid || 0, 0, 24, true);
+ const mainPost = topicData.posts[0];
topics.modifyPostsByPrivilege(topicData, userPrivileges);
-
+ const title = stripUnicodeControlChars(topicData.title);
const feed = new rss({
- title: utils.stripHTMLTags(topicData.title, utils.tags),
- description: topicData.posts.length ? topicData.posts[0].content : '',
+ title: utils.stripHTMLTags(title, utils.tags),
+ description: topicData.posts.length ? stripUnicodeControlChars(mainPost.content) : '',
feed_url: `${nconf.get('url')}/topic/${tid}.rss`,
site_url: `${nconf.get('url')}/topic/${topicData.slug}`,
- image_url: topicData.posts.length ? topicData.posts[0].picture : '',
- author: topicData.posts.length ? topicData.posts[0].username : '',
+ image_url: topicData.posts.length ? mainPost.picture : '',
+ author: topicData.posts.length ? mainPost.username : '',
ttl: 60,
});
if (topicData.posts.length > 0) {
- feed.pubDate = new Date(parseInt(topicData.posts[0].timestamp, 10)).toUTCString();
+ feed.pubDate = new Date(parseInt(mainPost.timestamp, 10)).toUTCString();
}
const replies = topicData.posts.slice(1);
replies.forEach((postData) => {
@@ -103,8 +109,8 @@ async function generateForTopic(req, res, next) {
).toUTCString();
feed.item({
- title: `Reply to ${utils.stripHTMLTags(topicData.title, utils.tags)} on ${dateStamp}`,
- description: postData.content,
+ title: `Reply to ${utils.stripHTMLTags(title, utils.tags)} on ${dateStamp}`,
+ description: stripUnicodeControlChars(postData.content),
url: `${nconf.get('url')}/post/${postData.pid}`,
author: postData.user ? postData.user.username : '',
date: dateStamp,