From df046c5335fc5a6b4968a967434134252505b1c7 Mon Sep 17 00:00:00 2001 From: orenom Date: Thu, 13 May 2021 17:40:56 +0200 Subject: [PATCH] fix invalid lang bug --- README.md | 2 +- src/routes.js | 2 +- src/utils.js | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 46ce296..288aff6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Many countries have censored Wikipedia pages, including China, France, Germany, ### 2: What's the problem of Wikipedia getting my IP address? -**Short:** If you trust that Wikipedia has not been infiltrated and/or you don't trust the Wikiless instance you would use, then you probably want to keep using Wikipedia instead of Wikiless because there are nothing to worry about giving IP address to Wikipedia. +**Short:** If you trust that Wikipedia has not been infiltrated and/or you don't trust the Wikiless instance you would use, then you probably want to keep using Wikipedia instead of Wikiless because there are nothing to worry about giving your IP address to Wikipedia. **Long:** We know from the leaks by Edward Snowden that the U.S. National Security Agency (NSA) has identified Wikipedia as a target for surveillance already in 2009.\[1\]\[2\] Wikimedia filled a lawsuit against the NSA in 2015 in order to fight against the mass-surveillance done by the NSA.\[2\]\[3\] diff --git a/src/routes.js b/src/routes.js index a7cad25..c43ccc1 100644 --- a/src/routes.js +++ b/src/routes.js @@ -79,7 +79,7 @@ module.exports = (app, utils) => { app.post('/preferences', (req, res, next) => { let theme = req.body.theme let default_lang = req.body.default_lang - let back = req.query.back + let back = req.url.split('?back=')[1] res.cookie('theme', theme, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true }) res.cookie('default_lang', default_lang, { maxAge: 365 * 24 * 60 * 60 * 1000, httpOnly: true }) diff --git a/src/utils.js b/src/utils.js index 723be99..4d674bb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -251,6 +251,14 @@ module.exports = function(redis) { this.handleWikiPage = async (req, res, prefix) => { let lang = req.query.lang || req.cookies.default_lang || config.default_lang + if(lang) { + if(typeof(lang) !== 'string') { + lang = lang[0] + } else { + lang = lang.split('?')[0] + } + } + if(!validLang(lang)) { return res.send('invalid lang') } @@ -385,6 +393,8 @@ module.exports = function(redis) { lang_select += '' + let back = req.url.split('?back=')[1] + let html = ` @@ -397,7 +407,7 @@ module.exports = function(redis) {

Preferences

-
+