mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
fix: Remove trust of state.host in auth error redirect
This commit is contained in:
1 parent
1d97a6c10b
commit
c9d5ff7ca5
1 file changed
+7
-2
@@ -3,7 +3,7 @@ import { Context } from "koa";
|
||||
import { InternalOAuthError } from "passport-oauth2";
|
||||
import { Client } from "@shared/types";
|
||||
import env from "@server/env";
|
||||
import { AuthenticationError } from "@server/errors";
|
||||
import { AuthenticationError, OAuthStateMismatchError } from "@server/errors";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import { AuthenticationResult } from "@server/types";
|
||||
import { signIn } from "@server/utils/authentication";
|
||||
@@ -39,7 +39,12 @@ export default function createMiddleware(providerName: string) {
|
||||
// form a URL object with the err.redirectPath and replace the host
|
||||
const reqProtocol =
|
||||
state?.client === Client.Desktop ? "outline" : ctx.protocol;
|
||||
const requestHost = state?.host ?? ctx.hostname;
|
||||
|
||||
// `state.host` cannot be trusted if the error is a state mismatch, use `ctx.hostname`
|
||||
const requestHost =
|
||||
err instanceof OAuthStateMismatchError
|
||||
? ctx.hostname
|
||||
: state?.host ?? ctx.hostname;
|
||||
const url = new URL(
|
||||
env.isCloudHosted
|
||||
? `${reqProtocol}://${requestHost}${redirectPath}`
|
||||
|
||||
Reference in new issue
Block a user