Skip to content
48 changes: 44 additions & 4 deletions apps/meteor/app/meteor-accounts-saml/server/lib/SAML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class SAML {
case 'logout':
return this.processLogoutAction(req, res, service);
case 'sloRedirect':
return this.processSLORedirectAction(req, res);
return this.processSLORedirectAction(req, res, service);
case 'authorize':
return this.processAuthorizeAction(res, service, samlObject);
case 'validate':
Expand Down Expand Up @@ -391,11 +391,51 @@ export class SAML {
});
}

private static processSLORedirectAction(req: IIncomingMessage, res: ServerResponse): void {
private static processSLORedirectAction(req: IIncomingMessage, res: ServerResponse, service: IServiceProviderOptions): void {
const { idpSLORedirectURL } = service;
const userRedirect = req.query.redirect as string;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.

if (!idpSLORedirectURL) {
res.writeHead(500);
res.end('SLO redirect not configured');
return;
}

if (!userRedirect) {
Comment thread
yasnagat marked this conversation as resolved.
Outdated
res.writeHead(400);
res.end('Missing redirect parameter');
return;
}

let configuredURL: URL;
let requestURL: URL;

try {
configuredURL = new URL(idpSLORedirectURL);
requestURL = new URL(userRedirect);
} catch {
res.writeHead(400);
res.end('Invalid URL format');
return;
Comment thread
julio-rocketchat marked this conversation as resolved.
}

if (configuredURL.origin !== requestURL.origin) {
res.writeHead(403);
res.end('Unauthorized redirect origin');
return;
}

const normalizePath = (p: string): string => p.replace(/\/+$/, '') || '/';
if (normalizePath(configuredURL.pathname) !== normalizePath(requestURL.pathname)) {
res.writeHead(403);
res.end('Unauthorized redirect path');
return;
}

res.writeHead(302, {
// credentialToken here is the SAML LogOut Request that we'll send back to IDP
Location: req.query.redirect,
Location: requestURL.toString(),
Comment thread
julio-rocketchat marked this conversation as resolved.
});

res.end();
}

Expand Down
Loading