Node.js based forum software built for the modern web
fix(feeds): replace user lockout with per-IP rate limit for RSS token failures (#14329)
Julian Lambdac7a7d1787
diff --git a/src/routes/feeds.js b/src/routes/feeds.jsindex 31ee634850..140d3830d1 100644--- a/src/routes/feeds.js+++ b/src/routes/feeds.js@@ -49,11 +49,22 @@ async function validateTokenIfRequiresLogin(requiresLogin, cid, req, res) {if (uid <= 0 || !token) {return controllerHelpers.notAllowed(req, res);}++ const ip = req.ip || req.connection.remoteAddress;+ const rateLimitKey = `rss:token:fail:${ip}`;+ const count = await db.increment(rateLimitKey);+ if (count === 1) {+ await db.pexpire(rateLimitKey, 3600000);+ }+ if (count > 5) {+ return controllerHelpers.notAllowed(req, res);+ }+const userToken = await db.getObjectField(`user:${uid}`, 'rss_token');if (userToken !== token) {- await user.auth.logAttempt(uid, req.ip);return controllerHelpers.notAllowed(req, res);}+ await db.delete(rateLimitKey);const userPrivileges = await privileges.categories.get(cid, uid);if (!userPrivileges.read) {return controllerHelpers.notAllowed(req, res);@@ -316,7 +327,8 @@ async function generateForRecentPosts(req, res, next) {const postsPerPage = 20;const start = Math.max(0, (page - 1) * postsPerPage);const stop = start + postsPerPage - 1;- const postData = await posts.getRecentPosts(req.uid, start, stop, 'month');+ const uid = await getUidFromToken(req);+ const postData = await posts.getRecentPosts(uid, start, stop, 'month');const feed = generateForPostsFeed({title: 'Recent Posts',description: 'A list of recent posts',@@ -394,8 +406,9 @@ async function generateForUserTopics(req, res, next) {return next();}const userData = await user.getUserFields(uid, ['uid', 'username']);+ const authUid = await getUidFromToken(req);await sendTopicsFeed({- uid: req.uid,+ uid: authUid,title: `Topics by ${userData.username}`,description: `A list of topics that are posted by ${userData.username}`,feed_url: `/user/${userslug}/topics.rss`,