Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[server/auth] ensure safe returnTo param #2879

Merged
merged 1 commit into from
Jan 13, 2021
Merged
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
6 changes: 6 additions & 0 deletions components/server/src/user/user-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ export class UserController {
}

// Proceed with login
this.ensureSafeReturnToParam(req);
await this.authenticator.authenticate(req, res, next);
});
router.get("/authorize", (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (!User.is(req.user)) {
res.sendStatus(401);
return;
}
this.ensureSafeReturnToParam(req);
this.authenticator.authorize(req, res, next);
});
const branding = this.env.brandingConfig;
Expand Down Expand Up @@ -483,6 +485,10 @@ export class UserController {
}
}

protected ensureSafeReturnToParam(req: express.Request) {
req.query.returnTo = this.getSafeReturnToParam(req);
}

protected getSafeReturnToParam(req: express.Request) {
const returnToURL: string | undefined = req.query.redirect || req.query.returnTo;
if (returnToURL) {
Expand Down