mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-17 14:00:29 +01:00
fix: closes #13068, encodeURIComponent X-Redirect
This commit is contained in:
@@ -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 || '');
|
||||||
|
|||||||
@@ -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));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user