mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-27 01:16:23 +02:00
parent
1f58c1f6cb
commit
acc655172d
8 changed files with 1642 additions and 1 deletions
|
|
@ -1,5 +1,18 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
const IFRAME_LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
||||
|
||||
export function isAllowedIframeUrl(url: string): boolean {
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (parsed.protocol === 'https:') return true;
|
||||
if (parsed.protocol !== 'http:') return false;
|
||||
return IFRAME_LOCAL_HOSTS.has(parsed.hostname.toLowerCase());
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export const ImageBlockSchema = z.object({
|
||||
src: z.string(),
|
||||
alt: z.string().optional(),
|
||||
|
|
@ -16,6 +29,18 @@ export const EmbedBlockSchema = z.object({
|
|||
|
||||
export type EmbedBlock = z.infer<typeof EmbedBlockSchema>;
|
||||
|
||||
export const IframeBlockSchema = z.object({
|
||||
url: z.string().url().refine(isAllowedIframeUrl, {
|
||||
message: 'Iframe URLs must use https:// or local http://localhost / 127.0.0.1.',
|
||||
}),
|
||||
title: z.string().optional(),
|
||||
caption: z.string().optional(),
|
||||
height: z.number().int().min(240).max(1600).optional(),
|
||||
allow: z.string().optional(),
|
||||
});
|
||||
|
||||
export type IframeBlock = z.infer<typeof IframeBlockSchema>;
|
||||
|
||||
export const ChartBlockSchema = z.object({
|
||||
chart: z.enum(['line', 'bar', 'pie']),
|
||||
title: z.string().optional(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue