fix(certificates): improve validation and prevent crash (#2910)

This commit is contained in:
Meier Lukas
2025-04-22 18:28:58 +02:00
committed by GitHub
parent 3172e6e0c4
commit c51424717d
5 changed files with 72 additions and 24 deletions

View File

@@ -1,3 +1,5 @@
import { X509Certificate } from "node:crypto";
import { TRPCError } from "@trpc/server";
import { z } from "zod";
import { zfd } from "zod-form-data";
@@ -16,6 +18,17 @@ export const certificateRouter = createTRPCRouter({
)
.mutation(async ({ input }) => {
const content = await input.file.text();
// Validate the certificate
try {
new X509Certificate(content);
} catch {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Invalid certificate",
});
}
await addCustomRootCertificateAsync(input.file.name, content);
}),
removeCertificate: permissionRequiredProcedure