Skip to content

Commit

Permalink
[server/auth] ensure safe returnTo param
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTugarev committed Jan 13, 2021
1 parent aced836 commit 8ca431f
Showing 1 changed file with 6 additions and 0 deletions.
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

0 comments on commit 8ca431f

Please sign in to comment.