1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-14 14:42:26 +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()
}
);

View File

@@ -15,7 +15,7 @@
import { preventDefault } from '$lib/utils/event-util';
import { createForm } from '$lib/utils/form-util';
import { cn } from '$lib/utils/style';
import { emptyToUndefined, optionalUrl } from '$lib/utils/zod-util';
import { callbackUrlSchema, emptyToUndefined, optionalUrl } from '$lib/utils/zod-util';
import { LucideChevronDown } from '@lucide/svelte';
import { slide } from 'svelte/transition';
import { z } from 'zod/v4';
@@ -65,8 +65,8 @@
.optional()
),
name: z.string().min(2).max(50),
callbackURLs: z.array(z.string().nonempty()).default([]),
logoutCallbackURLs: z.array(z.string().nonempty()),
callbackURLs: z.array(callbackUrlSchema).default([]),
logoutCallbackURLs: z.array(callbackUrlSchema).default([]),
isPublic: z.boolean(),
pkceEnabled: z.boolean(),
requiresReauthentication: z.boolean(),