Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Parse-Dashboard/Authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,22 @@ function initialize(app, options) {
csrf(),
(req,res,next) => {
let redirect = 'apps';
let originalRedirect = null;
if (req.body.redirect) {
redirect = req.body.redirect.charAt(0) === '/' ? req.body.redirect.substring(1) : req.body.redirect
originalRedirect = req.body.redirect;
// Validate redirect to prevent open redirect vulnerability
if (originalRedirect.includes('://') || originalRedirect.startsWith('//')) {
// Reject absolute URLs and protocol-relative URLs
redirect = 'apps';
originalRedirect = null;
} else {
// Strip leading slash from redirect to prevent double slashes
redirect = originalRedirect.charAt(0) === '/' ? originalRedirect.substring(1) : originalRedirect;
}
}
return passport.authenticate('local', {
successRedirect: `${self.mountPath}${redirect}`,
failureRedirect: `${self.mountPath}login${req.body.redirect ? `?redirect=${req.body.redirect}` : ''}`,
failureRedirect: `${self.mountPath}login${originalRedirect ? `?redirect=${originalRedirect}` : ''}`,
failureFlash : true
})(req, res, next)
},
Expand Down
20 changes: 19 additions & 1 deletion Parse-Dashboard/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,26 @@ You have direct access to the Parse database through function calls, so you can
}

app.get('/login', csrf(), function(req, res) {
const redirectURL = req.url.includes('?redirect=') && req.url.split('?redirect=')[1].length > 1 && req.url.split('?redirect=')[1];
let redirectURL = null;
try {
const url = new URL(req.url, 'http://localhost');
redirectURL = url.searchParams.get('redirect');
} catch (error) {
console.warn('Invalid URL in login redirect:', error.message);
}
if (!users || (req.user && req.user.isAuthenticated)) {
// Validate and sanitize redirect URL to prevent open redirect vulnerability
if (redirectURL) {
// Reject absolute URLs and protocol-relative URLs
if (redirectURL.includes('://') || redirectURL.startsWith('//')) {
redirectURL = null;
} else {
// Strip leading slash to prevent double slashes
if (redirectURL.charAt(0) === '/') {
redirectURL = redirectURL.substring(1);
}
}
}
return res.redirect(`${mountPath}${redirectURL || 'apps'}`);
}

Expand Down
Loading