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:
@@ -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()
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user