fix(mcp): reject normalized base paths
This commit is contained in:
1 parent
bb08a6d03b
commit
dda4f4d4ed
2 files changed
+5
-1
No files matched your search
@@ -14,6 +14,8 @@ describe("BASE_URL", () => {
|
|||||||
"ftp://homarr.example.com",
|
"ftp://homarr.example.com",
|
||||||
"https://user:password@homarr.example.com",
|
"https://user:password@homarr.example.com",
|
||||||
"https://homarr.example.com/prefix",
|
"https://homarr.example.com/prefix",
|
||||||
|
"https://homarr.example.com/.",
|
||||||
|
"https://homarr.example.com/a/..",
|
||||||
"https://homarr.example.com?preview=1",
|
"https://homarr.example.com?preview=1",
|
||||||
"https://homarr.example.com#preview",
|
"https://homarr.example.com#preview",
|
||||||
])("rejects the non-origin URL %s", (value) => {
|
])("rejects the non-origin URL %s", (value) => {
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { createBooleanSchema, createEnv } from "@homarr/core/infrastructure/env";
|
import { createBooleanSchema, createEnv } from "@homarr/core/infrastructure/env";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
|
|
||||||
|
const httpOriginRegex = /^https?:\/\/[^/?#\\]+\/?$/i;
|
||||||
|
|
||||||
export const baseUrlSchema = z.url({ protocol: /^https?$/ }).refine((value) => {
|
export const baseUrlSchema = z.url({ protocol: /^https?$/ }).refine((value) => {
|
||||||
const url = new URL(value);
|
const url = new URL(value);
|
||||||
return !url.username && !url.password && url.pathname === "/" && !url.search && !url.hash;
|
return httpOriginRegex.test(value) && !url.username && !url.password;
|
||||||
}, "BASE_URL must be an HTTP(S) origin without credentials, a path, query parameters, or a fragment");
|
}, "BASE_URL must be an HTTP(S) origin without credentials, a path, query parameters, or a fragment");
|
||||||
|
|
||||||
export const env = createEnv({
|
export const env = createEnv({
|
||||||
|
|||||||
Reference in new issue
Block a user