1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-03-23 20:30:07 +00:00

fix: add validation for callback URLs (#929)

This commit is contained in:
Elias Schneider
2025-09-10 19:14:54 +02:00
committed by GitHub
parent d123d7f335
commit 6c9147483c
4 changed files with 60 additions and 16 deletions

View File

@@ -1,3 +1,4 @@
import { m } from '$lib/paraglide/messages';
import z from 'zod/v4';
export const emptyToUndefined = <T>(validation: z.ZodType<T>) =>
@@ -7,3 +8,21 @@ export const optionalUrl = z
.url()
.optional()
.or(z.literal('').transform(() => undefined));
export const callbackUrlSchema = z
.string()
.nonempty()
.refine(
(val) => {
if (val === '*') return true;
try {
new URL(val.replace(/\*/g, 'x'));
return true;
} catch {
return false;
}
},
{
message: m.invalid_redirect_url()
}
);