mirror of
https://github.com/better-auth/better-auth.git
synced 2026-07-31 10:23:24 -05:00
fix: allow plus signs in relative callback URLs (#1823)
This commit is contained in:
@@ -73,6 +73,24 @@ describe("Origin Check", async (it) => {
|
||||
expect(res.data?.user).toBeDefined();
|
||||
});
|
||||
|
||||
it("should allow plus signs in the callback url", async (ctx) => {
|
||||
const client = createAuthClient({
|
||||
baseURL: "http://localhost:3000",
|
||||
fetchOptions: {
|
||||
customFetchImpl,
|
||||
headers: {
|
||||
origin: "https://localhost:3000",
|
||||
},
|
||||
},
|
||||
});
|
||||
const res = await client.signIn.email({
|
||||
email: testUser.email,
|
||||
password: testUser.password,
|
||||
callbackURL: "/dashboard+page?test=123+456",
|
||||
});
|
||||
expect(res.data?.user).toBeDefined();
|
||||
});
|
||||
|
||||
it("should reject callback url with double slash", async (ctx) => {
|
||||
const client = createAuthClient({
|
||||
baseURL: "http://localhost:3000",
|
||||
|
||||
@@ -49,7 +49,7 @@ export const originCheckMiddleware = createAuthMiddleware(async (ctx) => {
|
||||
matchesPattern(url, origin) ||
|
||||
(url?.startsWith("/") &&
|
||||
label !== "origin" &&
|
||||
/^\/(?!\/|\\|%2f|%5c)[\w\-./]*(?:\?[\w\-./=&%]*)?$/.test(url)),
|
||||
/^\/(?!\/|\\|%2f|%5c)[\w\-.\+/]*(?:\?[\w\-.\+/=&%]*)?$/.test(url)),
|
||||
);
|
||||
if (!isTrustedOrigin) {
|
||||
ctx.context.logger.error(`Invalid ${label}: ${url}`);
|
||||
@@ -106,7 +106,7 @@ export const originCheck = (
|
||||
matchesPattern(url, origin) ||
|
||||
(url?.startsWith("/") &&
|
||||
label !== "origin" &&
|
||||
/^\/(?!\/|\\|%2f|%5c)[\w\-./]*(?:\?[\w\-./=&%]*)?$/.test(url)),
|
||||
/^\/(?!\/|\\|%2f|%5c)[\w\-.\+/]*(?:\?[\w\-.\+/=&%]*)?$/.test(url)),
|
||||
);
|
||||
if (!isTrustedOrigin) {
|
||||
ctx.context.logger.error(`Invalid ${label}: ${url}`);
|
||||
|
||||
Reference in New Issue
Block a user