fix: allow plus signs in relative callback URLs (#1823)

This commit is contained in:
Alex Boyd
2025-03-15 08:02:13 +03:00
committed by GitHub
parent db9290b043
commit a448c517b3
2 changed files with 20 additions and 2 deletions
@@ -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}`);