fix: closes #13068, encodeURIComponent X-Redirect

This commit is contained in:
Barış Soner Uşaklı
2025-01-22 12:42:16 -05:00
parent 52f7f0a75c
commit f3b8ed274a
2 changed files with 5 additions and 3 deletions

View File

@@ -69,7 +69,9 @@ exports.handleErrors = async function handleErrors(err, req, res, next) { // esl
// Display NodeBB error page // Display NodeBB error page
const status = parseInt(err.status, 10); const status = parseInt(err.status, 10);
if ((status === 302 || status === 308) && err.path) { if ((status === 302 || status === 308) && err.path) {
return res.locals.isAPI ? res.set('X-Redirect', err.path).status(200).json(err.path) : res.redirect(nconf.get('relative_path') + err.path); return res.locals.isAPI ?
res.set('X-Redirect', encodeURIComponent(err.path)).status(200).json(err.path) :
res.redirect(nconf.get('relative_path') + err.path);
} }
const path = String(req.path || ''); const path = String(req.path || '');

View File

@@ -168,7 +168,7 @@ helpers.redirect = function (res, url, permanent) {
if (url.hasOwnProperty('external')) { if (url.hasOwnProperty('external')) {
const redirectUrl = prependRelativePath(url.external); const redirectUrl = prependRelativePath(url.external);
if (res.locals.isAPI) { if (res.locals.isAPI) {
res.set('X-Redirect', redirectUrl).status(200).json({ external: redirectUrl }); res.set('X-Redirect', encodeURIComponent(redirectUrl)).status(200).json({ external: redirectUrl });
} else { } else {
res.redirect(permanent ? 308 : 307, redirectUrl); res.redirect(permanent ? 308 : 307, redirectUrl);
} }
@@ -176,7 +176,7 @@ helpers.redirect = function (res, url, permanent) {
} }
if (res.locals.isAPI) { if (res.locals.isAPI) {
res.set('X-Redirect', url).status(200).json(url); res.set('X-Redirect', encodeURIComponent(url)).status(200).json(url);
} else { } else {
res.redirect(permanent ? 308 : 307, prependRelativePath(url)); res.redirect(permanent ? 308 : 307, prependRelativePath(url));
} }