fix: redirect middleware shouldn't check baseURL

This commit is contained in:
Bereket Engida
2024-10-26 19:49:25 +03:00
parent 16450137ad
commit 0211dfb562
3 changed files with 4 additions and 5 deletions

View File

@@ -13,7 +13,7 @@
"lint": "biome check .", "lint": "biome check .",
"lint:fix": "biome check . --apply", "lint:fix": "biome check . --apply",
"release": "turbo --filter \"./packages/*\" build && bumpp && pnpm -r publish --access public --no-git-checks", "release": "turbo --filter \"./packages/*\" build && bumpp && pnpm -r publish --access public --no-git-checks",
"release:no-build": "bumpp && pnpm -r publish --access public --no-git-checks", "release:no-build": "bumpp && pnpm -r publish --access public --no-git-checks --tag next",
"release:beta": "turbo --filter \"./packages/*\" build && bumpp && pnpm -r publish --access public --tag next --no-git-checks", "release:beta": "turbo --filter \"./packages/*\" build && bumpp && pnpm -r publish --access public --tag next --no-git-checks",
"test": "turbo --filter \"./packages/*\" test", "test": "turbo --filter \"./packages/*\" test",
"typecheck": "turbo --filter \"./packages/*\" typecheck" "typecheck": "turbo --filter \"./packages/*\" typecheck"

View File

@@ -7,15 +7,14 @@ import { logger } from "../../utils/logger";
* preventing open redirect attacks. * preventing open redirect attacks.
*/ */
export const redirectURLMiddleware = createAuthMiddleware(async (ctx) => { export const redirectURLMiddleware = createAuthMiddleware(async (ctx) => {
const { body, query, headers, context } = ctx; const { body, query, context } = ctx;
const callbackURL = const callbackURL =
body?.callbackURL || body?.callbackURL ||
query?.callbackURL || query?.callbackURL ||
query?.redirectTo || query?.redirectTo ||
body?.redirectTo; body?.redirectTo;
const currentURL = const currentURL = query?.currentURL;
query?.currentURL || headers?.get("referer") || context.baseURL;
const trustedOrigins = context.trustedOrigins; const trustedOrigins = context.trustedOrigins;
const validateURL = (url: string | undefined, label: string) => { const validateURL = (url: string | undefined, label: string) => {

View File

@@ -30,8 +30,8 @@ export const betterAuth = <O extends BetterAuthOptions>(options: O) => {
getBaseURL(undefined, basePath) || `${url.origin}${basePath}`; getBaseURL(undefined, basePath) || `${url.origin}${basePath}`;
ctx.options.baseURL = baseURL; ctx.options.baseURL = baseURL;
ctx.baseURL = baseURL; ctx.baseURL = baseURL;
ctx.trustedOrigins = [url.origin];
} }
ctx.trustedOrigins = [url.origin, ...(ctx.options.trustedOrigins || [])];
if (!ctx.options.baseURL) { if (!ctx.options.baseURL) {
return new Response("Base URL not set", { status: 400 }); return new Response("Base URL not set", { status: 400 });
} }