Sanitize values before including in treafik config

This commit is contained in:
Owen
2026-10-27 15:10:08 -04:00
parent a85b633ca0
commit f4410cdbeb
14 changed files with 157 additions and 26 deletions
+2 -1
View File
@@ -7,6 +7,7 @@ import HttpCode from "@server/types/HttpCode";
import createHttpError from "http-errors";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
import { subdomainSchema } from "@server/lib/schemas";
import { OpenAPITags, registry } from "@server/openApi";
import { and, eq } from "drizzle-orm";
import {
@@ -35,7 +36,7 @@ const bodySchema = z
name: z.string().nonempty(),
resourceId: z.number().int().positive().optional().nullable(),
domainId: z.string().nonempty().optional().nullable(),
subdomain: z.string().nonempty().optional().nullable(),
subdomain: subdomainSchema.optional().nullable(),
destinationHost: redirectDestinationHostSchema,
pathMatchType: redirectPathMatchTypeSchema.optional(),
matchPath: redirectMatchPathSchema.optional().nullable(),
+2 -1
View File
@@ -7,6 +7,7 @@ import HttpCode from "@server/types/HttpCode";
import createHttpError from "http-errors";
import logger from "@server/logger";
import { fromError } from "zod-validation-error";
import { subdomainSchema } from "@server/lib/schemas";
import { OpenAPITags, registry } from "@server/openApi";
import { and, eq, ne } from "drizzle-orm";
import {
@@ -36,7 +37,7 @@ const bodySchema = z.strictObject({
niceId: redirectNiceIdSchema.optional(),
resourceId: z.number().int().positive().optional().nullable(),
domainId: z.string().nonempty().optional().nullable(),
subdomain: z.string().nonempty().optional().nullable(),
subdomain: subdomainSchema.optional().nullable(),
destinationHost: redirectDestinationHostSchema.optional(),
pathMatchType: redirectPathMatchTypeSchema.optional(),
matchPath: redirectMatchPathSchema.optional().nullable(),
+2 -1
View File
@@ -1,6 +1,7 @@
import { z } from "zod";
import { isValidDomain } from "@server/lib/validators";
import { build } from "@server/build";
import { routePathSchema } from "@server/lib/schemas";
export const redirectNiceIdSchema = z
.string()
@@ -20,7 +21,7 @@ export const redirectRewritePathTypeSchema = z.enum([
"stripPrefix"
]);
export const redirectMatchPathSchema = z.string().nonempty();
export const redirectMatchPathSchema = routePathSchema.nonempty();
export function isValidRegex(pattern: string): boolean {
try {
+2 -1
View File
@@ -1,5 +1,6 @@
import { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { routePathSchema } from "@server/lib/schemas";
import {
db,
statusHistory,
@@ -76,7 +77,7 @@ const createTargetSchema = z
hcTlsServerName: z.string().optional().nullable(),
hcHealthyThreshold: z.int().positive().min(1).optional().nullable(),
hcUnhealthyThreshold: z.int().positive().min(1).optional().nullable(),
path: z.string().optional().nullable(),
path: routePathSchema.optional().nullable(),
pathMatchType: z
.enum(["exact", "prefix", "regex"])
.optional()
+2 -1
View File
@@ -1,5 +1,6 @@
import { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { routePathSchema } from "@server/lib/schemas";
import { db, targetHealthCheck } from "@server/db";
import { aiProviders, newts, resources, sites, targets } from "@server/db";
import { eq } from "drizzle-orm";
@@ -54,7 +55,7 @@ const updateTargetBodySchema = z
hcTlsServerName: z.string().optional().nullable(),
hcHealthyThreshold: z.int().positive().min(1).optional().nullable(),
hcUnhealthyThreshold: z.int().positive().min(1).optional().nullable(),
path: z.string().optional().nullable(),
path: routePathSchema.optional().nullable(),
pathMatchType: z
.enum(["exact", "prefix", "regex"])
.optional()