fix: Remove trust of state.host in auth error redirect
This commit is contained in:
@@ -3,7 +3,7 @@ import { Context } from "koa";
|
|||||||
import { InternalOAuthError } from "passport-oauth2";
|
import { InternalOAuthError } from "passport-oauth2";
|
||||||
import { Client } from "@shared/types";
|
import { Client } from "@shared/types";
|
||||||
import env from "@server/env";
|
import env from "@server/env";
|
||||||
import { AuthenticationError } from "@server/errors";
|
import { AuthenticationError, OAuthStateMismatchError } from "@server/errors";
|
||||||
import Logger from "@server/logging/Logger";
|
import Logger from "@server/logging/Logger";
|
||||||
import { AuthenticationResult } from "@server/types";
|
import { AuthenticationResult } from "@server/types";
|
||||||
import { signIn } from "@server/utils/authentication";
|
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
|
// form a URL object with the err.redirectPath and replace the host
|
||||||
const reqProtocol =
|
const reqProtocol =
|
||||||
state?.client === Client.Desktop ? "outline" : ctx.protocol;
|
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(
|
const url = new URL(
|
||||||
env.isCloudHosted
|
env.isCloudHosted
|
||||||
? `${reqProtocol}://${requestHost}${redirectPath}`
|
? `${reqProtocol}://${requestHost}${redirectPath}`
|
||||||
|
|||||||
Reference in New Issue
Block a user